Ask Your Question
0

Building JNI for OpenCV in Android

asked 2013-05-11 20:35:01 -0600

cvforall gravatar image

updated 2013-05-11 20:36:06 -0600

Bear with me - this is a long description, but I wanted to include all details. I'm trying use android NDK and JNI for building OpenCV Android apps. I've also tried posting on SO with no avail.

I'm following this tutorial to get everything installed: http://www.stanford.edu/class/ee368/Android/Tutorial-2-OpenCV-for-Android-Setup-Macintosh-API8.pdf

The following installed just fine:

/usr/bin/g++
/usr/local/bin/swig
/usr/bin/cmake
/usr/bin/make
/Developer/pcre-8.32/

Contents of my .bashrc file:

export  NDK=/Users/Me/Code/Android/android-ndk-r4-crystax
export  SDK=/Users/Me/Code/Android/adt-bundle-mac-x86_64-20130219/
export  OPCV=/Users/Me/Code/OpenCV/opencv
export  PATH=$NDK:$SDK/tools:$SDK/platform-tools:$PATH
export NDK_ROOT=$NDK

Making OpenCV libraries went just fine.

Due to complaint in using make, I had to make a small edit in /Users/Me/Code/OpenCV/opencv/android/android-jni/local.env.mk which looked like so:

#ANDROID_NDK_ROOT=$(HOME)/android-ndk-r4-crystax
ANDROID_NDK_ROOT=/Users/Me/Code/Android/android-ndk-r4-crystax

Then upon trying again to make in the android-jni, directory, disaster struck:

/Users/Me/Code/Android/android-ndk-r4-crystax/ndk-build OPENCV_CONFIG=../build/android-opencv.mk \
    PROJECT_PATH= ARM_TARGETS="armeabi armeabi-v7a" V= 
Gdbserver      : [arm-eabi-4.4.0] /Users/Me/Code/OpenCV/opencv/android/android-jni/libs/armeabi/gdbserver
Gdbsetup       : /Users/Me/Code/OpenCV/opencv/android/android-jni/libs/armeabi/gdb.setup
Gdbsetup       : + source directory /Users/Me/Code/OpenCV/opencv/android/android-jni/jni
Gdbserver      : [arm-eabi-4.4.0] /Users/Me/Code/OpenCV/opencv/android/android-jni/libs/armeabi-v7a/gdbserver
Gdbsetup       : /Users/Me/Code/OpenCV/opencv/android/android-jni/libs/armeabi-v7a/gdb.setup
Gdbsetup       : + source directory /Users/Me/Code/OpenCV/opencv/android/android-jni/jni
SharedLibrary  : libandroid-opencv.so
/Users/Me/Code/Android/android-ndk-r4-crystax/build/prebuilt/darwin-x86/arm-eabi-4.4.0/bin/../lib/gcc/arm-eabi/4.4.0/../../../../arm-eabi/bin/ld: cannot find -lopencv_calib3d
collect2: ld returned 1 exit status
make[1]: *** [/Users/Me/Code/OpenCV/opencv/android/android-jni/obj/local/armeabi/libandroid-opencv.so] Error 1
make: *** [libs/armeabi-v7a/libandroid-opencv.so] Error 2

I thought perhaps this was a pkg-config error, but that appears to be set up as well, though in my old install of OpenCV. Below is the output of pkg-config --cflags --libs opencv:

-I/usr/include/opencv  /usr/lib/libopencv_calib3d.dylib /usr/lib/libopencv_contrib.dylib /usr/lib/libopencv_core.dylib /usr/lib/libopencv_features2d.dylib /usr/lib/libopencv_flann.dylib /usr/lib/libopencv_gpu.dylib /usr/lib/libopencv_highgui.dylib /usr/lib/libopencv_imgproc.dylib /usr/lib/libopencv_legacy.dylib /usr/lib/libopencv_ml.dylib /usr/lib/libopencv_nonfree.dylib /usr/lib/libopencv_objdetect.dylib /usr/lib/libopencv_photo.dylib /usr/lib/libopencv_stitching.dylib /usr/lib/libopencv_ts.dylib /usr/lib/libopencv_video.dylib /usr/lib/libopencv_videostab.dylib

The install built by this particular tutorial has placed an opencv.pc file at this location:

/Users/Me/Code/OpenCV/opencv/build/unix-install

BUT Running the below and trying make again doesn't fix the problem:

export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/Users/Me/Code/OpenCV/opencv/build/unix-install

Any ideas on how I can complete this build?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2013-05-12 04:59:00 -0600

Andrey Pavlenko gravatar image

The official up-to-date tutorials are here:

  1. Introduction into Android Development
  2. OpenCV4Android SDK
  3. Android Development with OpenCV

Try them please.

edit flag offensive delete link more

Comments

the tutorial I linked should work just fine, it is used by stanford as recent as last month. it's also not really an answer to my question. do you have any specific recommendations given the build error I have above?

cvforall gravatar imagecvforall ( 2013-05-12 21:17:14 -0600 )edit
1

the answer is that there are official tutorials that are tested and supported by OpenCV dev team; so if some 3rd-party tutorial doesn't work it makes sense to try the official ones!

as for specific recommendations - I'm not sure the recent OpenCV4Android supports such an old NDK as r4, at least we don't test it with NDK older than r8.

Andrey Pavlenko gravatar imageAndrey Pavlenko ( 2013-05-13 03:18:53 -0600 )edit

Question Tools

Stats

Asked: 2013-05-11 20:35:01 -0600

Seen: 1,173 times

Last updated: May 12 '13