使用C ++ OpenCV + QT + Android,VideoCapture isOpened()始终为false

时间:2017-02-27 16:40:17

标签: android c++ qt opencv

我希望能够在Android 5.0设备上使用c ++ opencv 3.0和QT 5.7。

问题与cv :: VideoCapture打开功能有关。 mCamera.isOpened()始终返回false。

android opencv build是否允许我们使用相机?我能做些什么特别的事吗?

我阅读了很多关于android opencv的帖子,有时人们说它不可能使用它。

我已尝试过CV_CAP_ANDROID_FRONT,CV_CAP_ANDROID,CV_CAP_ANDROID_BACK,0,1。

这是main.cpp:

cv::Mat inframe = cv::Mat();
cv::VideoCapture mCamera;
mCamera.open(CV_CAP_ANDROID_FRONT);
mCamera.set(CV_CAP_PROP_FRAME_WIDTH, 400);
mCamera.set(CV_CAP_PROP_FRAME_HEIGHT, 300);

qDebug() << mCamera.isOpened();
while (mCamera.isOpened()) {
    bool grab = mCamera.grab();
    if (grab) {
        mCamera.retrieve(inframe, CV_CAP_ANDROID_FRONT);
    } else {
        cout << "--->Cannot grab a frame from camera." << endl;;
    }
}
mCamera.release();

这是我的.pro文件:

INCLUDEPATH += "$$_PRO_FILE_PWD_/opencv3Android/sdk/native/jni/include"
android {
    LIBS += \
        -L"$$_PRO_FILE_PWD_/opencv3Android/sdk/native/3rdparty/libs/armeabi-v7a"\
        -L"$$_PRO_FILE_PWD_/opencv3Android/sdk/native/libs/armeabi-v7a"\
        -llibtiff\
        -llibjpeg\
        -llibjasper\
        -llibpng\
        -lIlmImf\
        -ltbb\
        -lopencv_core\
        -lopencv_flann\
        -lopencv_imgproc\
        -lopencv_highgui\
        -lopencv_features2d\
        -lopencv_calib3d\
        -lopencv_ml\
        -lopencv_objdetect\
        -lopencv_video\
        -lopencv_photo\
        -lopencv_java3\
        -lopencv_stitching\
        -lopencv_superres\
        -lopencv_videostab

    ANDROID_PACKAGE_SOURCE_DIR=$$_PRO_FILE_PWD_/android
    ANDROID_PACKAGE_SOURCE_DIR = $$PWD/android-sources

}

contains(ANDROID_TARGET_ARCH,armeabi-v7a) {
    ANDROID_EXTRA_LIBS = \
        $$PWD/opencv3Android/sdk/native/libs/armeabi-v7a/libopencv_java3.so
}

win32:CONFIG(release, debug|release): LIBS += -L$$PWD/opencv3Android/sdk/native/3rdparty/libs/armeabi-v7a/release/ -ltegra_hal
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/opencv3Android/sdk/native/3rdparty/libs/armeabi-v7a/debug/ -ltegra_hal
else:unix: LIBS += -L$$PWD/opencv3Android/sdk/native/3rdparty/libs/armeabi-v7a/ -ltegra_hal

INCLUDEPATH += $$PWD/opencv3Android/sdk/native/3rdparty/libs/armeabi-v7a
DEPENDPATH += $$PWD/opencv3Android/sdk/native/3rdparty/libs/armeabi-v7a

win32-g++:CONFIG(release, debug|release): PRE_TARGETDEPS += $$PWD/opencv3Android/sdk/native/3rdparty/libs/armeabi-v7a/release/libtegra_hal.a
else:win32-g++:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$PWD/opencv3Android/sdk/native/3rdparty/libs/armeabi-v7a/debug/libtegra_hal.a
else:win32:!win32-g++:CONFIG(release, debug|release): PRE_TARGETDEPS += $$PWD/opencv3Android/sdk/native/3rdparty/libs/armeabi-v7a/release/tegra_hal.lib
else:win32:!win32-g++:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$PWD/opencv3Android/sdk/native/3rdparty/libs/armeabi-v7a/debug/tegra_hal.lib
else:unix: PRE_TARGETDEPS += $$PWD/opencv3Android/sdk/native/3rdparty/libs/armeabi-v7a/libtegra_hal.a

DISTFILES += \
    android-sources/AndroidManifest.xml

我还添加了manifest.xml的权限:

<uses-permission android:name="android.permission.CAMERA"/>

0 个答案:

没有答案