OpenCV的Android的绿色检测 [英] OpenCV Android Green Color Detection
问题描述
目前我在做一个应用程序,其中用户会发现绿色。我用这张照片来进行测试:
currently I'm making an app where user will detect green colors. I use this photo for testing:
我的问题是,我无法检测到任何绿色像素。之前,我曾与蓝色,一切运行良好。现在,我无法检测到任何东西,虽然我试图 RGB
的不同组合。我想知道它是否是问题,绿色或我的检测范围,所以我用涂料制成的图像(0,255,0)
和它的工作。为什么看不到这个圈子呢?我用这个code检测:
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);
这可能是我设置错了范围,但我用Photoshop来获得绿色像素的一种颜色并转换它的 RGB
价值为 HSV
。然而,这是行不通的。它并没有发现我已经采样偶数像素。怎么了?先谢谢了。
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.
使用三木的回答是:
推荐答案
绿颜色是HSV空间的H = 120,它是在区间[0,360]。
Green color is HSV space has H = 120 and it's in range [0, 360].
的OpenCV半部为H值,以适应范围[0,255],所以H值为代替范围[0,360]为,是在范围[0,180]。 S和V仍然在范围[0,255]。
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].
作为结果中,H为绿色的值是60 = 120/2
As a consequence, the value of H for green is 60 = 120 / 2.
您上限和下限应该是:
// sensitivity is a int, typically set to 15 - 20
[60 - sensitivity, 100, 100]
[60 + sensitivity, 255, 255]
更新
由于你的形象是相当黑暗的,你需要使用一个下界为V.有了这些值:
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:
您可以参考这个答案了解详情。
这篇关于OpenCV的Android的绿色检测的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!