1. 程式人生 > >android opencv配置及執行時不用opencv Manager即可執行APP

android opencv配置及執行時不用opencv Manager即可執行APP

各種教學視訊或文件資料 +QQ:635992897

  1. 準備Android-ndk Android-sdk eclipse(ADT+CDT) Java-JDK opencv android SDK軟體包並配置好Java環境

  2. 將opencv android SDK拷貝到Android工程目錄下,將OpenCV-2.4.10-android-sdk\sdk\java匯入到專案

  3. 配置NDK

  4. 新建一個呼叫opencv的Android專案,讓此專案支援JNI(eclipse直接編譯so,之前寫錯了,應該是載入native的support)

  5. 新增opencv依賴庫

  6. 新增opencv標頭檔案

  7. 將Android opencv SDK armeabi-v7a中的libopencv_java.so拷貝到JNI目錄下並在Android.mk中新增
    #OpenCV_INSTALL_MODULES:=on
    #OPENCV_CAMERA_MODULES:=off
    OPENCV_LIB_TYPE:=SHARE
    ifeq ("$(wildcard $(OPENCV_MK_PATH))","") 
    #try to load OpenCV.mk from default install location 
    include D:/Ovationsoft/Android/lxctest/OpenCV-2.4.10-android-sdk/sdk/native/jni/OpenCV.mk 
    else 
    include $(OPENCV_MK_PATH) 
    endif 
    include $(CLEAR_VARS)
    LOCAL_MODULE := opencv_java
    LOCAL_SRC_FILES := libopencv_java.so
    include $(PREBUILT_SHARED_LIBRARY)

  8. 建立Java呼叫JNI的類

  9. 在OnClickListener新增:  static {
         System.loadLibrary("TongueProcess"); 
      if (!OpenCVLoader.initDebug()) {
    //   Log.i("test", "OpenCVLoader.initDebug() 失敗");
      } else {
       System.loadLibrary("opencv_java");
      }
     }

  10. 進入到專案bin/classes目錄,javah包名+類名生成標頭檔案並將標頭檔案拷貝到JNI

    目錄

  11. 建立CPP檔案,並在Android.mk中新增

    LOCAL_MODULE   := ImgFun

    LOCAL_SRC_FILES :=com_ovation_healthmirror_utils_TestOpencv.cpp

    include$(BUILD_SHARED_LIBRARY)

  12. 直接Build Project即可生成so(build前要把引用的第三方so庫拷貝到JNI目錄下做備份並在Android.mk中配置

    include$(CLEAR_VARS)

LOCAL_MODULE := BaiduMapSDK_base_v3_7_0

LOCAL_SRC_FILES :=libBaiduMapSDK_base_v3_7_0.so

include$(PREBUILT_SHARED_LIBRARY)