android - Qt OpenCV Android 代码不会在 capture.grab() 之前移动

标签 android c++ qt opencv

使用 OpenCV 和 QT 创建了一个 Android 应用程序。调用 VideoCapture 对象的“grab”或“read”方法会卡住代码的进一步执行。之后什么也没有发生。只出现黑屏。

注意:考虑包含所有必需的头文件。该代码在桌面 (Linux) 上完美运行

int main(int argc, char *argv[]) { QApplication app(argc,argv); qDebug() << "CP 1"; Ptr<VideoCapture> capture; capture = new VideoCapture(CV_CAP_ANDROID_FRONT); if(capture->isOpened()) qDebug() << "CP 1.11"; Mat img; qDebug() << "CP 1.1";

capture->read(img); // **code doesn't moves ahead of this point**
qDebug() << "CP 1.3";

Mat gray;
Mat prev;
Mat diff;
cvtColor(img, prev, CV_BGR2GRAY);

以下是输出日志,代码没有超出capture read方法

`

Starting remote process.I/Qt      ( 8391): Network start
 I/Qt      ( 8391): qt start
 W/art     ( 8391): Thread[14,tid=8446,Native,Thread*=0x484282a8,peer=0x656ce530,"Thread-17697"] attached without supplying a name
I/Adreno-EGL( 8391): <qeglDrvAPI_eglInitialize:320>: EGL 1.4 QUALCOMM Build: I0404c4692afb8623f95c43aeb6d5e13ed4b30ddbDate: 11/06/13
W/art     ( 8391): Thread[14,tid=8446,Native,Thread*=0x484282a8,peer=0x656cffa8,"Thread-17698"] attached without supplying a name
W/art     ( 8391): Thread[14,tid=8446,Native,Thread*=0x484282a8,peer=0x656d01e0,"Thread-17699"] attached without supplying a name
D/Qt      ( 8391): ../test/main.cpp:62 (int main(int, char**)): CP 1
D/OpenCV::camera( 8391): CvCapture_Android::CvCapture_Android(98)
D/OpenCV::camera( 8391): Library name: libopencv_java.so
D/OpenCV::camera( 8391): Library base address: 0x498f6000
D/OpenCV::camera( 8391): Libraries folder found: /data/app-lib/com.sumit.tracker-1/
D/OpenCV::camera( 8391): CameraWrapperConnector::connectToLib: folderPath=/data/app-lib/com.sumit.tracker-1/
E/OpenCV::camera( 8391): ||libnative_camera_r4.4.0.so
D/OpenCV::camera( 8391): try to load library 'libnative_camera_r4.4.0.so'
D/OpenCV::camera( 8391): Loaded library '/data/app-lib/com.sumit.tracker-1/libnative_camera_r4.4.0.so'
D/OpenCV_NativeCamera( 8391): Front camera selected
D/OpenCV_NativeCamera( 8391): CameraHandler::initCameraConnect(0x49fcef99, 1, 0x48431af0, 0x0)
D/OpenCV_NativeCamera( 8391): Current process name for camera init: com.sumit.tracker
D/OpenGLRenderer( 8391): Enabling debug mode 0
D/OpenCV_NativeCamera( 8391): Instantiated new CameraHandler (0x49fcef99, 0x48431af0)
I/OpenCV_NativeCamera( 8391): initCameraConnect: [preview-size=1280x960;video-size=1280x960;preferred-preview-size-for-video=1280x960;preview-size-values=1280x960,1280x768,1280x720,1024x768,800x600,800x480,720x480,640x480,352x288,320x240,176x144;video-size-values=1280x960,1280x768,1280x720,1024x768,800x600,800x480,720x480,640x480,352x288,320x240,176x144;preview-format=yuv420sp;preview-format-values=yuv420p,yuv420sp,;preview-frame-rate=15;preview-fps-range=15000,15000;preview-fps-range-values=(15000,15000),(24000,24000),(7000,30000),(30000,30000);preview-frame-rate-values=15,24,30;picture-size=1280x960;picture-size-values=1280x960,1280x768,1280x720,1024x768,800x600,800x480,720x480,640x480,352x288,320x240,176x144;picture-format=jpeg;picture-format-values=jpeg;jpeg-thumbnail-width=320;jpeg-thumbnail-height=240;jpeg-thumbnail-size-values=512x288,480x288,256x154,432x288,320x240,176x144,0x0;jpeg-thumbnail-quality=90;jpeg-quality=90;rotation=0;whitebalance=auto;whitebalance-values=auto,incandescent,fluorescent,warm-fluorescent,daylight,cloudy-d
D/OpenCV_NativeCamera( 8391): Supported Cameras: (null)
D/OpenCV_NativeCamera( 8391): Supported Picture Sizes: 1280x960,1280x768,1280x720,1024x768,800x600,800x480,720x480,640x480,352x288,320x240,176x144
D/OpenCV_NativeCamera( 8391): Supported Picture Formats: jpeg
D/OpenCV_NativeCamera( 8391): Supported Preview Sizes: 1280x960,1280x768,1280x720,1024x768,800x600,800x480,720x480,640x480,352x288,320x240,176x144
D/OpenCV_NativeCamera( 8391): Supported Preview Formats: yuv420p,yuv420sp,
D/OpenCV_NativeCamera( 8391): Supported Preview Frame Rates: 15,24,30
D/OpenCV_NativeCamera( 8391): Supported Thumbnail Sizes: 512x288,480x288,256x154,432x288,320x240,176x144,0x0
D/OpenCV_NativeCamera( 8391): Supported Whitebalance Modes: auto,incandescent,fluorescent,warm-fluorescent,daylight,cloudy-daylight,twilight,shade
D/OpenCV_NativeCamera( 8391): Supported Effects: none,mono,negative,solarize,sepia,posterize,whiteboard,blackboard,aqua
D/OpenCV_NativeCamera( 8391): Supported Scene Modes: auto,landscape,snow,beach,sunset,night,portrait,sports,steadyphoto,candlelight,fireworks,party,night-portrait,theatre,action
D/OpenCV_NativeCamera( 8391): Supported Focus Modes: fixed
D/OpenCV_NativeCamera( 8391): Supported Antibanding Options: off,60hz,50hz,auto
D/OpenCV_NativeCamera( 8391): Supported Flash Modes: off
D/OpenCV_NativeCamera( 8391): initCameraConnect: preview format is set to yuv420sp
D/OpenCV_NativeCamera( 8391): initCameraConnect: preview format is set to 640x480
D/OpenCV_NativeCamera( 8391): Starting preview
D/OpenCV_NativeCamera( 8391): Preview started successfully
D/Qt      ( 8391): ../test/main.cpp:66 (int main(int, char**)): CP 1.11
D/Qt      ( 8391): ../test/main.cpp:69 (int main(int, char**)): CP 1.1

`

最佳答案

最终发现问题与 Nexus 5 上的 OpenCV 2.4.9 有关。

http://answers.opencv.org/question/30311/opencv_nativecamera-startpreview-fails-on-nexus-5/

关于android - Qt OpenCV Android 代码不会在 capture.grab() 之前移动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25603689/

相关文章:

c++ - 删除此保护互斥示例中的定义

qt - 带有 Qt 函数 cv::erode() 和 cv::dilate() 的 OpenCV 崩溃

android - 我在尝试将 Google Sign In 集成到我的 Android 应用程序时遇到错误 : Cannot Resolve Symbol GoogleSignIn

android - 屏蔽通知栏

C++: 奇怪的 "Request for member X of Y which is of non-class type Z"

c++ - 加载共享库时出错 : libcaffe. 所以

c++ - Qt 安装程序框架 : How to sign the maintenancetool. exe

qt - 未找到自定义 QML 模块

java - 安卓 : OpenCv comparing two images issue

android 辅助功能屏幕放大镜