I don't understand why output is a strange number when I run my code:
int main(int argc, char** argv)
{
Mat im;
im = imread("lena.png", CV_LOAD_IMAGE_GRAYSCALE);
cout << im.at<uchar>(0, 0) << endl;
waitKey(0);
}
If I visualize image I see the correct image. Where am I wrong?
Because it shows the symbol, like cout << char(123) << endl;
You have to use int cast:
cout << (int) im.at<uchar>(0, 0) << endl;
As stated in the official documentation you don´t get the actual intensity value directly but a scalar.
Try this:
Scalar intensity = im.at<uchar>(0, 0);
cout << intensity.val[0] << endl;
and for images with more than one channel you can use:
Vec3b intensity = im.at<Vec3b>(0, 0);
cout << intensity.val[0] << intensity.val[1] << intensity.val[2] << endl;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.