aihot  2017-05-02 16:16:53  OpenCV |   查看评论   
double>(box.y,box.x+box.width);  
  •   double tlsq = sqsum.at<double>(box.y,box.x);  
  •     
  •   double mean = (brs+tls-trs-bls)/((double)box.area());  
  •   double sqmean = (brsq+tlsq-trsq-blsq)/((double)box.area());  
  •   //方差=E(X^2)-(EX)^2   EX表示均值  
  •   return sqmean-mean*mean;  
  • }  
  •   
  • void TLD::processFrame(const cv::Mat& img1,const cv::Mat& img2,vector<Point2f>& points1,vector<Point2f>& points2,BoundingBox& bbnext, bool& lastboxfound, bool tl, FILE* bb_file){  
  •   vector<BoundingBox> cbb;  
  •   vector<float> cconf;  
  •   int confident_detections=0;  
  •   int didx; //detection index  
  •     
  •   ///Track  跟踪模块  
  •   if(lastboxfound && tl){   //tl: 训练和学习
  •       //跟踪  
  •       track(img1, img2, points1, points2);  
  •   }  
  •   else{  
  •       tracked = false;  
  •   }  
  •     
  •   ///Detect   检测模块  
  •   detect(img2);  
  •     
  •   ///Integration   综合模块  
  •   //TLD只跟踪单目标,所以综合模块综合跟踪器跟踪到的单个目标和检测器检测到的多个目标,然后只输出保守相似度最大的一个目标  
  •   if (tracked){  
  •       bbnext=tbb;  
  •       lastconf=tconf;   //表示相关相似度的阈值  
  •       lastvalid=tvalid;  //表示保守相似度的阈值  
  •       printf("Tracked\n");  
  •       if(detected){                                               //   if Detected  
  •           //通过 重叠度 对检测器检测到的目标bounding box进行聚类,每个类其重叠度小于0.5  
  •           clusterConf(dbb, dconf, cbb, cconf);                       //   cluster detections  
  •           printf("Found %d clusters\n",(int)cbb.size());  
  •           for (int i=0;i<cbb.size();i++){  
  •               //找到与跟踪器跟踪到的box距离比较远的类(检测器检测到的box),而且它的相关相似度比跟踪器的要大  
  •               if (bbOverlap(tbb, cbb[i])<0.5 && cconf[i]>tconf){  //  Get index of a clusters that is far from tracker and are more confident than the tracker  
  •                   confident_detections++;  //记录满足上述条件,也就是可信度比较高的目标box的个数  
  •                   didx=i; //detection index  
  •               }  
  •           }  
  •           //如果只有一个满足上述条件的box,那么就用这个目标box来重新初始化跟踪器(也就是用检测器的结果去纠正跟踪器)  
  •           if (confident_detections==1){                                //if there is ONE such a cluster, re-initialize the tracker  
  •               printf("Found a better match..reinitializing tracking\n");  
  •               bbnext=cbb[didx];  
  •               lastconf=cconf[didx];  
  •               lastvalid=false;  
  •           }  
  •           else {  
  •               printf("%d confident cluster was found\n", confident_detections);  
  •               int cx=0,cy=0,cw=0,ch=0;  
  •               int close_detections=0;  
  •               for (int i=0;i<dbb.size();i++){  
  •                   //找到检测器检测到的box与跟踪器预测到的box距离很近(重叠度大于0.7)的box,对其坐标和大小进行累加  
  •                   if(bbOverlap(tbb,dbb[i])>0.7){                     // Get mean of close detections  
  •                       cx += dbb[i].x;  
  •                       cy +=dbb[i].y;  
  •                       cw += dbb[i].width;  
  •                       ch += dbb[i].height;  
  •                       close_detections++;   //记录最近邻box的个数  
  •                       printf("weighted detection: %d %d %d %d\n",dbb[i].x,dbb[i].y,dbb[i].width,dbb[i].height);  
  •                   }  
  •               }  
  •               if (close_detections>0){  
  •                   //对与跟踪器预测到的box距离很近的box 和 跟踪器本身预测到的box 进行坐标与大小的平均作为最终的  
  •                   //目标bounding box,但是跟踪器的权值较大  
  •                   bbnext.x = cvRound((float)(10*tbb.x+cx)/(float)(10+close_detections));   // weighted average trackers trajectory with the close detections  
  •                   bbnext.y = cvRound((float)(10*tbb.y+cy)/(float)(10+close_detections));  
  •                   bbnext.width = cvRound((float)(10*tbb.width+cw)/(float)(10+close_detections));  
  •                   bbnext.height =  cvRound((float)(10*tbb.height+ch)/(float)(10+close_detections));  
  •                   printf("Tracker bb: %d %d %d %d\n",tbb.x,tbb.y,tbb.width,tbb.height);  
  •                   printf("Average bb: %d %d %d %d\n",bbnext.x,bbnext.y,bbnext.width,bbnext.height);  
  •                   printf("Weighting %d close detection(s) with tracker..\n",close_detections);  
  •               }  
  •               
  •  

    除特别注明外,本站所有文章均为 赢咖4注册 原创,转载请注明出处来自TLD(Tracking-Learning-Detection)学习与源码理解之(六)下

    留言与评论(共有 0 条评论)
       
    验证码:
    [lianlun]1[/lianlun]