[英]Visualization pixel with Opencv Mat at
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;
因为它显示符号,所以像cout << char(123) << endl;
You have to use int cast: 您必须使用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;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.