Esempio n. 1
0
   void TemplateTracker::setTemplateImage(const Img8u &templateImage, 
                                          float rotationStepSizeDegree){
     
     
     Img8u test = templateImage;
     test.scale(test.getSize()*4);
 
     RotateOp rot;    
     ICLASSERT_RETURN(rotationStepSizeDegree > 0.001);
 
     const int w = templateImage.getWidth();
     const int h = templateImage.getHeight();
     data->lut.clear();
     
     for(float a=0;a<=360;a+=rotationStepSizeDegree){
       rot.setAngle(a);
       const Img8u *r = rot.apply(&templateImage)->as8u();
       const int rw = r->getWidth();
       const int rh = r->getHeight();
       Rect center((rw-w)/2, (rh-h)/2, w,h);
       SmartPtr<const Img8u> roiimage = r->shallowCopy(center);
       
       Img8u *tmp = new Img8u(test.getSize()/4,1);
       //      data->lut.push_back(roiimage->deepCopyROI());
       roiimage->scaledCopyROI(tmp,interpolateLIN);
       data->lut.push_back(tmp);
     }    
   }
Esempio n. 2
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;
   }
Esempio n. 3
0
int main(int n, char **a){
  pa_explain("-o","output filename (should be some format, that supports alpha channel such as png)\n"
             "or, if no output is given, the image is just show");
  pa_init(n,a,"-icon-name|-i(iconname=empty) -output|-o(2) -image-file-to-c++-array|-ita(input-file-name)");
  
  if(pa("-ita")){
    Img8u image = load<icl8u>(pa("-ita"));
    const int w=image.getWidth(), h = image.getHeight(), c = image.getChannels();
    std::cout << "static icl8u data_XYZ["<<w<<"]["<<h<<"]["<<c<<"]={" << std::endl; 
    for(int y=0;y<h;++y){
      std::cout << "{";
      for(int x=0;x<w;++x){
        std::cout << "{";
        for(int i=0;i<c;++i){
          std::cout << (int)image(x,y,i) << (i<c-1?",":"}");
        }
        std::cout << (x<w-1?",":"}");
      }
      std::cout << (y<h-1?",":"};") << std::endl;
    }
    std::cout << "//#include <ICLCore/Img.h>" << std::endl;
    std::cout << "//#include <ICLCC/CCFunctions.h>" << std::endl;
    std::cout << "const Img8u& load_data_XYZ(){" << std::endl;
    std::cout << "  static SmartPtr<Img8u> image;" << std::endl;
    std::cout << "  if(!image){" << std::endl;
    std::cout << "     image = new Img8u(Size(" << w << "," << h << ")," << c << ");" << std::endl;
    std::cout << "     interleavedToPlanar((const icl8u*)data_XYZ, image.get());" << std::endl;
    std::cout << "  }" << std::endl;
    std::cout << "  return *image;" << std::endl;
    std::cout << "}" << std::endl;
  }else{
    const Img8u &image = IconFactory::create_image(pa("-i"));
    
    if(pa("-o")){
      GenericImageOutput out(pa("-o"));
      out.send(&image);
    }else{
      show(image);
    }
  }
}