1.拼写错误
2.如果c/c++,是否丢掉分号
3.条件边界错误
找错时候,其它都找了,就尝试,如果出现条件边界时候的情况,程序会不会出问题,例子(如果asignment2[i])==-1,并且 tracks_undet[i]->skipped_frames ++到等于maximum_allowed_skipped_frames,然后下一个条件Cost2.size()>0 && Cost2[i + assignment2[i] * tracks_undet.size()] < dist_thres满足,就会出错):
for (size_t i = 0; i < assignment2.size(); i++) {
if (assignment2[i] == -1 && tracks_undet[i]->skipped_frames < maximum_allowed_skipped_frames)
{
tracks_undet[i]->skipped_frames ++;
tracks_undet[i]->Update(Point_t(), cv::Rect(), -1., false, max_trace_length);
tracks_undet2.push_back(tracks_undet[i]);
}
else
{
if (Cost2.size()>0 && Cost2[i + assignment2[i] * tracks_undet.size()] < dist_thres)
{
tracks_undet[i]->skipped_frames = 0;
tracks_undet[i]->Update(detections_low[assignment2[i]], rects_low[assignment2[i]], probs_low[assignment2[i]], true, max_trace_length);
tracks_det2.push_back(tracks_undet[i]);
}
else if(tracks_undet[i]->skipped_frames < maximum_allowed_skipped_frames)
{
assignment2[i] = -1;
tracks_undet[i]->skipped_frames ++;
tracks_undet[i]->Update(Point_t(), cv::Rect(), -1., false, max_trace_length);
tracks_undet2.push_back(tracks_undet[i]);
}
解决办法,把不满足条件的去掉,类似于函数首先做参数合法检查。
for 下面加一句:
if (tracks_undet[i]->skipped_frames >= maximum_allowed_skipped_frames){ // delete to many frames not find obj
continue;
}