zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    Vue学录 (第三章)
    Vue学录 (第二章)
    Vue 学录 (第一章)
    SpringBoot 学集 (第七章) 数据访问
    Leetcode789 阻碍逃脱者 曼哈顿距离
    Leetcode707 设计链表 双向链表实现
    leetcode 743 网络延迟时间 Dijkstra算法
    Leetcode676 实现魔法字典
    Leetcode443 压缩字符串 双指针原地压缩算法
    Leetcode23 合并K个升序链表
  • 原文地址:https://www.cnblogs.com/573177885qq/p/9072823.html
Copyright © 2011-2022 走看看