我是OpenCV的新手,我正试图从灰度图像中获取像素值。
#include<opencv2\opencv.hpp>
#include<opencv2\highgui\highgui.hpp>
#include<opencv2\core\core.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值。我该如何解决这个问题?
谢谢。
答案 0 :(得分:4)
尝试输出为整数
std::cout<<"Value: "<<static_cast<int>(gray_image.at<uchar>(0,0));
答案 1 :(得分:1)
您需要在打印前将uchar变量强制转换为int
等
std::cout<<"Value: "<<(int)src.at<uchar>(0,0);