以下是您需要问自己的几个问题。您的问题表明您需要一个相当简单的跟踪算法。你看过哪些方法?opencv 库是入门的好地方。您是否尝试过阅读教程(即http://opencv-srf.blogspot.ro/2010/09/object-detection-using-color-seperation.html)这些将成为您构建越来越复杂的垫脚石算法。
- 您是否需要处理遮挡(当一个对象出现在另一个对象前面时?
- 你的背景有多么简单——它有没有改变。如果它不改变,事情会变得容易得多。
- 物体可以自发出现在图像帧的中间还是必须从侧面出现
- 物体在框架中移动时颜色会发生变化吗?
- 这是 2D 还是 3D 跟踪问题?
一般来说,跟踪问题通常根据上述和许多其他问题的答案分为两部分:
- 物体检测(当前帧)
- 对象关联(来自上一帧)
在这里做出最简单的假设是伪代码实现。请注意,还有许多其他方法可以做到这一点。密集特征跟踪、稀疏特征、基于直方图、运动
#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