Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

I'm having trouble accessing the intensity value of a CV_U8 gray image in C++ using the image.at() function and image.ptr() function

In a larger context, I'd like to perform a sweep on detected circle object in a image, but cannot get a reasonable intensity value or I guess access the pixel correctly. I expect a uchar pixel type with values from 0-255. When I run the code, I get outputs that either involve letters or numbers that are much too low to be correct.

I use cvtColor() to first change a RGB image to Gray. The RGB image is originally a CV_8UC3 type mat image. I am also using openCV 3.0.

Here's a small snippet of code where I try to display a pixel value in the terminal. Here, circles is a vector of vectors, and I'm using it to access the center point of the detected circle object. When I draw the detected circles on the image and display it, there seems to be no issue.

Point2f center(cvRound(circles[0][0]), cvRound(circles[0][1]));
int x = round(circles[0][0]);
int y = round(circles[0][1]);
printf("center: %x\n", image.at<uchar>(center));
printf("center: %x\n", image.at<uchar>(circles[0][0], circles[0][1]));
printf("center: %x\n", *image.ptr<uchar>(x, y));

Thanks! Rowan

I'm having trouble Trouble accessing the intensity value of a CV_U8 gray image in C++ using the image.at() function and image.ptr() functionC++

In a larger context, I'd like to perform a sweep on detected circle object in a image, but cannot get a reasonable intensity value or I guess access the pixel correctly. I expect a uchar pixel type with values from 0-255. When I run the code, I get outputs that either involve letters or numbers that are much too low to be correct.

I use cvtColor() to first change a RGB image to Gray. The RGB image is originally a CV_8UC3 type mat image. I am also using openCV 3.0.

Here's a small snippet of code where I try to display a pixel value in the terminal. Here, circles is a vector of vectors, and I'm using it to access the center point of the detected circle object. When I draw the detected circles on the image and display it, there seems to be no issue.

Point2f center(cvRound(circles[0][0]), cvRound(circles[0][1]));
int x = round(circles[0][0]);
int y = round(circles[0][1]);
printf("center: %x\n", image.at<uchar>(center));
printf("center: %x\n", image.at<uchar>(circles[0][0], circles[0][1]));
printf("center: %x\n", *image.ptr<uchar>(x, y));

Thanks! Rowan