Ask Your Question
0

unsigned short 1D array to Mat

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

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
2

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

gino0717 gravatar image

updated 2019-02-23 02:23:38 -0600

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

Comments

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 -0600 )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 -0600 )edit

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

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

yeah, try it

gino0717 gravatar imagegino0717 ( 2019-02-23 02:42:19 -0600 )edit

Question Tools

1 follower

Stats

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

Seen: 1,849 times

Last updated: Feb 23 '19