and then doing a tracking on a video with 30000 frames It is very likely that around 2000 frames or so in the video
a runtime error happens in the clustering loop
cvUpdateTracks which starts at Line 246 of cvtrack.cpp:
// Clustering
for (j=0; j<nTracks; j++) ....
at the point where it does
// Update track
// cout << "Matching: track=" << track->id << ", blob=" << blob->label << endl;
track->label = blob->label; //FAILS due to null pointer issue.
I managed to circumvent the issue by initializing the structures blob and track to Null:
CvTrack *track = NULL;
before these are set within the clustering subloops
and then check if these are null before updating :
if (track != NULL && blob != NULL )
{
// Update track
cout << "Matching: track=" << track->id << ", blob=" << blob->label << endl;
track->label = blob->label;
track->centroid = blob->centroid;
track->minx = blob->minx;
track->miny = blob->miny;
track->maxx = blob->maxx;
track->maxy = blob->maxy;
if (track->inactive)
track->active = 0;
track->inactive = 0;
}
But Its not clear to me why the issue arises, the original code conducts a search on line 261 to set the track struct:
for (list<CvTrack*>::const_iterator it=tt.begin(); it!=tt.end(); ++it)
{
CvTrack *t = *it;
unsigned int a = (t->maxx-t->minx)*(t->maxy-t->miny);
if (a>area)
{
area = a;
track = t;
}
}
But somehow it is assumed that this will not fail, and a t will always be set.
Initializing to null
CvTrack *track = NULL;
CvTrack *blob = NULL;
and checking if still null after the search seems to fix the issue.
Thanks,
Kostas