Ask Your Question

unsigned short 1D array to Mat

asked 2019-02-22 22:30:27 -0500

ymw gravatar image

hi, how can I convert unsigned short array to Mat in opencv ? unsigned short array[220*220]//contain pixel values of image

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2019-02-23 02:22:50 -0500

gino0717 gravatar image

updated 2019-02-23 02:23:38 -0500

ushort is CV_16U type, so if your array called H, then

Mat h = Mat(220,220,CV_16U,H);

to check it:

ushort H[4] = {1,2,3,4}; Mat h = Mat(2,2,CV_16U,H);
cout<<"take a look="<<h<<endl;

the output of h would same as H

edit flag offensive delete link more


gino0717, thanks for the reply, but I cannot see my image when I use imshow("h",h);

ymw gravatar imageymw ( 2019-02-23 02:30:47 -0500 )edit

you may not see image in CV_16U, try to .convertTo() CV_8U and imshow it

gino0717 gravatar imagegino0717 ( 2019-02-23 02:34:16 -0500 )edit

Mat t; h.convertTo(t,CV_8U); this is what you mean right?

ymw gravatar imageymw ( 2019-02-23 02:40:59 -0500 )edit

yeah, try it

gino0717 gravatar imagegino0717 ( 2019-02-23 02:42:19 -0500 )edit
Login/Signup to Answer

Question Tools

1 follower


Asked: 2019-02-22 22:30:27 -0500

Seen: 23 times

Last updated: Feb 23