Skip to content
프로젝트

leadrien/opencv_native_androidstudio

GitHub에서 보기

소개

An android studio project with native Opencv

기타 프로젝트

이 수치를 측정하는 방법

측정된 스타 증가

in 24h
0
in 7 days
0
in 15 days
0
in 1 month
기록 수집 중

서로 겹치는 기간의 순증가량이며 일별 합계가 아닙니다. 측정값이 없으면 비워 둡니다. 스타는 관심도를 나타내며 품질을 보장하지 않습니다.

README.md

Original

Native OpenCV with Android Studio

This application is a sample Android Studio project with native OpenCV.

It gets the camera frames, make JNI calls with its gray matrices references as parameters, add some random noise to the images from a C++ method, and render the generated frames.

It works with Android Studio 3+

Last included OpenCV version: 3.4

Usage

Here is how to use this project to run native OpenCV code.

  • Make sure you have Android SDK up to date, with NDK installed and CMake
  • Download latest OpenCV SDK for Android from OpenCV.org and decompress the zip file.
  • Clone this project
  • Create a symlink named jniLibs in app/src/main that points to YOUR_OPENCV_SDK/sdk/native/libs
  • In app/CMakeLists.txt change line 9 to points to YOUR_OPENCV_SDK/sdk/native/jni/include
  • Sync gradle
  • Run the application

How to create the native OpenCV project from scratch

Here is how I made this project. If you simply want to run openCV with NDK support, use the previous Usage chapter. If you want to build the full project from scratch, you can follow the steps in this chapter.

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

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

  • Create a new Android Studio project

    • Check Include C++ 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 27
      defaultConfig {
          minSdkVersion 19
          targetSdkVersion 27
      }
    
  • Add OpenCV module dependency in your app module

    File -> Project structure -> Module app -> Dependencies tab -> New module dependency -> choose OpenCV library module

  • Make a symlink named jniLibs in app/src/main that points to YOUR_OPENCV_SDK/sdk/native/libs

  • 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 symlink

      sourceSets {
          main {
              jniLibs.srcDirs = ['src/main/jniLibs']
          }
      }
      

    See build.gradle

  • Configure the CMakeLists.txt file

    • After the cmake_minimum_required, add

      include_directories(YOUR_OPENCV_SDK/sdk/native/jni/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

  • 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"/>
      
  • Add OpenCV code

관련 프로젝트 살펴보기

불러오는 중…