garak
garak

Reputation: 4813

How do I convert ARGB_8888 image in Android to a Mat in Native OpenCV

I have an Image loaded as a Bitmap(config: ARGB_8888) in Android.

How do I convert it into a cv::Mat in Native OpenCV(C++) using JNI?

Upvotes: 0

Views: 2818

Answers (2)

gartenabfall
gartenabfall

Reputation: 260

If u have the opencv libraries for android installed then do it like isHwang has said.
Example:
// MatToBitmap:

Bitmap bmp = Bitmap.createBitmap(640, 480, Bitmap.Config.ARGB_8888);  
android.MatToBitmap(mat, bmp);   

// BitmapToMat

mat = android.BitmapToMat(bmp);

Upvotes: 1

Demian Hwang
Demian Hwang

Reputation: 180

There is a method to do that in the opencv android library. Check org.opencv.android package. In the Utils.java, there is bitmapToMat method, and it is implmented using its own Native Code. Then you can pass the Mat to jni by Mat.getNativeObjAddr().

Upvotes: 3

Related Questions