A simple blob tracking system

well, blob tracking is the most basic thing for many applications. opencv provides an easy to use pipeline for doing this. but it seems the demo opencv provides is too slow, especially when there are more than two blobs.
so i just hack this simple blob tracking system from NUI’s community core vision. it’s based on KNN algorithm. it’s very fast. the accuracy is also very good. you can test the attached codes for yourself. it’s written in OF0.061, VS2008 and opencv2.0
a test video is also included. this code works well with this video. but if you use a webcam instead of this test video, this application will sometimes crash… and that’s why i’m posting here. in fact i find CCV sometimes crashes for unknown reasons, especially when there are lots of blobs poping up and disappearing.
For this code, when the application crashes, the size of the vector ‘trackedBlobs’ is unbelievable large, sometimes a negtive number. while in fact, the size of the vector ‘trackedBlobs’ should not exceed 20(the one MAXNUMBER definied in config.xml). besides, the int variable IDCounter also becomes very large.
i’m not very familiar with C++'s STL things such as vector, map, etc. but i doubt the bug just hide in the assignment operation between the vectors.
because of the upload limitation, you can go to here http://files.cnblogs.com/yangyangcv/simpleBlobTrackingSystem.rarto download the codes.