OpenCV:分割HSV图像并通过H通道扫描



当我想通过 H 通道扫描并在分割 HSV 图像后打印其像素值时遇到问题。问题是输出不是数字,而是凌乱的代码。

以下是我的代码(使用Opencv):

Mat hsv;
cvtColor(saveImage,hsv,CV_BGR2HSV);// convert BRG to HSV
vector<cv::Mat> v_channel;
split(hsv,v_channel);          //split into three channels
if (v_channel[0].data==0)      //channel[0] is Hue
{
    cout<<"Error getting the Hue***********"<<endl;
}
for (int i=0;i<hue.rows;i++)     //scan through Hue 
{
    for (int j=0;j<hue.cols;j++)
    {
        cout<<v_channel[0].at<uchar>(i,j)<<endl;
    }
}

希望有人能帮忙.非常感谢!

数据存储为字节,即字符,输出是将字符解释为字符并尝试打印符号。简单地告诉它是整数

cout<< (int) v_channel[0].at<uchar>(i,j)<<endl;

最新更新