renandame
renandame

Reputation: 25

HSV conversion with cvCvtColor() issue

I'm trying convert RGB image to HSV with the function cvCvtColor(), but the results are unexpected. For example, white are converted to something near to red.

        cvCvtColor(img, hsv, CV_BGR2HSV);
        cvSplit( hsv, h, s, v, NULL );
        cvInRangeS(h,cvScalar(0,0,0,0),cvScalar(20,0,0,0),imgthresh);  
        cvShowImage("image", img);
        cvShowImage("hsv", hsv);
        cvShowImage("threshold", imgthresh);

Is the image converted correctly and only displayed wrong? And about the threshold, the better way to do this is using the 3 channels or only the hue? I want track red objects. Sorry about the english. Thanks.

Upvotes: 0

Views: 1279

Answers (1)

Ian Medeiros
Ian Medeiros

Reputation: 1776

cvShowImage will always expect RGB values (Or BGR, I am not sure). So, when you convert to HSV, it's expected that the color are shown different. Using this rgb to hsv conversor, you can see that white - in RGB represented as (255,255,255) - is converted to (0,0,100%) in HSV. As you are saying that the displayed color of white is red, I suspect that cvShowImage is really expecting BGR by default.

Upvotes: 3

Related Questions