示例#1
0
const Img8u &thresh(const Img8u &input, icl8u t){
  static Img8u result;
  result.setChannels(1);
  result.setSize(input.getSize());
  
  int t3 = 3*t;
  for(int x=0;x<input.getWidth();++x){
    for(int y=0;y<input.getHeight();++y){
      result(x,y,0) = 255*((input(x,y,0)+input(x,y,1)+input(x,y,2))>t3);
    }
  }
  return result;
}
示例#2
0
文件: crop.cpp 项目: ethz-asl/iclcv
void run(){
  bool c_arg = pa("-c");
  
  static FPSLimiter fpsLimit(30);
  fpsLimit.wait();

  const ImgBase *image = grabber.grab();
  DrawHandle draw = gui["draw"];
  ImageHandle cropped = gui["cropped"];

  draw = image;

  static RotateOp rot;
  if(c_arg){
    rot.setAngle(0);
  }else{
    rot.setAngle(parse<int>(gui["rot"]));
  }

  const ImgBase *cro = 0;
  if(c_arg || gui["rect"].as<bool>()){
    static Img8u roi;
    std::vector<utils::Rect> rs = mouse_2->getRects();
    ICLASSERT_THROW(rs.size() == 1, ICLException("expected exactly one rectangle"));
    lastRect = rs[0];
    mouse_2->visualize(**draw);
    SmartPtr<const ImgBase> tmp = image->shallowCopy(rs[0] & image->getImageRect());
    roi.setChannels(tmp->getChannels());
    roi.setFormat(tmp->getFormat());
    roi.setSize(tmp->getROISize());
    tmp->convertROI(&roi);
    cro = rot.apply(&roi);

    draw->color(0,255,0,255);
    draw->text(str(rs[0]), rs[0].x, rs[0].y);

  }else{
    draw->draw(mouse_1->vis());
    Size32f s(gui["s1"],gui["s2"]);
    Point32f ps[4] = { mouse_1->ps[0],  mouse_1->ps[1],  mouse_1->ps[2],  mouse_1->ps[3] };
    switch(image->getDepth()){
#define ICL_INSTANTIATE_DEPTH(D)                                \
      case depth##D:{                                           \
        static ImageRectification<icl##D> ir;                   \
        try{                                                    \
          cro = rot.apply(&ir.apply(ps,*image->as##D(),s));     \
        }catch(...){}                                           \
        break;                                                  \
      }
      ICL_INSTANTIATE_ALL_DEPTHS;
#undef ICL_INSTANTIATE_DEPTH
    }
  }
  if(cro){
    cropped = cro;
    currMutex.lock();
    cro->convert(&curr);
    currMutex.unlock();
  }

  gui["draw"].render();
  gui["fps"].render();
}