OpenCV Android绿色检测 [英] OpenCV Android Green Color Detection
问题描述
目前我在做一个应用程序,用户将检测绿色。我使用这张照片进行测试:
我的问题是我无法检测到任何绿色像素。在我使用蓝色和一切工作正常之前。现在我不能检测到任何东西,虽然我尝试不同的组合 RGB
。我想知道它是否与绿色或我的检测范围有问题,所以我使用(0,255,0)
在画油漆图像,它的工作。为什么看不到此圈子?我使用这个代码进行检测:
Core.inRange(hsv_image,new Scalar([I change this value]),new Scalar (60,255,255),ultimate_blue);
这可能是我设置了错误的Range,但我使用Photoshop获得绿色像素并将 RGB
的值转换为 HSV
。但它不工作。它甚至不检测我已经采样的像素。怎么了?提前感谢。
使用Miki的回答:
绿色是HSV空间的H = 120,范围为[0,360]。
OpenCV将H值减半以适应范围[0,255],因此H值而不是范围[0,360]在范围[0,180]内。
S和V仍在[0,255]范围内。
因此,绿色的H值为60 = 120 / / p>
您的上限和下限应为:
a int,通常设置为15 - 20
[60 - sensitivity,100,100]
[60 + sensitivity,255,255]
UPDATE
图像非常暗,您需要为V使用下限。使用这些值:
sensitivity = 15;
[60 - sensitivity,100,50] //下界
[60 + sensitivity,255,255] //上界
生成的掩码将是:
有关详情,请参阅此答案。
currently I'm making an app where user will detect green colors. I use this photo for testing:
My problem is that I can not detect any green pixel. Before I worked with blue color and everything worked fine. Now I can't detect anything though I tried different combinations of RGB
. I wanted to know whether it's problem with green or my detection range, so I made an image in paint using (0, 255, 0)
and it worked. Why it can't see this circle then? I use this code for detection:
Core.inRange(hsv_image, new Scalar([I change this value]), new Scalar(60, 255, 255), ultimate_blue);
It could have been that I set wrong Range, but I use Photoshop to get color of one of green pixels and convert RGB
value of it into HSV
. Yet it doesn't work. It don't detect even pixel that I've sampled. What's wrong? Thanks in advance.
Using Miki's answer:
Green color is HSV space has H = 120 and it's in range [0, 360].
OpenCV halves the H values to fit the range [0,255], so H value instead of being in range [0, 360], is in range [0, 180]. S and V are still in range [0, 255].
As a consequence, the value of H for green is 60 = 120 / 2.
You upper and lower bound should be:
// sensitivity is a int, typically set to 15 - 20
[60 - sensitivity, 100, 100]
[60 + sensitivity, 255, 255]
UPDATE
Since your image is quite dark, you need to use a lower bound for V. With these values:
sensitivity = 15;
[60 - sensitivity, 100, 50] // lower bound
[60 + sensitivity, 255, 255] // upper bound
the resulting mask would be like:
You can refer to this answer for the details.
这篇关于OpenCV Android绿色检测的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!