Ask Your Question

What is the correct way to convert a Mat to a Bitmap ?

asked 2015-01-10 13:39:06 -0500

sup gravatar image

updated 2015-01-10 14:02:21 -0500

I am working with OpenCV Android, I need to use a Java OCR library that works on bitmaps. Please, how can I convert my RGBA Mat (which by the way comes from Mat to a Bitmap ? Thanks

EDIT : I think I found the answer in the Utils class. But how to properly initialize the type of the Bitmap object so that it will be compatible with my Mat ?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2015-01-11 09:22:33 -0500

You are right, using matToBitmap from Utils class is the easiest way.

You can see the OpenCV Android examples for usages, something like this:

Mat myMat = mListener.onCameraFrame(frame);

Utils.matToBitmap(myMat, myBitmap);

According to the documentation:

  • mat is a valid input Mat object of the types 'CV_8UC1', 'CV_8UC3' or 'CV_8UC4'.
  • bmp is a valid Bitmap object of the same size as the Mat and of type 'ARGB_8888' or 'RGB_565'.
edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower


Asked: 2015-01-10 13:39:06 -0500

Seen: 9,285 times

Last updated: Jan 10 '15