As Mikka suggested, you have your own algorithm to distinguish tracked_object from new_detection. The simplest solution is to compare the distance between the centroids.
Other applications include
- Correlation of overlapping cells with codes
- Hungarian algorithm
(I provided links to code and articles at the end.)
BoundingBoxOverlapRatio Method:
Steps
- Frame_1: Define blobs -> Draw boundingRectangles for each blob
bbox_frame1_obj1 , bbox_frame1_obj2 ... Frame_2: Identify blobs -> Draw boundingRectangles bbox_frame2_obj1
-> compare the overlap of bbox_frame2_obj1 with bbox_frame1_obj1 , bbox_frame1_obj2 , etc.
The number of overlaps indicates the likelihood of being the same object, depending on which positions of the object can be updated.
But this method is suitable for scenarios that include slow moving objects, such as pedestrian detection, or possibly not overlapping at all.
Hungarian algorithm
This algorithm from 5 to 6 steps serves as a simple but reliable solution for this kind of assignment tasks.
It works as shown below.
Create a matrix with rows as prev_position objects and columns as new_detections
If we have 3 objects in memory and the new frame has 4 drops, this leads to a 3x4 matrix with each element being the distance between the objects and the detections.
Element (1,1) → the distance between the centroid obj_1 and the detected detection_1
Element (1,2) → the distance between the centroid obj_1 and the detected detection_2 ...
Example matrix (units in pixels):
5 15 30 20 20 30 3 40 12 4 15 50
The situation here is simple and straightforward, which leads to the conclusion
obj_1 -> detection_1 (5px between obj_1 and detection_1) obj_2 -> detection_3 (3px between obj_2 and detection_3) obj_3 -> detection_2 (4px between obj_3 and detection_2)
Thus, detect_4 must be a new object, and a new track and identifier must be assigned.
After that, obj_4 should be tracked together, and the next matrix has 4 rows ...
But with more objects, the task gets more lumps. And the Hungarian algorithm helps solve more complex and huge matrices for optimal assignment of detections to objects.
Below are some useful resources for tracking multiple objects and the Hungarian algorithm.