在OpenCV中获取像素值

我是OpenCV的新手,我试图从灰度图像中获取像素值。

#include<opencv2opencv.hpp>
#include<opencv2highguihighgui.hpp>
#include<opencv2corecore.hpp>
#include<iostream>

using namespace cv;

int main()
{
    VideoCapture cap(1);
    Mat image,gray_image;
    cap>>image;
    cvtColor(image,gray_image,CV_BGR2GRAY);
    std::cout<<"Value: "<<gray_image.at<uchar>(0,0);
    imshow("Window",gray_image);
    waitKey(0);
    return 0;
}

像素值显示为*或〜等。我认为它正在转换为ASCII值。 我如何解决这个问题?

谢谢。


尝试输出为整数

std::cout<<"Value: "<<static_cast<int>(gray_image.at<uchar>(0,0));

打印前,您需要将您的uchar变量转换为int

喜欢,

std::cout<<"Value: "<<(int)src.at<uchar>(0,0);
链接地址: http://www.djcxy.com/p/89787.html

上一篇: Getting pixel value in OpenCV

下一篇: Different Pixel Values in MATLAB and C++ with OpenCV