Ask Your Question
0

Android NDK Native Activity: Problem using OpenCV

asked 2013-03-03 17:46:53 -0600

Dave gravatar image

updated 2013-03-03 17:49:51 -0600

Hello

I'm trying to use OpenCV VideoCapture in an Android NDK Native Activity. Unfortunately I can't find a tutorial for integrating OpenCV with Native Activity, so I was trying to discover a solution myself.

This is my Android.mk file:

LOCAL_PATH := $(call my-dir)
SELF_DIR := $(dir $(lastword $(MAKEFILE_LIST)))
OPENCV_SDK_DIR := $(SELF_DIR)/../../OpenCV-2.4.4-android-sdk

include $(CLEAR_VARS)
OPENCV_CAMERA_MODULES:=on
OPENCV_INSTALL_MODULES:=on
OPENCV_LIB_TYPE:=SHARED
include $(OPENCV_SDK_DIR)/sdk/native/jni/OpenCV.mk

LOCAL_MODULE    := CameraTest
LOCAL_SRC_FILES := AppEngine.cpp ConcreteApp.cpp main.cpp
LOCAL_LDLIBS    += -llog -landroid -lEGL -lGLESv1_CM
LOCAL_STATIC_LIBRARIES += android_native_app_glue
include $(BUILD_SHARED_LIBRARY)

$(call import-module,android/native_app_glue)

The problem is that the app is only starting, when I do static linking of OpenCV with OPENCV_LIB_TYPE := STATIC. With dynamic linking, the app doesn't even start and I get the following exception:

03-04 00:19:39.880: E/AndroidRuntime(3667): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.cameratest/android.app.NativeActivity}: java.lang.IllegalArgumentException: Unable to load native library: /data/data/com.example.cameratest/lib/libCameraTest.so

I actually wouldn't mind static linking, but I discovered other problems with this method: The video capture doesn't seem to work. I tried the camera examples in the samples folder of the OpenCV Android SDK and they all work. So the problem seems to be on my side.

As I said, the video capture doesn't work when linking statically. I get the following log messages:

03-04 00:26:59.090: D/OpenCV::camera(3818): CvCapture_Android::CvCapture_Android(0)
03-04 00:26:59.090: D/OpenCV::camera(3818): Library name: libCameraTest.so
03-04 00:26:59.090: D/OpenCV::camera(3818): Library base address: 0x80400000
03-04 00:26:59.100: D/OpenCV::camera(3818): Libraries folder found: /data/data/ch.bfh.cpvr.cameratest/lib/
03-04 00:26:59.100: D/OpenCV::camera(3818): CameraWrapperConnector::connectToLib: folderPath=/data/data/ch.bfh.cpvr.cameratest/lib/
03-04 00:26:59.100: E/OpenCV::camera(3818): ||libnative_camera_r4.2.0.so
03-04 00:26:59.100: E/OpenCV::camera(3818): ||libnative_camera_r3.0.1.so
03-04 00:26:59.100: E/OpenCV::camera(3818): ||libnative_camera_r2.3.3.so
03-04 00:26:59.100: E/OpenCV::camera(3818): ||libnative_camera_r2.2.0.so
03-04 00:26:59.100: E/OpenCV::camera(3818): ||libnative_camera_r4.0.3.so
03-04 00:26:59.100: E/OpenCV::camera(3818): ||libnative_camera_r4.1.1.so
03-04 00:26:59.100: E/OpenCV::camera(3818): ||libnative_camera_r4.0.0.so
03-04 00:26:59.100: D/OpenCV::camera(3818): try to load library 'libnative_camera_r4.2.0.so'
03-04 00:26:59.110: D/OpenCV::camera(3818): CameraWrapperConnector::connectToLib ERROR: cannot dlopen camera wrapper library /data/data/ch.bfh.cpvr.cameratest/lib/libnative_camera_r4.2.0.so, dlerror="Cannot load library: reloc_library[1311]:  1386 cannot locate '_ZN7android11BufferQueueC1EbRKNS_2spINS_19IGraphicBufferAllocEEE'...
03-04 00:26:59.110: D/OpenCV::camera(3818): "
03-04 00:26:59.110: D/OpenCV::camera(3818): try to load library 'libnative_camera_r4.1.1.so'
03-04 00:26:59.110: D/OpenCV::camera(3818): CameraWrapperConnector::connectToLib ERROR: cannot dlopen camera wrapper library /data/data/ch.bfh ...
(more)
edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2013-03-04 00:26:56 -0600

The reason of your application failure is linking with native OpenCV libraries in run time. There is the same question here. See Stackoverflow thread for the solution.

edit flag offensive delete link more

Question Tools

Stats

Asked: 2013-03-03 17:46:53 -0600

Seen: 6,488 times

Last updated: Mar 04 '13