0

I meet a problem when I want to scan through H channel and print its pixel values after splitting a HSV image.The problem is that the outputs are not numbers but messy codes.

Following is my code(using 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;
    }
}

Hope anyone could help . Thanks very much!

Menghuadong
  • 35
  • 1
  • 5

1 Answers1

4

The data is stored as bytes, ie chars, the output is interpreting the chars as, well, chars and trying to print the symbol. Simply tell it they are integers

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

Martin Beckett
  • 94,801
  • 28
  • 188
  • 263