问题描述
这个问题困扰了我很长时间.基本车辆计数程序包括:1.识别车辆. 2.按功能跟踪车辆.
This question bothers me for a long time. The basic vehicle counting program includes: 1. recognize a vehicle. 2. track the vehicle by features.
但是,如果在时间t找到了#1车辆,则在t + 1时程序开始跟踪车辆,但是也可以通过识别过程找到#1,然后t + 2程序将跟踪两辆车辆,但实际上只是框架中的#1.被识别的车辆如何避免重复检测?
However, if the vehicle #1 was found at time t, then at t+1 the program start to track the vehicle, but #1 can also be found by recognizing process, then t+2 program two vehicles will be tracked, but actually just one #1 in the frame. How can the recognized vehicle avoiding duplicate detect?
提前谢谢!
推荐答案
如果我理解正确,则您担心要检测到已经在跟踪的对象(检测器/跟踪器通信不足).在这种情况下,您可以:
If I understood correctly, you are concerned about detecting the object that you are already tracking (lack of detector/tracker communication). In that case you can either:
- 预检查-在检测期间排除您已经跟踪物体的区域或
- 后检查-丢弃靠近跟踪对象的检测到的对象(如果由于某种原因由于您的方法无法进行选择性"检测)
- Pre-check - during detection exclude the areas, where you already track objects or
- Post-check - discard detected objects, that are near tracked ones (if "selective" detection is not possible for your approach for some reason)
有几种可能的实现方式.
There are several possible implementations.
-
面具.创建一个二进制蒙版,在该处对被跟踪对象"附近的区域进行标记"(例如,在被跟踪对象附近的区域以及在其他任何地方为零).有了这样的遮罩,在特定位置进行检测之前,如果您坚持使用后检查方法.
Mask. Create a binary mask, where areas near tracked objects are "marked" (e.g. ones near tracked objects and zeros everywhere else). Given such a mask, before detection in particular location you can quickly check if something is being tracked there, and abort detection (Pre-check approach) or remove detected object, if you stick with the Post-check approach.
蛮力.计算特定位置与每个被跟踪位置之间的距离(您也可以检查重叠区域和其他特征).然后,您可以丢弃与已经跟踪的对象过于接近和/或相似的检测.
Brute-force. Calculate distances between particular location and each of the tracked ones (you can also check overlapping area and other characteristics). You can then discard detections, that are too close and/or similar to already tracked objects.
让我们考虑哪种方法更好(何时).
Lets consider which way is better (and when).
-
蒙版需要O( N )个操作才能将所有跟踪的对象添加到蒙版中,还需要O( M )个操作来进行检查所有感兴趣的地点.那是O( N + M )= O(max( N , M )),其中 N 是被跟踪对象的数量, M 是已检查位置的数量(例如,检测到的对象).哪个数字更大( N 或 M )取决于您的应用程序.还需要额外的内存来保存二进制掩码(通常这不是很重要,但又取决于应用程序).
Mask needs O(N) operations to add all tracked objects to the mask and O(M) operations to check all locations of interest. That's O(N + M) = O(max(N, M)), where N is number of tracked objects and M is number of checked locations (detected objects, for example). Which number (N or M) will be bigger depends on your application. Additional memory is also needed to hold the binary mask (usually it is not very important, but again, it depends on the application).
蛮力需要O( N * M )次操作(每个 M 个位置已针对 N 个候选人进行了检查).它不需要额外的内存,并且允许在检查过程中执行更复杂的逻辑.例如,如果某个对象在一帧内突然改变大小/颜色/任何内容-我们可能不应该对其进行跟踪(因为它可能是一个与原始对象完全不同的对象),而是执行其他操作.
Brute-force needs O(N * M) operations (each of M locations is checked against N candidates). It doesn't need additional memory, and allows doing more complex logic during checks. For example, if object suddenly changes size/color/whatever within one frame - we should probably not track it (since it may be a completely different object occluding original one) and do something else instead.
总结:
- 当您有很多对象时,
- 遮罩渐近地表现更好.如果在检测期间执行类似滑动窗口的搜索操作,并且可以排除某些区域(因为在这种情况下,您可能会有很大的 M ),这几乎是必不可少的.您可能会通过预检查使用它. 当对象很少且需要进行涉及不同属性的检查时,
- 蛮力是可以的.与事后检查一起使用是最有意义的.
- Mask is asymptotically better when you have a lot of objects. It is almost essential if you do something like a sliding window search during detection, and can exclude some areas (since in this case you will likely have a large M). You will likely use it with Pre-check.
- Brute-force is OK when you have few objects and need to do checks that involve different properties. It makes most sense to use it with Post-check.
如果您碰巧之间需要一些东西-您将必须更有创造力,或者以某种方式在对象蒙版中编码对象属性(以实现恒定的查找时间),或者使用更复杂的数据结构(以加快蛮力" 搜索).
If you happen to need something inbetween - you'll have to be more creative and either encode object properties in mask somehow (to achieve constant look-up time) or use more complex data structures (to speed up "Brute-force" search).
这篇关于使用opencv跟踪车辆轨迹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!