/******************************************************************** ** 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 : ICLGeom/apps/[...]/surf-based-object-tracking/.cpp ** ** Module : ICLGeom ** ** 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 #include #include GenericGrabber grabber; SmartPtr surf; RansacBasedPoseEstimator *pe = 0; Size32f ts; // template pixel -> mm VBox gui; Scene scene; SceneObject *obj = 0; void init(){ grabber.init(pa("-i")); Size32f t(pa("-t",1).as(), pa("-t",2).as()); float d = pa("-t",3); scene.addCamera(*pa("-cam")); pe = new RansacBasedPoseEstimator(scene.getCamera(0)); obj = SceneObject::cuboid(t.width/2,t.height/2,d/2,t.width,t.height,d); obj->setColor(Primitive::quad, GeomColor(0,100,255,50)); obj->setColor(Primitive::line, geom_red()); obj->setLineWidth(3); scene.addObject(obj); surf = new SurfFeatureDetector(5,4,2,0.00005,"opensurf"); Img8u templ = load(pa("-t")); surf->setReferenceImage(&templ); ts = Size32f(t.width/templ.getWidth(), t.height/templ.getHeight()); gui << Draw3D().handle("draw").minSize(32,24) << FSlider(0,0.04,0.001).handle("t").maxSize(99,3) << Show(); gui["draw"].link(scene.getGLCallback(0)); gui["draw"].install(scene.getMouseHandler(0)); } void run(){ DrawHandle3D draw = gui["draw"]; const ImgBase *image = grabber.grab(); draw = image; surf->setThreshold(gui["t"]); const std::vector &ms = surf->match(image); if(ms.size() >= 4){ std::vector curr(ms.size()),templ(ms.size()); for(size_t i=0;idraw(ms[i].first.vis()); curr[i] = Point32f(ms[i].first.x,ms[i].first.y); templ[i] = Point32f(ms[i].second.x,ms[i].second.y).transform(ts.width,ts.height); } Mat T = pe->fit(templ,curr).T; obj->setTransformation(T); } draw.render(); } int main(int n, char **args){ pa_explain("-p","select surf-feature detection plugin (opensurf, clsurf or best)"); return ICLApp(n,args,"[m]-i(2) -t(filename,obj-width-mm,obj-height-mm,obj-thickness-mm) " "-cam(file) -surf-plugin|-p(plugin=opensurf)",init,run).exec(); }