Cannot use camera on Android 4.1.2 with OpenCV 2.4.6

asked 2013-08-07 09:50:37 -0500

Chaos_99 gravatar image

updated 2013-08-07 09:52:07 -0500

There are numerous questions here, but none of them quite match my case. (And a lot are unanswered anyway.)

I'm using OpenCV for Android 2.4.6 (the prebuilt version downloadable from the main site) to build a native App for Android (4.1.2) on a Samsung Galaxy Note 2 with Qt 5.0.1 for Android (using QtCreator 2.7.2) on a x86_64 Linux host.

I've linked against the libraries in the ../sdk/native/libs/armeabi-v7a folder. (I haven't built OpenCV from source, I'm just using what was in the downloaded package). This includes a libopencv_androidcam.a library. I've also downloaded the market app "OpenCV Manager".

The sample .apks from the samples directory work on my phone, but I haven't tried to build them on my own, as I don't have a Java development environment set up.

Starting my application, which contains a cv::VideoCapture inputCapture(CV_CAM_ANDROID); statement, I get the following error and no camera input:

E/OpenCV::camera(15299): CameraWrapperConnector::connectToLib ERROR: cannot dlopen camera wrapper library
E/OpenCV::camera(15299): Native_camera returned opening error: 4

My questions:

  • Should this work? I have seen a lot of bug reports, but all with older OpenCV versions and newer/older Android versions. Bonus points if it has been seen working on this phone model.
  • Should this work out of the box with the downloaded OpenCV Android SDK? Or do I need to build OpenCV from source with some special options? (Which ones?)
  • Do I need special library versions on the phone itself? Do I need to have root access to the device to make this work?
  • Are there any "known to be working" Andoid examples using native code instead of Java?

Thanks a lot for any help!

edit retag flag offensive close merge delete



Copy from the folder /sdk/native/libs/armeabi-v7a to your Qt project's folder /android/libs/armeabi-v7a. Make sure you have also allowed the camera in the android_manifest in the Qt creator. Maybe all this helps

Moster gravatar imageMoster ( 2013-08-08 05:30:59 -0500 )edit

@Moster It worked! Thanks a lot. The video output is still very slow and there are some issues with rotation, but at least the camera works. Do you know why this lib wasn't present on the device before? Shouldn't this be handled by the OpenCV Manager App? And why does it build in the first place, although this library isn't linked? (If you give this as an answer, I could accept it as right. Also, if you like, you could answer the same question on stackexchange if you are active on that platform.)

Chaos_99 gravatar imageChaos_99 ( 2013-08-08 08:30:40 -0500 )edit

Do you actually still load the Opencv Manager app? I mean, you are using Qt, so I guess all the stuff you are doing is in c++. If you would go for normal android java coding, you would need to initialize the opencv manager in your main activity. Qt5 also creates an android activity, but I guess you didnt bother editing it to load the Opencv Manager (probably its better not to do that). So obviously the native camera library does not get loaded. So you need to manually copy it into your Qt project, so that it gets packed into the android apk. The reason why it still successfully builds is that you also just link against precompiled opencv libraries. So while you are building, all the opencv libraries are available and so it will be succesful.

Moster gravatar imageMoster ( 2013-08-08 09:24:50 -0500 )edit

But one of those libraries requires the native camera lib to be available at runtime, but this is obviously not checked at compile time. This is at least how I imagine it. I hope you understand what I mean.

Btw, how many fps do you get from the camera? It should actually log that all the time. Im getting at least 30 on my tegra 3 device.

Moster gravatar imageMoster ( 2013-08-08 09:26:58 -0500 )edit

Qt5 creates the Java stub to call the JNI functions and it's complex enough that I didn't try to mess with it. The Qt5 project settings allow to either load all libraries to the device on build/run or just use the ones already present on the device. While I tried the former first, I also manually installed the OpenCV Manager app (and the Ministro app, which is kind of the same for the Qt libs) to externally load the needed libs and try the second option. Seems that the "load libs to device" option doesn't quite work for non-Qt shared libs like the libnative_camera. (And I've tried to explicitly mention it as needed in the project file.) Also the OpenCV Manager App doesn't seem to load the libs either if it's just startet on its own and not called correctly from the Java code.

Chaos_99 gravatar imageChaos_99 ( 2013-08-09 03:14:13 -0500 )edit

Ye, thats basically the problem. The opencv manager app cannot provide the libs as long as you dont load it. The app cant install the libraries systemwide. Thats why you need to load it at run time. I guess this might be possible if it had root access, but you cant require every use to have that. Maybe Im totally wrong though.

Moster gravatar imageMoster ( 2013-08-09 04:15:35 -0500 )edit

I try to use opencv camera with Qt5.2 but have no luck, may you show me your .pro and some codes?

stereomatching gravatar imagestereomatching ( 2013-11-29 14:01:08 -0500 )edit