@Andrey Pavlenko i want to convert a Mat CV_8UC4 to byte[] but don't work any of those solution!
Marwen Z ( 2013-04-07 06:45:43 -0500 )editFor 8UC4 (or any 8UCx) you need:
byte[] data = new byte[ (int) (mRgba.total() * mRgba.channels()) ];
mRgba.get(0, 0, data);
Andrey Pavlenko (
2013-04-08 00:57:30 -0500
)edityes i try it but not working, i found another solution is to convert Mat to Bitmap then to Byte[]
Utils.matTobitmap(mRgba,bitmap); ByteArrayOutputStream os = new ByteArrayOutputStream(); bitmap.compress(CompressFormat.PNG, 100, os); bytes[] data= os.toByteArray(); //the opposite case : BitmapFactory.decodeByteArray(bytes, 0, bytes.length);
How you thnig about it ? it's efficace !
Marwen Z (
2013-04-08 04:07:10 -0500
)editthis introduces extra copying, what are the problems using Mat.get() ?
but what does your_mat.toString() returns? your_mat.total()?
For what purpose do you want to use MatOfByte? Maybe there are better solutions.
Rui Marques ( 2012-10-04 04:58:08 -0500 )editI want to pass the Image to Tesseract-OCR api with byte data array. Because I don't want to convert it to bitmap.
http://fossies.org/dox/tesseract-3.01/group__AdvancedAPI.html#gaa463622111f3b11d8fca5863709cc699
Quill Hon ( 2012-10-05 22:16:44 -0500 )edit