Ask Your Question
0

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

asked 2016-01-14 03:48:49 -0600

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.

edit retag flag offensive close merge delete

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 ( 2016-01-14 03:53:17 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2016-01-14 04:12:24 -0600

ocv_user gravatar image

Thank you so much. It solved the problem!

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2016-01-14 03:48:49 -0600

Seen: 187 times

Last updated: Jan 14 '16