问题
I need to change the hue of some pixels of my image, but i don't know how to set them!
I converted the image in HSV with CV_BGR2HSV
and now i'm cycling with a for by rows and cols...
how can I access each pixel's hue?
for setting RGB i'm using this code...
CvScalar s;
s=cvGet2D(imgRGB,i,j); // get the (i,j) pixel value
printf("B=%f, G=%f, R=%f\n",s.val[0],s.val[1],s.val[2]);
s.val[0]=240;
s.val[1]=100;
s.val[2]=100;
cvSet2D(imgRGB,i,j,s); // set the (i,j) pixel value
回答1:
You already converted your image to HSV, so the 3 layers of the image now correspond to Hue, Saturation and Value:
s.val[0]
is the hue.s.val[1]
is the saturation.s.val[2]
is the value.
So go ahead and use exactly the same method as for your RGB images to get and set the pixel values.
回答2:
Yes, openCV uses 180° i.e., (0°-179°) cylinder of HSV; while normally its (0°-240°) in MS paint and ideally (0°-360°). So, openCV gives you result of hue from (0°-179°).
来源:https://stackoverflow.com/questions/5642097/how-to-set-hue-value-of-some-pixel-with-opencv