简体   繁体   English

OpenCV Mat方法“ at”在Linux中返回奇怪字符

[英]OpenCV Mat method “at” returning strange character in Linux

I am looking for a way to acces the value of the grayscale pixel in a cv::Mat object, I was able to find a lot of answers and I'm sure they worked, but for me they just don't do. 我正在寻找一种方法来对cv :: Mat对象中的灰度像素值进行访问,我能够找到很多答案,并且我敢肯定它们是有效的,但是对我来说它们是行不通的。 So basically what I have is the following: 所以基本上我有以下内容:

    gray_image = imread("myimage.png", CV_LOAD_IMAGE_GRAYSCALE);

    equalizeHist(gray_image, eq_image);

    // This line prints garbage
    const unsigned char* row = eq_image.ptr<unsigned char>(10);
    cout << row[10] << endl;

    // This line also prints garbage
    cout << eq_image.at<uchar>(10, 10) << endl;

I just want to see the grayscale[0,255] value of the pixel, in position (10,10). 我只想在位置(10,10)中查看像素的grayscale [0,255]值。 I'm pretty sure those 2 lines worked for some other people, but not for me, maybe it's a Linux thing. 我很确定那两条线对其他人有用,但是对我来说不是,也许这是Linux的事情。

How can I read the cv::Mat pixel in a grayscale integer ? 如何读取灰度整数中的cv :: Mat像素?

Thank you, 谢谢,

The value is printed as an ASCII character, that is depending on the actual value possibly non-printable garbage. 该值被打印为ASCII字符,这取决于实际值(可能是不可打印的垃圾)。 If you are interested to print the pixel value as an integer number instead, you need to cast the value to an int to get the other operator<< overload : 如果您有兴趣将像素值打印为整数,则需要将该值强制转换为int以获得另一个运算符<<重载

cout << static_cast<int>(row[10]) << endl;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM