Ask Your Question

Camera Not working

asked 2012-08-17 11:29:29 -0500

Pete gravatar image

updated 2012-08-26 11:32:41 -0500

I am using the OpenCV-2.4.2-android-sdk and have problems with the camera on my target. On the emulator the sample color-blob-detection works for me so I know I have the sdk correctly configured. On target the application crashes and in the logs I get
E/CAMERA_ACTIVITY( 1940): Could not read /proc/self/smaps
D/CAMERA_ACTIVITY( 1940): CameraWrapperConnector::connectToLib: folderPath=/data/data/com.NativeCamera/lib/
E/CAMERA_ACTIVITY( 1940): CameraWrapperConnector::connectToLib ERROR: cannot dlopen camera wrapper library
E/CV_CAP ( 1940): Native_camera returned opening error: 4
E/Sample-ImageManipulations::SurfaceView( 1940): Failed to open native camera

I see in the code that this is used in std::string CameraWrapperConnector::getPathLibFolder() as a default when /proc/self/smaps cant be opened. The path /data/data/com.NativeCamera AND /proc/self/smaps do not exist on my target, does this mean that the native camera is not supported on my target? Or do I have to change the name of /proc/self/smaps in the OpenCV code to map to a file that does exist on Android 4.0.3?

looking at the output from dumpsys run on my target ("adb shell dumpsys") I get the following interesting entry:

When I start the camera application on target I get the following in the logs:
I/ActivityManager( 312): START {act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000} from pid 525
I/ActivityManager( 312): Start proc for activity pid=2028 uid=10007 gids={1006, 1015}

So it looks like the OpenCV code is trying to find a way to locate the nativeLibraryPath using smaps.. but smaps now does not exist on Android so OpenCV must change to find a new way to locate the correct library. Has this bug already been fixed?

edit retag flag offensive close merge delete


/proc/self/smaps does exist on Android. What device are you using?

Andrey Kamaev gravatar imageAndrey Kamaev ( 2012-08-27 05:55:09 -0500 )edit

I am using SmartQ Ten3 T15 tablet with Android 4.1 Jelly Bean. Now all the OpenCV examples work and a learnt a whole lot about android and OpenCV on Android in the process.

Pete gravatar imagePete ( 2012-08-27 14:30:47 -0500 )edit

2 answers

Sort by ยป oldest newest most voted

answered 2012-08-26 02:54:19 -0500

Pete gravatar image

updated 2012-08-27 14:35:42 -0500

I have fix the problem of the camera not working. In brief I moved to latest OpenCV code, installed Android 4.1.1 on my tablet, moved to the latest Android development environment. Then I built OpenCV Manager and the camera wrapper ( is a guide but not complete). I changed the default path in camera_activity.cpp:
#define DEFAULT_WRAPPER_PACKAGE_NAME "org.opencv.lib_v24_armv7a_neon"
After the build I installed my version of the OpenCV binary_pack_armv7a_neon-release.apk and the examples began to work. Then I fixed a problem where OpenCV examples assume a backward facing camera. My tablet only has forward facing camera so 4 of the examples failed till I fixed that example code bug and now all examples work.

As you will know from reading to build modules/androidcamera/camera_wrapper and the binary pack OpenCV binary_pack_armv7a_neon-release.apk you need to have a working build of the android source for your platform. Building on 64bit Linux requires the latest Android source, plus a lot of 32bit libraries as detailed at, then follow the instructions at (I configured and built full-eng that builds the generic/system/lib libraries referenced by camera_wrapper/CMakeLists.txt).
Now the fun started for me because OpenCV does not seem to have been built as a package so here are the fixes that I have used. First I set my path up and ANDROID_NDK
export ANDROID_NDK=~/InstallPackages/android-ndk-r8b
export ANDROID_SDK=~/InstallPackages/android-sdk-linux
export ANDROID_SRC=~/Projects/Android411
export PATH=${PATH}:${ANDROID_SDK}/platform-tools:${ANDROID_SDK}/tools:${ANDROID_SDK}:${ANDROID_NDK}
then in the build folder (android/build) I ran cmake


and built the code

make -j8
make install

I use ANDROID_USE_STLPORT=OFF because various parts of OpenCV include android-ndk-r8b/sources/cxx-stl/gnu-libstdc++/include/ext/atomicity.h that does not exist in the stlport libraries that are described as "experimental" by the Android team. The side effect of this is that rtti is switched on so linking fails. So one of either include atomicity.h or linking have to be fixed. It also has the side effect that the OpenCV Manager is not built, but I have a simple fix for this. The result is that the entire OpenCV code is built and all the .apk files are produced (although OpenCV binary_pack_armv7a_neon-release-unsigned.apk has to be signed (see

Ok so here are my patches:
ERROR from the logcat output "CameraWrapperConnector::connectToLib: folderPath=/data/data/com.NativeCamera/lib/
CameraWrapperConnector::connectToLib ERROR: cannot dlopen camera wrapper library E/CV_CAP ( 1796): Native_camera returned opening error: 4 E/Sample::SurfaceView( 1796): Failed to open native camera
FIX this is the error that started it all.. fix is to build android and opencv but ... (more)

edit flag offensive delete link more


Thanks for the great information!

profox gravatar imageprofox ( 2015-02-01 05:21:10 -0500 )edit

answered 2012-09-16 15:12:12 -0500

this post is marked as community wiki

This post is a wiki. Anyone with karma >50 is welcome to improve it.

Wow, simply amazing, although is this really an answer to the camera not working: "fix is to build android and opencv"... I really don't want to build Android, nor build OpenCV; I was having the same problem, and I switched to a different brand of device, from Samsung Galaxy S, to an HTC Slide, and then all the tutorials and demos ran fine. If anyone has a solution, other than rebuilding ANDROID, please let me know.

As for the gentleman who did the rebuilding, hats off to you! Amazing work. If you have the knowledge to rebuild Android, and to rebuild OpenCV, you should be writing the tutorials, not following them!

UPDATE: I found a way to get the tutorials working! Just don't use the Native Camera code! Modify the tutorials that use the SampleCvViewBase class to use the SampleViewBase class in the other tutorials. The key is to modify the processFrame to convert the data for a VideoCapture to a byte[], so:

capture.retrieve(mRgba, Highgui.CV_CAP_ANDROID_COLOR_FRAME_RGBA);
capture.retrieve(mGray, Highgui.CV_CAP_ANDROID_GREY_FRAME);


Mat mYuv = new Mat(getFrameHeight()+getFrameHeight()/2, getFrameWidth(), CvType.CV_8UC1);
mYuv.put(0, 0, data);
Imgproc.cvtColor(mYuv, mRgba, Imgproc.COLOR_YUV420sp2RGB, 4);
Imgproc.cvtColor(mRgba, mGray, Imgproc.COLOR_RGB2GRAY, 0);
edit flag offensive delete link more


in the OpenCV Android examples there is no SampleCvViewBase nor any other class you mentioned.

Nagilo gravatar imageNagilo ( 2013-09-20 02:50:17 -0500 )edit
Login/Signup to Answer

Question Tools



Asked: 2012-08-17 11:29:29 -0500

Seen: 8,636 times

Last updated: Sep 16 '12