/******************************************************************** ** Image Component Library (ICL) ** ** ** ** Copyright (C) 2006-2013 CITEC, University of Bielefeld ** ** Neuroinformatics Group ** ** Website: www.iclcv.org and ** ** http://opensource.cit-ec.de/projects/icl ** ** ** ** File : ICLCV/demos/hough-line/hough-line.cpp ** ** Module : ICLCV ** ** Authors: Christof Elbrechter ** ** ** ** ** ** GNU LESSER GENERAL PUBLIC LICENSE ** ** This file may be used under the terms of the GNU Lesser General ** ** Public License version 3.0 as published by the ** ** ** ** Free Software Foundation and appearing in the file LICENSE.LGPL ** ** included in the packaging of this file. Please review the ** ** following information to ensure the license requirements will ** ** be met: http://www.gnu.org/licenses/lgpl-3.0.txt ** ** ** ** The development of this software was supported by the ** ** Excellence Cluster EXC 277 Cognitive Interaction Technology. ** ** The Excellence Cluster EXC 277 is a grant of the Deutsche ** ** Forschungsgemeinschaft (DFG) in the context of the German ** ** Excellence Initiative. ** ** ** ********************************************************************/ #include #include typedef FixedColVector Pos; HSplit gui; HoughLineDetector hld; Img8u edgeImage(Size::VGA,1); struct Mouse : public MouseHandler { virtual void process(const MouseEvent &e){ if(e.isLeft() || e.isRight()){ edgeImage(e.getX(), e.getY(), 0) = 255 * e.isLeft(); } } }; void init(){ edgeImage.fill(0); gui << Draw().handle("view").minSize(32,24) << ( VSplit() << Image().handle("lut").label("hough space").minSize(16,12) << ( VBox() << Button("load image").handle("load") << Image().handle("inhibit").label("local inhibition image").minSize(8,6) << Slider(0,100,1).out("maxlines").label("max lines") << FSlider(0.01,1,0.03).out("dRho").label("rho sampling step") << FSlider(0.1,10,2).out("dR").label("r sampling step") << FSlider(2,100,10).out("rInhib").label("r inhibition radius") << FSlider(0.05,2,0.3).out("rhoInhib").label("rho inhibition radius") << ( HBox() << Button("off","!on").out("gaussianInhibition").label("gaussian inhib") << Button("off","!on").out("blurHoughSpace").label("blur hough space") ) << ( HBox() << Button("off","!on").out("dilateEntries").label("dilate entries") << Button("off","!on").out("blurredSampling").label("blurred sampling") ) ) ) << Show(); gui["view"].install(new Mouse); gui["view"] = Img8u(Size::VGA,1); gui["view"].render(); } void run(){ int maxlines = gui["maxlines"]; float dRho = gui["dRho"]; float dR = gui["dR"]; float rInhib = gui["rInhib"]; float rhoInhib = gui["rhoInhib"]; ImageHandle lut = gui["lut"]; ImageHandle inhibit = gui["inhibit"]; DrawHandle view = gui["view"]; bool gaussianInhibition = gui["gaussianInhibition"]; bool blurHoughSpace = gui["blurHoughSpace"]; bool dilateEntries = gui["dilateEntries"]; bool blurredSampling = gui["blurredSampling"]; static ButtonHandle load = gui["load"]; if(load.wasTriggered()){ try{ edgeImage = qt::load(openFileDialog()); }catch(...){} } int w = edgeImage.getWidth(), h = edgeImage.getHeight(); hld.init(dRho,dR,Range32f(0,sqrt(w*w+h*h)),rInhib,rhoInhib, gaussianInhibition,blurHoughSpace,dilateEntries,blurredSampling); hld.clear(); hld.add(edgeImage); std::vector sig; std::vector ls = hld.getLines(maxlines,sig); (*lut)->setRangeMode(ICLWidget::rmAuto); (*lut)->setFitMode(ICLWidget::fmFit); lut = hld.getImage(); lut.render(); if(gaussianInhibition){ (*inhibit)->setRangeMode(ICLWidget::rmAuto); (*inhibit)->setFitMode(ICLWidget::fmFit); inhibit = hld.getInhibitionMap(); } view = edgeImage; (*view)->fill(255,255,255,0); (*view)->color(255,0,0,255); for(unsigned int i=0;iline(a[0],a[1],b[0],b[1]); (*view)->text(str(sig[i]),l.o[0],l.o[1],-1,-1,8); } view->render(); Thread::msleep(10); } int main(int n, char **ppc){ return ICLApplication(n,ppc,"",init,run).exec(); }