Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

VideoCapture.isOpened() always returns false on Android

Hi,

I am new to OpenCV, and I am trying to get this library to work. Part of my code looks like this:

Log.e("myapp", "creating VideoCapture");
VideoCapture mCamera = new VideoCapture(mCameraId);
Log.e("myapp", "created VideoCapture");
if(!mCamera.isOpened()){
    Log.e("myapp", "VideoCapture is not open");
}

Since it is using OpenCV 2.4, I tried to do so as well. Between the first two log messages, I got a lot of initialization errors:

12-16 16:44:04.037: E/myapp(10300): creating VideoCapture
12-16 16:44:04.037: D/OpenCV::camera(10300): CvCapture_Android::CvCapture_Android(1)
12-16 16:44:04.038: D/OpenCV::camera(10300): Library name: libopencv_java.so
12-16 16:44:04.038: D/OpenCV::camera(10300): Library base address: 0xa1dff000
12-16 16:44:04.044: D/OpenCV::camera(10300): Libraries folder found: /data/app/com.scrambled.kookstand-2/lib/arm/
12-16 16:44:04.044: D/OpenCV::camera(10300): CameraWrapperConnector::connectToLib: folderPath=/data/app/com.scrambled.kookstand-2/lib/arm/
12-16 16:44:04.044: E/OpenCV::camera(10300): ||libnative_camera_r4.1.1.so
12-16 16:44:04.044: E/OpenCV::camera(10300): ||libnative_camera_r4.0.3.so
12-16 16:44:04.044: E/OpenCV::camera(10300): ||libnative_camera_r2.3.3.so
12-16 16:44:04.044: E/OpenCV::camera(10300): ||libnative_camera_r4.2.0.so
12-16 16:44:04.044: E/OpenCV::camera(10300): ||libnative_camera_r2.2.0.so
12-16 16:44:04.044: E/OpenCV::camera(10300): ||libnative_camera_r3.0.1.so
12-16 16:44:04.044: E/OpenCV::camera(10300): ||libnative_camera_r4.3.0.so
12-16 16:44:04.044: E/OpenCV::camera(10300): ||libnative_camera_r4.0.0.so
12-16 16:44:04.044: E/OpenCV::camera(10300): ||libnative_camera_r4.4.0.so
12-16 16:44:04.044: D/OpenCV::camera(10300): try to load library 'libnative_camera_r4.4.0.so'
12-16 16:44:04.046: D/OpenCV::camera(10300): CameraWrapperConnector::connectToLib ERROR: cannot dlopen camera wrapper library /data/app/com.scrambled.kookstand-2/lib/arm/libnative_camera_r4.4.0.so, dlerror="dlopen failed: cannot locate symbol "_ZN7android11BufferQueueC1ERKNS_2spINS_19IGraphicBufferAllocEEE" referenced by "libnative_camera_r4.4.0.so"..."
12-16 16:44:04.046: D/OpenCV::camera(10300): try to load library 'libnative_camera_r4.3.0.so'
12-16 16:44:04.046: D/OpenCV::camera(10300): CameraWrapperConnector::connectToLib ERROR: cannot dlopen camera wrapper library /data/app/com.scrambled.kookstand-2/lib/arm/libnative_camera_r4.3.0.so, dlerror="dlopen failed: cannot locate symbol "_ZN7android11BufferQueueC1EbRKNS_2spINS_19IGraphicBufferAllocEEE" referenced by "libnative_camera_r4.3.0.so"..."
12-16 16:44:04.046: D/OpenCV::camera(10300): try to load library 'libnative_camera_r4.2.0.so'
12-16 16:44:04.047: D/OpenCV::camera(10300): CameraWrapperConnector::connectToLib ERROR: cannot dlopen camera wrapper library /data/app/com.scrambled.kookstand-2/lib/arm/libnative_camera_r4.2.0.so, dlerror="dlopen failed: cannot locate symbol "_ZN7android6Camera10disconnectEv" referenced by "libnative_camera_r4.2.0.so"..."
12-16 16:44:04.047: D/OpenCV::camera(10300): try to load library 'libnative_camera_r4.1.1.so'
12-16 16:44:04.048: D/OpenCV::camera(10300): CameraWrapperConnector::connectToLib ERROR: cannot dlopen camera wrapper library /data/app/com.scrambled.kookstand-2/lib/arm/libnative_camera_r4.1.1.so, dlerror="dlopen failed: cannot locate symbol "_ZN7android6Camera10disconnectEv" referenced by "libnative_camera_r4.1.1.so"..."
12-16 16:44:04.048: D/OpenCV::camera(10300): try to load library 'libnative_camera_r4.0.3.so'
12-16 16:44:04.048: D/OpenCV::camera(10300): CameraWrapperConnector::connectToLib ERROR: cannot dlopen camera wrapper library /data/app/com.scrambled.kookstand-2/lib/arm/libnative_camera_r4.0.3.so, dlerror="dlopen failed: cannot locate symbol "__exidx_end" referenced by "libnative_camera_r4.0.3.so"..."
12-16 16:44:04.048: D/OpenCV::camera(10300): try to load library 'libnative_camera_r4.0.0.so'
12-16 16:44:04.049: D/OpenCV::camera(10300): CameraWrapperConnector::connectToLib ERROR: cannot dlopen camera wrapper library /data/app/com.scrambled.kookstand-2/lib/arm/libnative_camera_r4.0.0.so, dlerror="dlopen failed: cannot locate symbol "_ZN7android6Camera10disconnectEv" referenced by "libnative_camera_r4.0.0.so"..."
12-16 16:44:04.049: D/OpenCV::camera(10300): try to load library 'libnative_camera_r3.0.1.so'
12-16 16:44:04.049: D/OpenCV::camera(10300): CameraWrapperConnector::connectToLib ERROR: cannot dlopen camera wrapper library /data/app/com.scrambled.kookstand-2/lib/arm/libnative_camera_r3.0.1.so, dlerror="dlopen failed: cannot locate symbol "__exidx_end" referenced by "libnative_camera_r3.0.1.so"..."
12-16 16:44:04.049: D/OpenCV::camera(10300): try to load library 'libnative_camera_r2.3.3.so'
12-16 16:44:04.050: D/OpenCV::camera(10300): CameraWrapperConnector::connectToLib ERROR: cannot dlopen camera wrapper library /data/app/com.scrambled.kookstand-2/lib/arm/libnative_camera_r2.3.3.so, dlerror="dlopen failed: cannot locate symbol "__exidx_start" referenced by "libnative_camera_r2.3.3.so"..."
12-16 16:44:04.050: D/OpenCV::camera(10300): try to load library 'libnative_camera_r2.2.0.so'
12-16 16:44:04.051: D/OpenCV::camera(10300): CameraWrapperConnector::connectToLib ERROR: cannot dlopen camera wrapper library /data/app/com.scrambled.kookstand-2/lib/arm/libnative_camera_r2.2.0.so, dlerror="dlopen failed: cannot locate symbol "__exidx_end" referenced by "libnative_camera_r2.2.0.so"..."
12-16 16:44:04.051: E/OpenCV::camera(10300): CameraWrapperConnector::connectToLib ERROR: cannot dlopen camera wrapper library
12-16 16:44:04.051: E/OpenCV::camera(10300): Native_camera returned opening error: 4
12-16 16:44:04.051: E/myapp(10300): created VideoCapture
12-16 16:44:04.051: E/myapp(13503): VideoCapture is not open

It looks like the libraries are trying to use unsupported methods that were removed from the Android NDK, as described here. These suspisions are strengthened by the absence of a library for the Android version I am using (5.1 lollipop).

So I tried to update to OpenCV 3 to solve the problem. However, now there is no output at all between the log messages:

12-16 16:55:42.301: E/myapp(13503): creating VideoCapture
12-16 16:55:42.302: E/myapp(13503): created VideoCapture
12-16 16:55:42.302: E/myapp(13503): VideoCapture is not open

I tried many possible combinations of calling the VideoCapture constructor but none is working. This makes it look like the VideoCapture constructor on Android is fundamentally broken. It does not seem to do anything, not even outputting a single log message. Obviously this also means that VideoCapture.isOpened will return false.

Can anybody help me with this problem using either OpenCV 2.4 or 3.0?