Ask Your Question
1

android 3rd party library using opencv

asked 2012-10-22 12:58:26 -0600

cooperz gravatar image

hi there,

I'm encountering problems when trying to compile and use another library on android (let us name it CoreVision) that uses opencv and cmake.

The library is using a cmake file and I'm using the opencv 2.4.2 android.toolchain.cmake file provided, as well as the OpenCVConfig.cmake from the Opencv-2.4.2/sdk/native/jni folder.

The library cross-compiles successfully. I try to add it to (and modify) one of the opencv android examples that uses JNI (I named the library that contains the JNI code CoreVisionIntegration), but everything explodes when I try to load the CoreVision library. While I do not know the exact cause, since the stack trace is not showing any useful information, the library has some static variables that are initialized to OpenCV types. Upon inspection of libCoreVision.so with the arm objdump, I notice that it does not link against libopencv_java.so, as is the libCoreVisionIntegration.so. Everything seems to be linked statically.

Any ideas on why that might be the case? Thanks, Andrei.

edit retag flag offensive close merge delete

Comments

I've reduced this to a very simple sample library (just one class and one function call).

If I introduce static member that is of cv::Mat type, I can reproduce the crash.

cooperz gravatar imagecooperz ( 2012-10-22 13:23:10 -0600 )edit

Eventually I've eliminated all the static non trivial opencv types (i.e. cv::Mat, cv::Point) and I have been able to eliminate the crashes. I hope it helps somebody out there.

cooperz gravatar imagecooperz ( 2012-10-27 19:08:24 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
1

answered 2012-10-29 04:31:41 -0600

  1. You have two independent versions of OpenCV. The first is linked against libCoreVision statically. The second is libopencv_java that is linked against integration library dynamically. The problem appears when you try to put some OpenCV object from one library to another. The root of strange crashes may be different versions of STL or different compiler options. To solve the problem you need to use the same shared library in both cases.
  2. Java machine does not load dependent libs from libs directory in your package. You need to load all your libs in reverse order to satisfy all dependencies. Move all System.LoadLibrary() calls to onManagerConnected() callback to load all your libs after OpenCV initialization.
edit flag offensive delete link more

Comments

If libopencv_java is the preferred way of linking against opencv on Android, then this should really be reflected in the OpenCVConfig.cmake file from sdk/native/jni folder, to resemble more what is found in OpenCV.mk for NDK, no ?

cooperz gravatar imagecooperz ( 2012-10-30 11:39:39 -0600 )edit

I've modified the file OpenCVConfig.cmake, by replacing:

SET(OpenCV_LIB_COMPONENTS opencv_java)

and adding:

set(OpenCV_opencv_java_LIBNAME_OPT "libopencv_java.so") set(OpenCV_opencv_java_DEPS_OPT ) set(OpenCV_opencv_java_EXTRA_DEPS_OPT )

Now arm-linux-androideabi-objdump -p libOpenCV.so confirms that it links against libopencv_java.so.

cooperz gravatar imagecooperz ( 2012-10-30 12:03:05 -0600 )edit

Question Tools

Stats

Asked: 2012-10-22 12:58:26 -0600

Seen: 863 times

Last updated: Oct 29 '12