Ask Your Question

question of reading pixel

asked 2018-01-16 03:09:20 -0500

Weifa Gan gravatar image

when reading pixel of image,using this sentence: (unsigned int)<uchar>(y, x) I don't know that why use the data type,uchar. when i changed uchar to int,it will be error;

i just learn opencv,pleace help me to understand. Thank you.

edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted

answered 2018-01-16 03:43:33 -0500

kbarni gravatar image

For each image type you have the according data type: uchar for CV_8U, Vec3b for CV_8UC3, ushort for CV_16U, int for CV_32S, float for CV_32F etc.

Always use the according data type:

Mat image(100,100,CV_8UC1);

(you don't need a second type cast: pixel=(uchar)<uchar>(10,10);)

The pixel access in OpenCV is quite well explained in the docs.

It's also good to learn the pointer (line) access.

edit flag offensive delete link more


thanks your help

Weifa Gan gravatar imageWeifa Gan ( 2018-01-16 05:43:29 -0500 )edit

answered 2018-01-16 03:42:18 -0500

VxW gravatar image

you also have to learn C++, see e.g. C++ Templates

<uchar> is a template parameter and means that img_pyr2 must be of type uchar

if you would like to convert an uchar image to int you should use img_pyr2.convertTo(img_pyr_int, CV_32S);. Afterwards you can access the pixels via<int>(y, x)

edit flag offensive delete link more


thank you very much!

Weifa Gan gravatar imageWeifa Gan ( 2018-01-16 05:42:03 -0500 )edit
Login/Signup to Answer

Question Tools

1 follower


Asked: 2018-01-16 03:09:20 -0500

Seen: 250 times

Last updated: Jan 16 '18