make Mat from buffer byte
Hi,
I have a Byte buffer and i want to make a Mat.How can i achieve it using a java code?Should i make a bitmap with the byte buffer first then transform it to Mat?
Hi,
I have a Byte buffer and i want to make a Mat.How can i achieve it using a java code?Should i make a bitmap with the byte buffer first then transform it to Mat?
You need to allocate a Mat
of the appropriate size and type and then use Mat.put()
method:
byte buf[] = new byte[100];
//...
Mat m = new Mat(1, 100, CvType.CV_8UC1);
m.put(0, 0, buf);
@TimeManx No, it's not possible: Mat
reallocates its buffer on native level when needed, so it's hard to share it between native and java without copying...
In JavaCV's OpenCV wrapper, the IplImage has a "getDirectByteBuffer" native method that will from JNI create a new ByteBuffer with the address of the data of the Mat. In my tests modifying pixels like that performs much better than copying byte arrays to and from the Mat.
Just created a feature request (http://code.opencv.org/issues/3405) and attached the result of my tests.
Hi i think you can ref : http://answers.opencv.org/question/4761/mat-to-byte-array/#4923
Asked: 2013-03-23 11:55:03 -0600
Seen: 16,296 times
Last updated: Mar 25 '13
OpenCV Tutorial 1 - Add OpenCV on API 8
Unresolved inclusion in OpenCV+Android tutorial
build problems for android_binary_package - Eclipse Indigo, Ubuntu 12.04
Installing Sample App / OpenCV Manager
How to translate this to Java?
android: how to put a column into Mat
OpenCV-2.4.2-android-sdk missing build.xml?
OpenCV libs on Real Android Device