Android – Como converter um byte[] em um objeto Mat utilizando o OpenCV no Android (How to get the Mat object from the Byte[] in openCV android?)

Simples assim:

Mat mat = Imgcodecs.imdecode(
    new MatOfByte(bytes), Imgcodecs.CV_LOAD_IMAGE_UNCHANGED

Como converter um Bitmap em um objeto Mat:


Mat mat = new Mat();    
Bitmap bmp32 = bmp.copy(Bitmap.Config.ARGB_8888, true);
Utils.bitmapToMat(bmp32, mat);

Android – Detecção facial utilizando o OpenCV (OpenCV in Android Studio with face detect)


Detecção facial utilizando OpenCV no Android – OpenCV in Android Studio with face detect

This application is a sample Android Studio project (tested on gradle 3.0.1) with ‘Android SDK OpenCV 3.3.1’



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

  • Make sure you have Android SDK up to date, with NDK installed
  • Download latest OpenCV SDK for Android from 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