Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Convert Mat to MatOfByte in Android

I got a Mat from OpenCV's camera. And I want to convert it to a MatOfByte or a byte[]. But I got runtime error in my code:

Mat mGray = new Mat();    
capture.retrieve(mGray, Highgui.CV_CAP_ANDROID_GREY_FRAME);
MatOfByte mGrayByte = new MatOfByte(mGray);

I got the error:

10-04 12:50:35.470: E/AndroidRuntime(25086): java.lang.IllegalArgumentException: Incomatible Mat 10-04 12:50:35.470: E/AndroidRuntime(25086): at org.opencv.core.MatOfByte.<init>(MatOfByte.java:29)

The error line is:

MatOfByte mGrayByte = new MatOfByte(mGray);