Ask Your Question
0

question of reading pixel

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

Weifa Gan gravatar image

when reading pixel of image,using this sentence: (unsigned int)img_pyr2.at<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
2

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

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);
uchar pixel=image.at<uchar>(10,10);

(you don't need a second type cast: pixel=(uchar)img.at<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

Comments

thanks your help

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

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

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 img_py_int.at<int>(y, x)

edit flag offensive delete link more

Comments

thank you very much!

Weifa Gan gravatar imageWeifa Gan ( 2018-01-16 05:42:03 -0600 )edit

Question Tools

1 follower

Stats

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

Seen: 977 times

Last updated: Jan 16 '18