Coder Social home page Coder Social logo

android-opencv-cmake's Introduction

Android-opencv-cmake

Android 集成 opencv示例, 使用cmake 文件编译; 使用cmake的好处: studio原生支持, 方便debug c++库

如果直接导入OpenCV的SDK,然后通过opencv的Utils实现bitmap到cv::Mat的转换, 会加载所有so库, 导致最终的apk文件比较大。

如果使用jni直接编译opencv的cpp, 则只打包需求的部分, apk体积比较小

环境要求

  • Android Studio, ndk, opencv4, c++14

  • 在build.gradle中配置cmake参数

externalNativeBuild {
     cmake {
         cppFlags '-std=c++14'
     }
}
ndk {
      abiFilters  "armeabi-v7a"   //, "arm64-v8a","armeabi",
}
...
externalNativeBuild {
    cmake {
        path file('src/main/cpp/CMakeLists.txt')
        version '3.18.1'
    }
}

  • CMakeLists.txt
 cmake_minimum_required(VERSION 3.18.1)

project("cv_lib4")
set(PROJECT_NAME cv_lib4)
# opencv-android sdk
set(OpenCV_DIR "/mnt/app/local/opencv/openCV-android-sdk4/sdk/native/jni")
find_package(OpenCV REQUIRED)
message(STATUS "OpenCV libraries: ${OpenCV_LIBS}")

add_library(
        ${PROJECT_NAME}
        SHARED
        native-lib.cpp cv-lib.h cv-lib.cpp)

find_library(log-lib log)

target_link_libraries(
        ${PROJECT_NAME}
        ${log-lib}
        ${OpenCV_LIBS}
        jnigraphics)

License

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

android-opencv-cmake's People

Contributors

sunworthy avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.