Opencv Java Convert Mat object to bytebuffer
Hi I want to convert Mat Object to bytebuffer Can you please help here
Hi I want to convert Mat Object to bytebuffer Can you please help here
ok, you can use Mat.get() to copy all of the pixels into a buffer:
//but first : check !
if (mat.depth() == CvType.CV_8U) { //bytes !
byte[] buffer = new byte[mat.total() * mat.channels()];
mat.get(0,0,buffer);
} else
if (mat.depth() == CvType.CV_32F) { //float !
float[] buffer = new float[mat.total() * mat.channels()];
... etc
the reverse is simply:
Mat m(height, width, type);
m.put(0,0,buffer);
I have did code as below:
Mat m = new Mat (720, 1280, CvType.CV_8U);
m.put(0,0,vf.rawData.getBytes());
Imgproc.putText(m, "Welcome", new Point(250,100),
Core.FONT_ITALIC, 4.0 ,new Scalar(222),2);
byte[] buffer = new byte[((int)m.total())*m.channels()];
m.get(0,0,buffer);
I think there is problem with below: byte[] buffer = new byte[((int)m.total())*m.channels()]; m.get(0,0,buffer);
But I am getting error as below:
Corrupt JPEG data: bad Huffman code
Corrupt JPEG data: premature end of data segment
Corrupt JPEG data: bad Huffman code
Asked: 2018-10-25 04:53:49 -0600
Seen: 4,563 times
Last updated: Oct 27 '18
Unresolved inclusion in OpenCV+Android tutorial
How to convert Floating point image to 32-bit single-channel?
How to translate this to Java?
android: how to put a column into Mat
OpenCV Tutorial 1 - Add OpenCV on API 8
Running the OpenCV4Android application on my PC
Using OpenCV as a stress detector
what does
bytebuffer
mean exactly, here ? did you mean abyte[]
? or this ?please be concise !
Its byte[]
I am working on project where we are displaying the videos, I want to add the text to the video. So I am trying to convert byte[] to Mat Object, then add text to it, then again convery Mat object to byte[]. I need help in converting below 2 things
1> byte[] to Mat object, 2> Mat Object to byte[].
How can I achieve it..
there's
putText()
, look it up.