由于《Master OpenCV with Pratical Computer Vision Projects》对其Android例子的环境配置没有详细介绍,所以我通过自己的摸索,把相关经验拿来与大家分享,希望大家能够少走点弯路。
我的环境及对应的保存路径如下:
Cygwin——【C:\Cygwin_】
android-ndk-r9——【C:\Work\android-ndk-r9】(我自己用了r8编译报错,r9却没问题,错误如下所示)
C:/AndroidSDK_Eclipse/android-ndk-r8/toolchains/arm-linux-androideabi-4.4.3/prebuilt/windows/bin/../lib/gcc/arm-linux-androideabi/4.4.3/../../../../arm-linux-androideabi/bin/ld.exe: ./obj/local/armeabi-v7a/libopencv_contrib.a: No such file: Permission denied /cygdrive/c/AndroidSDK_Eclipse/android-ndk-r8/build/core/build-binary.mk:369: recipe for target `obj/local/armeabi-v7a/libcartoonifier.so' failed collect2: ld returned 1 exit status make: *** [obj/local/armeabi-v7a/libcartoonifier.so] Error 1
OpenCV-2.4.6-android-sdk——【C:\Work\OpenCV4Android\OpenCV-2.4.6-android-sdk】
具体步骤如下:
1.首先,将Cartoonifier_Android放在C:\Work\OpenCV4Android\OpenCV-2.4.6-android-sdk\samples目录下(如果不放在这目录下,需要在Android.mk中更改相应的OpenCV.mk路径),并从Cartoonifier_Desktop中把cartoon.cpp、cartoon.h、ImageUtils_0.7.cpp、ImageUtils.h放在jni目录下;
当然,我们也在该目录下新建一个includeOpenCV.mk文件来指定OpenCV文件的位置,内容如下
OPENCV_MK_PATH:=C:\Work\OpenCV4Android\OpenCV-2.4.6-android-sdk\sdk\native\jni\OpenCV.mk
2.接着,我们来看一下Android.mk文件的中需要修改的内容:
#/**************************************************************************** #* Cartoonifier, for Android. #***************************************************************************** #* by Shervin Emami, 5th Dec 2012 ([email protected]) #* http://www.shervinemami.info/ #***************************************************************************** #* Ch1 of the book "Mastering OpenCV with Practical Computer Vision Projects" #* Copyright Packt Publishing 2012. #* http://www.packtpub.com/cool-projects-with-opencv/book #****************************************************************************/ LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) OPENCV_LIB_TYPE:=STATIC OPENCV_INSTALL_MODULES:=on # Path to OpenCV.mk file, which is generated when you build OpenCV for Android. # include C:\OpenCV\android\build\OpenCV.mk # include ~/OpenCV/android/build/OpenCV.mk #include ../includeOpenCV.mk //把这句话注释 include ../../sdk/native/jni/OpenCV.mk //加上这句话,前提是我们的工程是放在OpenCV-2.4.6-android-sdk\samples目录下的 ifeq ("$(wildcard $(OPENCV_MK_PATH))","") #try to load OpenCV.mk from default install location #include $(TOOLCHAIN_PREBUILT_ROOT)/user/share/OpenCV/OpenCV.mk else #include $(OPENCV_MK_PATH) endif LOCAL_MODULE := cartoonifier LOCAL_LDLIBS += -llog -ldl # Since we have source + headers files in an external folder, we need to show where they are. LOCAL_SRC_FILES := jni_part.cpp LOCAL_SRC_FILES += cartoon.cpp //把desk_top项目中的源文件拷贝到Android目录下一起编译 LOCAL_SRC_FILES += ImageUtils_0.7.cpp LOCAL_C_INCLUDES += $(LOCAL_PATH) include $(BUILD_SHARED_LIBRARY)