I'm trying to create simple blob tracking using OpenCV. I have detected the blobs using findcontours. I would like to give those blobs a constant ID.
I have collected a list of blobs in the previous frame and the current frame. Then I took the distance between each blob in the previous frame and the current frame. I would like to know what else is needed to track the blobs and give them an ID. I just took the distance between previous and current frame blobs, but how can I assign the blobs a consistent ID using the measured distance between the blobs?
In the first frame, you can assign id any way, 1 for the first you find, 2 for the second... or simply give them ID according to their position in the collection.
Then on next frame you will have to use best match. Find the blobs, compute all distances between current blobs and all the blobs of the previous image and assign each previous ID to the closest blob. Blobs that just enter the field will get new IDs.
Now you have two frames, you can do movement prediction for the next one. Just compute deltaX and deltaY between previous and current position of the blob. You can use this information to guess future position. Match against this future position.
This should work if you have not to many overlapping blobs, and if movement is not too fast and erratic between each frames.
It's possible to be more accurate using a scoring system trough several images:
Get positions for the first 3 or 5 images. For any blob of frame one, seek the closest on frame 2, compute the speed (deltaX deltaY), seek the closest to predicted position for frame 3, 4, 5... Sum up all distances between predicted positon and closest blob it will be the score. Do the same using the 2nd closest on frame 2 (it will seek in another direction). The lower the score the most likely its the good blob.
If you have lot of blobs, you should use a quadtree to speedup process. Compare squared distance; it will avoid lot of sqrt computations.
It's important to know how your blob tipically move to tune your algotrithm.