First time here? Check out the FAQ!

Ask Your Question
0

Unable to store stort[] array in Matrix object : OpenCV Java

asked Jan 14 '16

ocv_user gravatar image

Hi, I am trying to store a short[1280*1024] 1D array in Mat object and and trying to create an image out of it. Below is code:

Mat mat1=new Mat();
mat1.create(1280, 1024, CvType.CV_16UC1);
mat1.put(1280, 1024,pix);  //pix is short[1280*1024]
Imgcodecs.imwrite("/../pic.png", mat1);

The put() function is not able to store all the [1280*1024] elements in the cells of the matrix. Only around 1/4th of the data seems to be stored. The rest are all 0s. I would be grateful if anyone can throw some light on this and tell if this is the right way to store the array into Matrix object.

Preview: (hide)

Comments

1

mat1.put(1280, 1024,pix); <-- this is storing your pixels outside (after the last pixel).

i'm pretty sure, you wanted to store it, beginning with the 1st pixel, like: mat1.put(0, 0,pix);

berak gravatar imageberak (Jan 14 '16)edit

1 answer

Sort by » oldest newest most voted
0

answered Jan 14 '16

ocv_user gravatar image

Thank you so much. It solved the problem!

Preview: (hide)

Question Tools

1 follower

Stats

Asked: Jan 14 '16

Seen: 219 times

Last updated: Jan 14 '16