Yaron Vazana

NLP, Algorithms, Machine Learning, Data Science, tutorials, tips and more

  • About
  • Blog
  • Projects
  • Medium

Contact Me

yaronv99 [at] gmail.com

Powered by Genesis

You are here: Home / Android / How To Add OpenCV To Your Android App

How To Add OpenCV To Your Android App

January 20, 2016 by Yaron 4 Comments

OpenCV is an open source library which provides a wide range of machine learning and computer vision algorithms. OpenCV original library is written in C++ but there are wrappers for other major programming languages, including Java (for android).

Since I use OpenCV quite often, I decided to dedicate a separate post and write a tutorial on how to add the library to an existing android application, developed in android studio.

OpenCV for android

General OpenCV Installation

Whether you’re using a real android device for testing and running your application, or using the integrated android emulator inside the android studio IDE,  you need to follow those steps:

  • Download OpenCV SDK for Android, and extract it somewhere in your home folder – I use the 241 version
  • Make sure your App build.gradle file looks like this – you need to add the OpenCV compile command. (Alternatively you can add a new module from the file -> Project Structure menu)
  • Create a new folder named jniLibs inside app/src/main and copy all content from SDK_FOLDER/SDK/native/libs into the new folder jniLibs
  • Build -> Rebuild Project

In case you encounter build errors, it means your app SDK version and OpenCV SDK version does not match. Open the build.grade file of the OpenCV library (important) and make sure those values match the values in your app build.grade file:

  • compileSdkVersion
  • buildToolsVersion
  • minSdkVersion
  • targetSdkVersion

Developing On a Real Device

In case you connect your real android device to your computer and use it for running your app, you won’t need to install the library on the emulator. In this case, just install the OpenCV manager android app from the play store. You can actually skip this because when you will run your app, your device will automatically ask you to install it.

Developing On The Emulator

In case you use the built in android emulator, you need to install the OpenCV library inside it

  • Start the emulator from the android studio by clicking the play button
  • Open a terminal and navigate to SDK_FOLDER/apk and execute this command to install the OpenCV in your emulator:

$adb install OpenCV_2.4.11_Manager_2.20_x86.apk

Initialize OpenCV Library In Your Code

Conclusion

Installing OpenCV is not hard but requires some work. Don’t worry, you only need to do it once. I found it much easier to use a real device for development instead of the integrated emulator, a real device just performs better.

Subscribe to Blog

Subscribe to get the latest posts to your inbox

Cheers

Filed Under: Android, Mobile Tagged With: Android, Android Studio, Apps, Material Design, Mobile, Open CV, Programming

I am a data science team lead at Darrow and NLP enthusiastic. My interests range from machine learning modeling to solving challenging data related problems. I believe sharing ideas is where we all become better in what we do. If you’d like to get in touch, feel free to say hello through any of the social platforms. More About Yaron…

SUBSCRIBE TO BLOG

Subscribe to Blog

Subscribe to get the latest posts to your inbox

Recent Posts

  • Training an AutoEncoder to Generate Text Embeddings
  • Using Dockers for your Data Science Dev Environment
  • Identifying Real Estate Opportunities using Machine Learning
  • How to Create a Simple WhatsApp Chatbot in Python using Doc2vec
  • Average Word Vectors – Generate Document / Paragraph / Sentence Embeddings
  • Visualizing Vectors using TensorBoard
  • Training a Doc2Vec Model with Gensim
 

Loading Comments...