• android 使用opencv


    1、将已有的项目名称改名字,但一直报错

    Error:A problem occurred configuring project ':app'.
    > executing external native build for cmake /home/xia/ncnn_demo/ssd_mobilenet_opencv/app/CMakeLists.txt

    解决办法:直接删掉app/.externalNativeBuild即可

    2、在main下新建文件夹jniLibs,将OpenCV SDK 目录 sdk ativelibs 下的 armeabiarmeabi-v7a 复制到  jniLibs 目录下;

    3、修改CMakeLists.txt

    # Sets the minimum version of CMake required to build the native
    # library. You should either keep the default value or only pass a
    # value of 3.4.0 or lower.
    
    
    #include头文件目录
    include_directories(src/main/cpp/include
                        src/main/cpp/)
    
    #source directory源文件目录
    file(GLOB SSD_SRC src/main/cpp/*.h
                        src/main/cpp/*.cpp)
    set(SSD_COMPILE_CODE ${SSD_SRC})
    
    
    cmake_minimum_required(VERSION 3.4.1)
    
    # Creates and names a library, sets it as either STATIC
    # or SHARED, and provides the relative paths to its source code.
    # You can define multiple libraries, and CMake builds it for you.
    # Gradle automatically packages shared libraries with your APK.
    
    add_library(libncnn STATIC IMPORTED )
    set_target_properties(libncnn
      PROPERTIES IMPORTED_LOCATION
      ${CMAKE_SOURCE_DIR}/src/main/jniLibs/${ANDROID_ABI}/libncnn.a)
    
    # opencv import libs
    
    set(pathToOpenCV /home/xia/OpenCV-android-sdk)
    
    include_directories( ${pathToOpenCV}/sdk/native/jni/include )
    add_library( lib_opencv SHARED IMPORTED )
    set_target_properties( lib_opencv
     PROPERTIES IMPORTED_LOCATION
      ${CMAKE_SOURCE_DIR}/src/main/jniLibs/${ANDROID_ABI}/libopencv_java3.so)
    
    
    
    
    #编译为动态库
    add_library(ssd SHARED ${SSD_COMPILE_CODE})
    
    #添加工程所依赖的库
    find_library(  log-lib log )
    target_link_libraries( ssd
                           libncnn
                           lib_opencv
                           jnigraphics
                           z
                           ${log-lib}
                            )

    4、在cpp文件中调用即可

    参考:https://blog.csdn.net/youngpan1101/article/details/53614588

  • 相关阅读:
    android apk 反编译
    js 读 xml 非ie 可以支持 chrome 浏览器 与 android webView
    php+mySQl 环境搭建
    Activity 生命周期
    div 隐藏 显示 占空间 不占空间
    android 异步加载
    android 文件操作
    透明 GridView 背景透明
    eclipse 版本理解
    WebKit 上的JS直接使用Java Bean
  • 原文地址:https://www.cnblogs.com/573177885qq/p/9072823.html
Copyright © 2020-2023  润新知