Esempio n. 1
0
   TemplateTracker::Result TemplateTracker::track(const Img8u &image, 
                                                  const Result *initialResult,
                                                  std::vector<Result> *allResults){
     Result last = initialResult ? *initialResult : data->lastResult;
     if(last.pos == Point32f(-1,-1)){
       last.pos = Point(image.getWidth()/2,image.getHeight()/2); 
     }
     
     const double angle = last.angle;
     const int X = last.pos.x;
     const int Y = last.pos.y;
     const int lutSize = (int)data->lut.size();
     const int angleIndex = angle / (2*M_PI) * (lutSize-1);
     const int ROI = getPropertyValue("tracking.position range");
     const float rotationRange = getPropertyValue("tracking.rotation range");
     const int step1 = getPropertyValue("tracking.coarse steps");
     //const int step2 = getPropertyValue("tracking.fine steps");
     //const float angleStepSize = 360./lutSize;
 
     const Rect roi(X - ROI/2, Y-ROI/2, ROI, ROI);
     
     SmartPtr<const Img8u> roiImageTmp = image.shallowCopy(roi);
     SmartPtr<Img8u> roiImage = roiImageTmp->deepCopyROI();
 
     const int stepRadius = lutSize * rotationRange/720;
 
     Result bestResult = last;
     for(int i = -stepRadius; i <= stepRadius; i+= step1){
       int curIndex = angleIndex + i;
       while(curIndex >= lutSize) curIndex -= lutSize;
       while(curIndex < 0) curIndex += lutSize;
       
       data->prox->apply(roiImage.get(),data->lut.at(curIndex).get(),&data->buf);
       
       Point maxPos;
       float maxValue = data->buf->getMax(0,&maxPos);
     
       Result curr(maxPos+last.pos,
                   (float(curIndex)/lutSize) * 2 * M_PI, 
                   maxValue,
                   data->lut.at(curIndex).get());
       if(curr.proximityValue > bestResult.proximityValue){
         bestResult = curr;
       }
       if(allResults) allResults->push_back(curr);
     }
     data->lastResult = bestResult;
     return bestResult;
   }