问题描述
Im开发使用kinect进行图像处理的系统。系统需要基于它们的颜色(从kinect图像)检测某些对象。
Im developing a system that uses kinect for image processing. The system needs to detect certain objects based on their colors (from the kinect image).
我当前的解决方案是使用一个固定大小的窗口,整个图像。然后我计数(在窗口中)绿色的像素数,并将其与某个阈值进行比较。要检查像素是否为绿色,我使用参考颜色(0x00FF00),然后计算当前像素与参考颜色的距离。
My current solution is to use a window (of fixed size) and slide it through the whole image. I then count(in the window) the number of pixels that are green and compare it against some treshold. To check if the pixel is green i use a reference color (0x00FF00) and then calculate the distance of the current pixel to the reference color.
算法如下所示:
referenceColor = 0x00FF00;
window_width = 10;
window_height = 10;
colorSum = 0;
COLOR_TRESHOLD = 20;
WINDOW_COLOR_TRESHOLD = 70;
foreach (pixel in image)
{
colorSum = 0;
for(i = 0; i < window_width; i++)
{
for(j = 0; j < window_height; j++)
{
//get the current pixel that is processed by the window
curPixel = image.getPixelAt(i+pixel.indexX,j+pixel.indexY);
// calculate the distance
distance = sqrt((curPixel.r - referenceColor.r) ^ 2 + (curPixel.g - referenceColor.g) ^ 2 + (curPixel.b - referenceColor.b) ^ 2);
// check if distance smaller than the treshold
if(distance <= COLOR_TRESHOLD)
{
// pixel is green
colorSum++;
}
}
}
// check if there are enough green pixels in the image
if(colorSum > WINDOW_COLOR_TRESHOLD)
{
// green object detected
}
}
如果颜色是暗/明亮(由于阳光/反射),它会失败(我必须改变阈值以获得良好的检测)。理想情况下,我想归档,每个绿色像素/对象将被检测(无论它是多么明亮/黑暗)。任何知道任何好的(鲁棒)算法来归档这个?将欣赏一个点在正确的方向。
The problem with this algorithm is that if the color is to dark/bright (due to sunlight/reflections) it fails (and i have to change the tresholds to get good detection). Ideally i would like to archive that every green pixel/object will get detected (regardless of how bright/dark it is). Does any know any good (robust) algorithm to archive this? Would appreciate a point in the right direction.
感谢。
推荐答案
您可能需要使用其他颜色空间。转换为HSV,并与色调一起工作。
查看,它提供了一个例子。这是用openCV,但它不应该太难适应。
You may need to use another colour space. Convert to HSV, and work with the hue.Have a look at this article, it provides an example. This is with openCV, but it should not be too difficult to adapt.
这篇关于颜色检测算法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!