图像处理 - 跟踪不同颜色的斑点

时间:2013-11-11 17:50:00

标签: c++ opencv image-processing

我正在尝试找到在普通背景上跟踪不同颜色对象的最佳方法。

我已阅读过,似乎区分颜色的最佳方法是首先将图像转换为HSV空间,然后将阈值转换为基于色调的阈值。但是,由于我不仅跟踪一个对象,而且还不知道要用哪个值来限制它,哪种方法最好找到这些对象的颜色?直方图方法是否有效,在背景占据大部分像素的情况下忽略峰值,其余峰值代表不同的颜色?

一旦找到了不同的颜色,我就可以对图像进行阈值处理,然后找到勾勒出对象的轮廓。

有没有比我建议的方法更好的跟踪blob的方法?

我也看过像cvBlob这样的库但是我在尝试安装这些库时遇到了麻烦,所以我宁愿坚持使用纯粹的OpenCV实现。

作为旁注,我正在使用C ++ OpenCV库。

1 个答案:

答案 0 :(得分:0)

以下是您需要问自己的一些问题。您的问题表明您需要一个相当简单的跟踪算法。你看过什么方法? opencv库是伟大的开始的地方。您是否尝试过阅读教程(即http://opencv-srf.blogspot.ro/2010/09/object-detection-using-color-seperation.html)这些将成为您构建越来越复杂的算法的垫脚石。

  • 您是否需要处理遮挡(当一个物体在另一个物体前面时?
  • 你的背景有多简单 - 它是否会发生变化。如果不改变事情变得容易多了。
  • 对象可以在图像框架的中间自发出现,或者对象必须来自两侧
  • 物体在框架中移动时颜色是否会发生变化?
  • 这是2D或3D跟踪问题吗?

一般来说,跟踪问题通常根据上述答案和许多其他问题分为两部分:

  1. 物体检测(当前帧)
  2. 对象关联(来自上一帧)
  3. 这里做出最简单的假设是伪代码实现。请注意,还有许多其他方法可以做到这一点。密集特征跟踪,稀疏特征,基于直方图,运动

    #object detection (relatively easy part)
    Read b = Background Image (this image needs to be read before any objects are in the scene - it can be thought of as initialization stage)
    Read c = Current Image
    diff = c - b > Threshold
    #everywhere there is a difference indicates a part of an object
    #now abstract to higher level objects based on connected components.  During occlusions you'll need to differentiate based on color, and maybe even motion if two objects are similar color
    #Object association (relatively harder part)
    For every object check if this object is already in your list (you'll need a distance metric here to check how similar this object is to another - based on histogram difference, feature points, motion etc...)
    If in list, then add this information to the object's track
    If in list, you want to consider if you need to update the object model based on the new information.  Did the object change shape/color/motion?
    If not in list add it