/******************************************************************** ** 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 : ICLIO/src/ICLIO/DemoGrabber.cpp ** ** Module : ICLIO ** ** Authors: Christof Elbrechter, Viktor Richter ** ** ** ** ** ** 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 using namespace icl::utils; using namespace icl::core; namespace icl{ namespace io{ namespace{ template void rect(Img &image, const Color &color, const Rect &r){ for(int i=0;i(color[i]); for(int y=r.y; y void erode_buffer(Img &t){ t.transform(std::bind2nd(std::multiplies(),0.99),t); } const ImgBase* DemoGrabber::acquireImage(){ Mutex::Locker __lock(m_mutex); ensureCompatible(&m_drawBuffer,m_drawDepth,m_drawSize,m_drawFormat); m_v += Point32f(utils::random(-0.001, 0.001),utils::random(-0.001, 0.001)); m_v.x = clip(m_v.x,-m_maxV.x,m_maxV.x); m_v.y = clip(m_v.y,-m_maxV.y,m_maxV.y); m_x += m_v; if(m_x.x>1 || m_x.x<0){ m_v.x *= -1; if(m_x.x>1){ m_x.x = 1; }else{ m_x.x = 0; } } if(m_x.y>1 || m_x.y<0){ m_v.y *= -1; if(m_x.y>1){ m_x.y = 1; }else{ m_x.y = 0; } } Size s = m_drawBuffer->getSize(); Rect r((int)((m_x.x-m_size.width)*s.width), (int)((m_x.y-m_size.height)*s.height), (int)(m_size.width*s.width), (int)(m_size.height*s.height)); r &= m_drawBuffer->getImageRect(); if(m_drawBuffer->getDepth() == depth8u){ rect(*m_drawBuffer->asImg(),m_color,r); }else{ rect(*m_drawBuffer->asImg(),m_color,r); } if(m_drawBuffer->getDepth() == depth8u){ erode_buffer(*m_drawBuffer->asImg());; }else{ erode_buffer(*m_drawBuffer->asImg());; } Time now = Time::now(); Time neededInterval = Time(1000000)/m_maxFPS; if((now-m_lastTime) < neededInterval){ Time restSleepTime = neededInterval-(now-m_lastTime); Thread::msleep(restSleepTime.toMilliSeconds()); } m_drawBuffer->setTime(now); m_lastTime = now; prop("current-pos").value = "x:" + str(m_x.x*m_drawSize.width) + " y:" + str(m_x.y*m_drawSize.height); return m_drawBuffer; } // callback for changed configurable properties void DemoGrabber::processPropertyChange(const utils::Configurable::Property &prop){ if(prop.name == "current-pos"){ // do nothing. info field return; } if(prop.name == "blob-red"){ m_color[0] = parse(prop.value); }else if(prop.name == "blob-green"){ m_color[1] = parse(prop.value); }else if(prop.name == "blob-blue"){ m_color[2] = parse(prop.value); }else if(prop.name == "blob-size"){ int percent = parse(prop.value); m_size = Size32f(percent/100.,percent/100.); }else if(prop.name == "format"){ std::vector x = tok(prop.value,"-"); if(x.size() != 2){ ERROR_LOG("invalid value for prorerty \"format\"" << prop.value); }else{ m_drawFormat = parse(x[0]); m_drawDepth = parse(x[1]); } }else if(prop.name == "size"){ m_drawSize = parse(prop.value); }else if(prop.name == "max-speed"){ float m = parse(prop.value); m_maxV.x = m_maxV.y = m; }else if(prop.name == "set-to-center"){ m_x.x = 0.5; m_x.y = 0.5; } } REGISTER_CONFIGURABLE(DemoGrabber, return new DemoGrabber(30)); Grabber* createDemoGrabber(const std::string ¶m){ return new DemoGrabber(to32f(param)); } const std::vector& getDemoDeviceList(std::string hint, bool rescan){ static std::vector deviceList; if(rescan){ deviceList.clear(); if(hint.size()){ deviceList.push_back(GrabberDeviceDescription("demo", hint, "a demo image source")); } else { deviceList.push_back(GrabberDeviceDescription("demo", "0", "a demo image source")); } } return deviceList; } REGISTER_GRABBER(demo,utils::function(createDemoGrabber), utils::function(getDemoDeviceList),"demo:0:demo image source"); } // namespace io }