Ask Your Question
1

cvtColor RGB to HSV, different look???

asked 2014-03-29 08:08:39 -0600

Brixus gravatar image

Hello, I would like to convert a stream from my webcam to HSV colorspace.

Therefore I used cvtColor in the following code:

int main()
{
VideoCapture cap(0);
if(!cap.isOpened())
{
cout << "Capture could not be opened succesfully" << endl;
return -1;
}
namedWindow("RGB");
namedWindow("HSV");

while(char(waitKey(1)) != 'q' && cap.isOpened())
{
Mat frame, frame_hsv;
cap >> frame;
cvtColor(frame, frame_hsv, CV_RGB2HSV);

imshow("RGB", frame);
imshow("HSV", frame_hsv);

}
return 0;
}

First I am wondering because if I change CV_RGB2HSV to CV_BGR2HSV there is no difference in the shown images.

In the attached file you can see the output.

Why are the colors in the new "HSV-image" wrong? And what can I do to solve this?

I thougt cvtColor would calculate the matching colors for the new color space.

Thank you :-)

RGBtoHSV.PNG

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2014-05-03 20:43:56 -0600

jasedit gravatar image

OpenCV doesn't record the colorspace of an image in the image itself, so imshow has no way of knowing what colorspace you are working in. So what is most likely happening is imshow() is taking the HSV values and interpreting them as RGB/BGR, which would produce some significantly different effect. That's my guess anyways.

edit flag offensive delete link more

Comments

Thank you very much. This sounds logical :-)

Brixus gravatar imageBrixus ( 2014-07-05 08:14:01 -0600 )edit

Question Tools

Stats

Asked: 2014-03-29 08:08:39 -0600

Seen: 742 times

Last updated: May 03 '14