C++ opencv中的黑色物体检测HSV范围

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25398188/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-28 11:18:32  来源:igfitidea点击:

Black color object detection HSV range in opencv

c++opencvhsv

提问by sushma ahirwar

What is the range of Black color object detection?

黑色物体检测的范围是多少?

i tried following code

我试过下面的代码

cvInRangeS(imgHSV, cvScalar(0, 0, 0, 0), cvScalar(0, 255, 255, 0), imgThreshold);

but its not working.

但它不工作。

回答by elvis.dukaj

For black and white colors in HSV range you have to set hue at maximum range (0 to 180), and saturation at maximum range (0 to 255). You can play with the value, for example, 0 to 30 or 40 for black, and 200 to 255 for white.

对于 HSV 范围内的黑白颜色,您必须将色调设置为最大范围(0 到 180),并将饱和度设置为最大范围(0 到 255)。您可以使用该值,例如,黑色为 0 到 30 或 40,白色为 200 到 255。

// 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:

或者您可以使用 C++ 接口:

// 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);

回答by robbycandra

Black colour in HSVand HSLcolour space, is detected with low Value (or Lightness in HSL).

HSVHSL颜色空间中的黑色被检测为低值(或HSL 中的亮度)。

White colour in HSLdetected with high Value. White colour is HSVdetected with high Lightness and Low Saturation.

HSL 中的白色检测到高值。白色是检测到具有高亮度和低饱和度的HSV

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);

回答by SonamYeshe

Hue is like the dominant light wavelength your eye receives. But black light wavelength is beyond visible light wavelength range. The hue doesn't count black light directly.

色调就像你的眼睛接收到的主光波长。但是黑光波长超出了可见光波长范围。色调不直接计算黑光。

Value is the lightness/darkness value. Any hue can be regarded as black in a bad lighting condition.

值是明度/暗度值。在恶劣的照明条件下,任何色调都可以被视为黑色。

Saturation is also referred to as "chroma". It depicts the signal intensity level of any hue. If S=0, any hue looks like "black" in color. On the contrary, if you want to segment true black color (rather than the "black" triggered by "darkness") from images, set a small saturation threshold is always the first job. Then combine with Hue and Value masks as the secondary mask will give you a more accurate answer.

饱和度也称为“色度”。它描绘了任何色调的信号强度水平。如果 S=0,任何色调看起来都像“黑色”。相反,如果您想从图像中分割出真正的黑色(而不是由“黑暗”触发的“黑色”),设置一个小的饱和度阈值始终是首要任务。然后结合 Hue 和 Value 蒙版作为辅助蒙版将为您提供更准确的答案。