5

请耐心等待 - 这是一个很长的描述,但我想包括所有细节。我正在尝试使用 android NDK 和 JNI 来构建 OpenCV Android 应用程序。

我正在按照本教程安装所有内容:http: //www.stanford.edu/class/ee368/Android/Tutorial-2-OpenCV-for-Android-Setup-Macintosh-API8.pdf

以下安装就好了:

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

我的 .bashrc 文件的内容:

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

制作 OpenCV 库一切顺利。

由于使用中的抱怨make,我不得不做一个小编辑/Users/Me/Code/OpenCV/opencv/android/android-jni/local.env.mk,看起来像这样:

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

然后在 android-jni 目录中再次尝试时make,灾难发生了:

/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

我想这可能是一个 pkg-config 错误,但似乎也设置了,尽管在我旧安装的 OpenCV 中。下面是输出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 

此特定教程构建的安装已opencv.pc在此位置放置了一个文件:

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

但是运行以下并重试make并不能解决问题:

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

我不知道出了什么问题。我一直在与这个问题作斗争大约一个月,最后需要一些外部意见。有任何想法吗?

4

2 回答 2

2

错误信息说

找不到 -lopencv_calib3d collect2:ld 返回 1 退出状态

这意味着链接器找不到 opencv_calib3d 库。它可能有名称 libopencv_calib3d.a 或 libopencv_calib3d.so。因此,您需要找到其中一个并将此文件的路径添加到您的 LD_LIBRARY_PATH 环境变量中。

我的意思是,如果假设文件夹 /Users/Me/Code/OpenCV/opencv/lib 包含 libopencv_calib3d.so 那么您需要在 make 之前执行以下操作:

export LD_LIBRARY_PATH=/Users/Me/Code/OpenCV/opencv/lib:$LD_LIBRARY_PATH
于 2013-05-16T20:39:26.253 回答
0

在http://docs.opencv.org/trunk/doc/tutorials/introduction/android_binary_package/android_dev_intro.html尝试官方 OpenCV4Android 教程

于 2013-05-12T09:59:47.370 回答