Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

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_32) { //float !
    float[] buffer = new float[mat.total() * mat.channels()]; 
    ... etc

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_32) { //float !
    float[] buffer = new float[mat.total() * mat.channels()]; 
    ... etc

the reverse is simply:

Mat m(height, width, type);
m.put(0,0,buffer);

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_32) 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);