예제 #1
0
void myrun(){
  static GenericGrabber grabber(FROM_PROGARG("-input"));
  grabber.setDesiredDepth(depth8u);
  
  const Img8u &image = *grabber.grab()->asImg<icl8u>();
  
  const Img8u &tImage = thresh(image,gui.getValue<int>("t"));
  
  gui.getValue<ImageHandle>("myimage") = tImage;
  gui.getValue<ImageHandle>("myimage").update();  
  Thread::msleep(10);
}
예제 #2
0
파일: crop.cpp 프로젝트: ethz-asl/iclcv
void init(){
  grabber.init(pa("-i"));

  bool c_arg = pa("-c");

  gui << Draw().handle("draw").label("input image")
      << Image().handle("cropped").label("cropped")
      << ( VBox().maxSize(c_arg ? 0 : 12,99).minSize(c_arg ? 0 : 12,1)
           << Button("save as ..").handle("saveAs")
           << Button("overwrite input").handle("overwrite")
           << Combo("0,90,180,270").handle("rot").label("rotation")
           << CheckBox("rectangular",!pa("-r")).handle("rect")
           << Button("Batch crop...").handle("batch")
           << ( HBox().label("rectification size")
                << Spinner(1,4096,640).handle("s1")
                << Label(":")
                << Spinner(1,4096,480).handle("s2")
                )
           << (HBox() 
               << Fps().handle("fps")
               << CamCfg()
               )
           )
      << Show();


  if(!c_arg){
    gui["batch"].registerCallback(batch_crop);
  }
  const ImgBase *image = grabber.grab();
  if(!c_arg){
    mouse_1 = new Mouse1(image->getSize());
    gui["draw"].install(mouse_1);
  }
  mouse_2 = new Mouse2(image->getSize());
  gui["draw"].install(mouse_2);
  
  DrawHandle draw = gui["draw"];
  draw->setImageInfoIndicatorEnabled(false);
  
  if(!c_arg){
    gui["rect"].registerCallback(rectangular_changed);
    rectangular_changed();
    if(*pa("-i",0) != "file" || FileList(*pa("-i",1)).size() != 1){
      gui["overwrite"].disable();
    }else{
      gui["overwrite"].registerCallback(overwrite);
    }
    gui["saveAs"].registerCallback(save_as);
  }

}
예제 #3
0
void batch_mode(){
  if(pa("-config")){
    ConfigFile f(*pa("-config"));
    int masksize = f["config.masksize"];
    int thresh = f["config.threshold"];
    float gamma = f["config.gammaslope"];
    if(!pa("-output")){
      printf("please specify output file pattern\n");
      return;
    }

    grabber.init(pa("-i"));
    FileList fl;
    int maxSteps = -1;
    if(grabber.getType() == "file"){
      fl = FileList(*pa("-input",1));
      maxSteps = fl.size();
    }

    static FileWriter w(*pa("-output"));
    static LocalThresholdOp t;
    t.setMaskSize(masksize);
    t.setGlobalThreshold(thresh);
    t.setGammaSlope(gamma);
  
    int i=0;
    while(maxSteps < 0 || maxSteps--){
      if(maxSteps > 0){
        printf("processing image %30s ......",fl[i++].c_str());
      }
      const ImgBase *image = grabber.grab();
      if(image->getFormat() != formatGray){
        printf("...");
        static ImgBase *grayImage = 0;
        ensureCompatible(&grayImage,depth8u,image->getSize(),formatGray);
        cc(image,grayImage);
        printf("...");
        image = grayImage;
      }
      static ImgBase *dst = 0;
      printf("...");
      t.apply(image,&dst);
      printf("...");
      w.write(dst); 
      printf("done! \n");
      printf("writing image to %30s ... done\n",w.getFilenameGenerator().showNext().c_str());
    }
  }else{
    ERROR_LOG("please run with -config config-filename!");
    return;
  }
}
예제 #4
0
파일: viewer.cpp 프로젝트: ethz-asl/iclcv
void run(){
  static FPSLimiter fps(pa("-maxfps"),10);
  
  gui["image"] = grabber.grab();
  gui["fps"].render();
  fps.wait();
}
예제 #5
0
void update(){
  static Mutex mutex;
  Mutex::Locker l(mutex);
  
  static ImageHandle image = gui["image"];
  static ImageHandle imageOut = gui["imageOut"];
  int filterSize = gui["filterSize"];
  int difference = gui["difference"];
  
  if(gui["disableCL"]){
    smoothing->setUseCL(true);
  }else{
    smoothing->setUseCL(false);
  }
  
  static ImgBase *dst = 0;
  const ImgBase *src = grabber.grab();
  
  smoothing->setFilterSize(filterSize);
  smoothing->setDifference(difference);
  
  Time startT, endT;
  startT = Time::now();
  smoothing->apply(src, &dst);
  endT = Time::now();
  if(smoothing->isCLActive()){
    std::cout <<"OpenCL :"<< (endT-startT).toMilliSeconds() <<" ms" << endl;
  }else{     
    std::cout << "CPU :" << (endT - startT).toMilliSeconds() << " ms" << endl;
  }
  imageOut = dst;
  image = src;
}
예제 #6
0
void init(){
  int masksize = 10;
  int thresh = 2;
  float gamma = 0;
  if(pa("-config")){
    ConfigFile f(*pa("-config"));
    masksize = f["config.masksize"];
    thresh = f["config.threshold"];
    gamma = f["config.gammaslope"];
  }

  gui << Draw().minSize(16,12).handle("orig").label("original image")
      << Image().minSize(16,12).handle("prev").label("preview image")
      << ( VBox().label("controls")
           << Slider(2,200,masksize).label("mask size").out("masksize").minSize(15,2).handle("a")
           << FSlider(-30,40,thresh).label("threshold").out("threshold").minSize(15,2).handle("b")
           << FSlider(0,15,gamma).label("gamma slope").out("gamma").minSize(15,2).handle("c")
           << Button("next image").handle("next")
           << Button("stopped","running").out("loop").handle("d")
           << Button("no clip","clip to roi").out("clipToROI").handle("e")
           << Button("save params").handle("save")
           << Combo("region mean,tiledNN,tiledLIN").handle("algorithm").label("algorithm")
           << ( HBox()
                << Label("..ms").handle("time").label("apply time").minSize(2,3)
                << Fps(10).handle("fps").minSize(4,3).label("fps")
                )
           )
      << Show();
  
  grabber.init(pa("-i"));
  if(grabber.getType() != "file"){
    grabber.useDesired<Size>(pa("-s"));
    if(!pa("-color")){
      grabber.useDesired(formatGray);
    }else{
      grabber.useDesired(formatRGB);
    }
    grabber.useDesired(depth8u);
  }
  
  gui.registerCallback(step,"a,b,c,d,e,next,algorithm");
  gui["orig"].install(new MouseHandler(mouse));
  
  step();
}
예제 #7
0
void step(){
  Mutex::Locker lock(mtex);
  static DrawHandle orig = gui["orig"];
  static ImageHandle prev = gui["prev"];
  static ButtonHandle next = gui["next"];
  static LabelHandle time = gui["time"];
  static ComboHandle algorithm = gui["algorithm"];
  static FPSHandle fps = gui["fps"];
  bool loop = gui["loop"];
  bool clipToROI = gui["clipToROI"];
  int masksize = gui["masksize"];
  float threshold = gui["threshold"];
  float gamma = gui["gamma"];
  gui["save"].registerCallback(save);

  ltop.setClipToROI(clipToROI);
  ltop.setup(masksize, threshold, (LocalThresholdOp::algorithm)(int)algorithm, gamma);

  static const ImgBase *image = 0;
  if(!image || loop || next.wasTriggered()){
    bool init = !image;
    image = grabber.grab();
    if(init){
      selroi[0]=selroi[2]=image->getImageRect();
    }
  }

  const ImgBase *useImage = image;
  if(selroi[1] != image->getImageRect()){
    useImage = useImage->shallowCopy(selroi[1]);
  }
  Time last = Time::now();
  const ImgBase *result = ltop.apply(useImage);
  time = str((Time::now()-last).toMilliSeconds())+"ms";

        
  orig = image;
  
  if(image != useImage){
    delete useImage;
  }

  
  if(selroi[0] != Rect::null){
    orig->color(0,100,255);
    orig->fill(0,100,255,20);
    orig->rect(selroi[0]);
  }
  
  orig->color(255,0,0);
  orig->nofill();
  orig->rect(selroi[1]);
  orig.render();
    
  prev = result;
  fps.render();
}
예제 #8
0
void run(){
  DrawHandle draw = gui["image"];
  const ImgBase *I = grabber.grab();

  draw = I;

  std::vector<ImageRegion> rs = rd.detect(cd.apply(I));
  for(size_t i=0;i<rs.size();++i){
    draw->linestrip(rs[i].getBoundary());
  }
  draw->render();
}
예제 #9
0
파일: viewer.cpp 프로젝트: ethz-asl/iclcv
void init(){
  gui << Image().handle("image").minSize(16,12);
  gui << ( HBox().maxSize(100,2)
           << Fps(10).handle("fps").maxSize(100,2).minSize(5,2)
           << CamCfg("")
           )
      << Show();

  grabber.init(pa("-i"));
  if(pa("-size")){
    grabber.useDesired<Size>(pa("-size"));
  }

}
예제 #10
0
void init() {

	grabber.init(pa("-i"));

	if (pa("-s")) {
		utils::Size size = pa("-s");
		grabber.setDesiredSizeInternal(size);
	}

    // create the GUI
	gui << ( VBox()
			 << ( HBox()
				  << Draw().label("Original").handle("view1").minSize(16, 12)
				  << Draw().label("Median").handle("view2").minSize(16, 12)
				  << Draw().label("Bilateral Filtered").handle("view3").minSize(16, 12)
				  )
			 << ( HBox()
				  << Draw().label("Original").handle("viewedge1").minSize(16, 12)
				  << Draw().label("Median").handle("viewedge2").minSize(16, 12)
				  << Draw().label("Bilateral Filtered").handle("viewedge3").minSize(16, 12)
				  )
			 << CheckBox("Use LAB",true).handle("use_lab")
			 << CheckBox("Use gray image",false).handle("to_gray")
			 << Slider(1,24,4).label("Bilateral Kernel Radius").handle("bi_radius")
			 << Slider(1,24,4).label("Median Kernel Radius").handle("median_radius")
			 << FSlider(0.1,200,5).label("sigma_r (bilateral) ").handle("sigma_r")
			 << FSlider(0.1,200,5).label("sigma_s (bilateral) ").handle("sigma_s")
			 << Slider(0,255,200).label("Canny low th").handle("canny_low_th")
			 << Slider(0,255,255).label("Canny high th").handle("canny_high_th")
			 << Slider(10,100,100).label("ROI of Img (Percent)").handle("roi_size")
			 << Fps().handle("fps")
			 );
    gui << Show();

	bi_filter = new BilateralFilterOp();

}
예제 #11
0
void init(){
  gui << Image().handle("image").minSize(32,24)
      << Image().handle("imageOut").minSize(32,24)
      << Slider(1,22,5).out("filterSize").label("filterSize").maxSize(100,2).handle("filterSize-handle")
      << Slider(1,22,10).out("difference").label("difference").maxSize(100,2).handle("difference-handle")
      << CheckBox("useCL", true).out("disableCL").maxSize(100,2).handle("disableCL-handle")
      << Show();
  
  int maxFilterSize=pa("-maxFilterSize");
  int nullValue=pa("-nullValue");
  
  smoothing = new MotionSensitiveTemporalSmoothing(nullValue, maxFilterSize);
  grabber.init(pa("-i"));
  
  update(); 
}
예제 #12
0
void run() {

	const ImgBase* img = grabber.grab();

	switch(img->getDepth()) {
		case(core::depth8u): {
			grab_cb<icl8u>(img);
			break;
		}
		case(core::depth32f): {
			grab_cb<icl32f>(img);
			break;
		}
		default: break;
	}

	gui["fps"].render();
}
예제 #13
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();
}
예제 #14
0
void init(){
  grabber.init(pa("-i"));
  gui << Draw().handle("image") << Show();

  gui["image"].install(mouse);
}