问题
cvInRangeS(imgHSV, cvScalar(15, 234, 120), cvScalar(21, 234, 120), imgThreshed);
I am wondering what each parameter in the cvScalar function represents. I thought it would be HSV but it doesnt seem to be thresholding the desired color. Could someone explain the parameters a bit clearer?
回答1:
It means
H - Hue, S - Saturation, V - Value
take a look in here for understanding each one of those:
http://en.wikipedia.org/wiki/HSL_and_HSV
the color is mainly defined in the Hue component. There is a good tutorial about thresholding in HSV space in here:
http://aishack.in/tutorials/thresholding/
回答2:
cvInrangeS
function checks that array elements lie between two scalars.
First cvScalar value denotes inclusive lower boundary. Second cvScalar value denotes exclusive upper boundary.
cvInrangeS doesn't care the values you give as either RGB or BGR or HSV etc. It just goes through the array elements you give as input (first parameter)(here it is an image) and checks if elements are in the given range you specified. If so, it is selected, otherwise rejected. And feed result to last parameter, your output image.
Check out its documentation
Now here if you give a HSV image. So cvScalar denotes lowest and highest color of range you want to extract.
If it is RGB image, you specify min and max RGB colors.
And better use HSV because it provides good result. Read here.
And now if you want to convert RGB to HSV values, Try here and here.
(Remember, in OpenCV red and blue interchanged. It is BGR, not RGB).
来源:https://stackoverflow.com/questions/9073124/hsv-colour-space-and-cvinranges-function