Black object detection HSV range in opencv
For black and white colors in the HSV range, you should set the hue to the maximum range (0 to 180) and the saturation to the maximum range (0 to 255). You can play with a value such as 0 to 30 or 40 for black and 200 to 255 for white.
// for black
cvInRangeS(imgHSV, cvScalar(0, 0, 0, 0), cvScalar(180, 255, 30, 0), imgThreshold);
// for white
cvInRangeS(imgHSV, cvScalar(0, 0, 200, 0), cvScalar(180, 255, 255, 0), imgThreshold);
Or you can use the C ++ interface:
// for black
cv::inRange(imgHSV, cv::Scalar(0, 0, 0, 0), cv::Scalar(180, 255, 30, 0), imgThreshold);
// for white
cv::inRange(imgHSV, cv::Scalar(0, 0, 200, 0), cv::Scalar(180, 255, 255, 0), imgThreshold);
source to share
Black in HSV and HSL color space is detected with a low value (or Lightness in HSL ).
White is found in HSL with a high value. HSV white is detected with high brightness and low saturation.
for white
cv::inRange(imgHSL, cv::Scalar(0, 0, 200, 0), cv::Scalar(180, 255, 255, 0), imgThreshold);
or
cv::inRange(imgHSV, cv::Scalar(0, 0, 200, 0), cv::Scalar(180, 20, 255, 0), imgThreshold);
source to share
Hue is similar to the wavelength of dominant light that your eye receives. But the wavelength of black light is outside the visible light wavelength range. The hue does not directly account for black light.
The value is the brightness / darkness value. Any shade can be considered black in low light.
Saturation is also referred to as "chroma". It displays the intensity level of a signal of any shade. If S = 0, any shade appears "black" in color. Conversely, if you want to segment true blacks (and not the "black" caused by "darkness") from images, set a small saturation threshold always first. Then combine them with the Hue and Value masks as the additional mask will give you a more accurate answer.
source to share