how to set hue value of some pixel with opencv

2019-07-18 12:02发布

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

标签: opencv hsv
2条回答
叼着烟拽天下
2楼-- · 2019-07-18 12:27

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°).

查看更多
神经病院院长
3楼-- · 2019-07-18 12:38

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.

查看更多
登录 后发表回答