0

当我想通过 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;
    }
}

希望任何人都可以提供帮助。非常感谢!

4

1 回答 1

4

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

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

于 2012-12-05T13:37:36.150 回答