Coder Social home page Coder Social logo

tommyteavee / android-kotlin-native-cv-examples Goto Github PK

View Code? Open in Web Editor NEW

This project forked from linkedopenknowledge/android-kotlin-native-cv-examples

0.0 0.0 0.0 74.83 MB

Some examples of OpenCV on Android

CMake 0.04% Kotlin 0.10% C 4.96% C++ 72.61% Objective-C 0.17% Java 22.13%

android-kotlin-native-cv-examples's Introduction

Android-Kotlin-Native-CV-Examples

This is a Android Studio Kotlin project to demo some OpenCV operations. Some examples include native OpenCV functions and JNI calls.

Requirement:

Android Studio 3+

OpenCV version: 3.4.1

How to create the native OpenCV project

  • Make sure you have Android SDK up to date, with NDK installed and CMake

  • Download OpenCV SDK for Android from OpenCV.org and decompress the zip file

  • Create a new Android Studio project

    • Check Include C++ and Kotlin support
    • Choose empty Activity
    • In C++ Support, you can check -fexceptions and -frtti
  • Import OpenCV library module

    • New -> Import Module

    • Choose the YOUR_OPENCV_SDK/sdk/java folder

    • Unckeck replace jar, unckeck replace lib, unckeck create gradle-style

    • Set the OpenCV library module up to fit your SDK

      Edit openCVLibrary/build.gradle to fit your SDK:

      compileSdkVersion 28
      defaultConfig {
          minSdkVersion 25
          targetSdkVersion 28
      }
      
    • Add OpenCV module dependency in your app module

      • File -> Project structure -> Module app -> Dependencies tab -> New module dependency -> choose OpenCV library module
  • Create a folder named jniLibs in app/src/main and copy the files from YOUR_OPENCV_SDK/sdk/native/libs to that folder

    • Set the app build.gradle

      Add abiFilters

      externalNativeBuild {
          cmake {
              cppFlags "-frtti -fexceptions"
              abiFilters 'x86', 'x86_64', 'armeabi-v7a', 'arm64-v8a'
          }
      }
      
    • Add openCV jniLibs directory to point to the libs

      sourceSets {
          main {
              jniLibs.srcDirs = ['src/main/jniLibs']
          }
      }
      
  • Create a folder named include in app/src/main/cpp/include and copy the header files from YOUR_OPENCV_SDK/sdk/native/jni/include.

  • Configure the CMakeLists.txt file

    • After the cmake_minimum_required, add

      include_directories(src/main/cpp/include)
      add_library( lib_opencv SHARED IMPORTED )
      set_target_properties(lib_opencv PROPERTIES IMPORTED_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/src/main/jniLibs/${ANDROID_ABI}/libopencv_java3.so)
      
    • At the end of the file add lib_opencv to the target_link_libraries list

      target_link_libraries(
              native-lib
              lib_opencv
              ${log-lib})
      
  • Grant camera permission

    • Add the following lines in the AndroidManifest.xml file

      <uses-permission android:name="android.permission.CAMERA"/>
      <uses-feature android:name="android.hardware.camera"/>
      <uses-feature android:name="android.hardware.camera.autofocus"/>
      <uses-feature android:name="android.hardware.camera.front"/>
      <uses-feature android:name="android.hardware.camera.front.autofocus"/>
      

Activities

android-kotlin-native-cv-examples's People

Contributors

bbclr20 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.