views:

373

answers:

1

When I run this following code on a sample image ie an rgb image; and then execute it to display the converted hsv image, both appear to be different... can anyone explain why? or can you suggest a solution for this not to happen... coz its the same image afterall

Mat img_hsv,img_rgb,red_blob,blue_blob;
img_rgb = imread("pic.png",1);
cvtColor(img_rgb,img_hsv,CV_RGB2HSV);
namedWindow("win1", CV_WINDOW_AUTOSIZE);
imshow("win1", img_hsv);
+2  A: 
  1. I don't know the new (2.x) OpenCV good enough yet, but usually images loaded in OpenCV are in CV_BGR channel order and not RGB, therefore you most likely want CV_BGR2HSV

  2. OpenCV does not actually "know" HSV, it will just encode Hue in first channel, Saturation in second and Value in third. If you display and image in OpenCV, highgui assumes it's a BGR image, thus interpreting the first channel (now Hue) as Blue etc.

zerm
Its so rare to see an OpenCV question on SO, let along an answer.
JustSmith
even i tried that dude ... din work either... just a bit of minor change in the output image... well doesn't it use the following formulae to convert the images given in http://opencv.willowgarage.com/documentation/cpp/miscellaneous_image_transformations.html
Kaushal
@kaushalyjain: yes, but as i've said: Hue ends in first channel, S in 2nd, V in 3rd. imshow does not interpret the colorspace, it assumes BGR (at least that was the case with pre-2.x cvShowImage). What you see is HSV encoded as BGR ;)
zerm
oh! got it ... thanks a lot!! i have another question based on this... i'll be posting it as a new question.. please take pains to answer that as well... !! :)
Kaushal