converting from pixel array (rgba) to Mat - (java API)

asked 2013-07-18 16:21:04 -0600

agforte gravatar image

updated 2013-07-18 16:21:47 -0600

Hi all,

I am struggling on how to convert the pixel array of an image

int [] pixels = new int[myheight * mywidth];

to a Mat so that I can apply various transformations. I have tried the following (and more):

decodeYUV420SP(pixels, data, mywidth, myheight);
Mat mRgbaRaw = new Mat(myheight, mywidth, CvType.CV_8UC4);
mRgbaRaw.put(0, 0, pixels);

but it gives me the error:

Exception in thread "main" java.lang.UnsupportedOperationException: Mat data type is not compatible: 24
    at org.opencv.core.Mat.put(Mat.java:2511)

Anyone knows how to do this?

Thanks a lot!

edit retag flag offensive close merge delete

Comments

2

CvType.CV_8UC4 != int !

it means, that you probably need to supply a byte[4] per pixel in mRgbaRaw.put(i,j, pixel); // *1* pixel at a time, too

berak gravatar imageberak ( 2013-07-18 16:54:53 -0600 )edit