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?
如果我可视化图像,我会看到正确的图像。我哪里错了?
2 个解决方案
#1
3
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;
#2
2
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;
#1
3
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;
#2
2
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;