OpenCV with Android Studio

Untitled

Pre-requisites:

Download OpenCV for Android from https://sourceforge.net/projects/opencvlibrary/files/opencv-android/3.1.0/OpenCV-3.1.0-android-sdk.zip/download

Download and Install Android Studio from https://developer.android.com/studio/install.html

 

 

  1. Open Android Studio File -> New Project
    Untitled
  2. Select No Activity and Finish.
    Untitled
  3. Create a folder called “libraries” inside your Android Studio project, and copy the folder sdk/java to this folder. Rename it to “opencv”.
    Untitled
  4. Now, inside this “opencv” folder, create a build.gradle file, with the following content:
  5. Edit your gradlefile in your application’s main directory and add this line:
  6. Tools -> Android -> Sync Project with Gradle files
    Untitled
  7. Go to File -> Project Structure, inside Modules pick your ‘app’, then from the Tab pick: Dependencies, click + to add new dependency, pick Module Dependency, and add :library:opencv dependency to your project. Click OK.
    Untitled
  8. Create a jniLibs folder in the /app/src/main/ location and copy the all the folders from the OpenCV Android SDK/native/libs folder here.
    Untitled
  9. Sync again and build it.

To run OpenCV sample applications:

  • Delete java and res folders from app/src/main.
  • Go to the OpenCV for Android/samples and copy res and src folder and manifest file from any sample and paste them in your app/src/main.
  • Rename src to java.
  • Build and run.Here’s the application running
    Untitled

For OpenCV with Eclipse tutorial, go here.

3 Comments

  1. Pingback: OpenCV with Android on Eclipse | SensoVision Systems

  2. Victor

    Great tutorial, got it working in here! Can you please make one on how to run OpenCV samples with jni files? For instance face detection sample. Thank you very much!

    Reply
    1. admin

      Thank you. Working on OpenCV with Android NDK. Will let you know once it finishes.

      Reply

Leave a Comment

Your email address will not be published. Required fields are marked *