/******************************************************************** ** 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 : ICLMarkers/src/ICLMarkers/MultiCamFiducialDetector.cpp ** ** Module : ICLMarkers ** ** 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 using namespace icl::utils; using namespace icl::math; using namespace icl::core; using namespace icl::geom; namespace icl{ namespace markers{ struct MultiCamFiducialDetector::Data{ bool camsDeeplyCopied; std::vector cams; std::vector detectors; std::vector > results; std::vector impls; int numImplsUsed; std::vector output; ~Data(){ if(camsDeeplyCopied){ for(unsigned int i=0;idetectors.size();++i){ m_data->detectors[i]->setPropertyValue(p.name, value); } } MultiCamFiducialDetector::MultiCamFiducialDetector():m_data(0){} MultiCamFiducialDetector::MultiCamFiducialDetector(const std::string &pluginType, const Any &markersToLoad, const ParamList ¶ms, const std::vector &cams, bool syncProperties, bool deepCopyCams) throw (ICLException):m_data(0){ init(pluginType,markersToLoad,params,cams,syncProperties,deepCopyCams); } void MultiCamFiducialDetector::init(const std::string &pluginType, const Any &markersToLoad, const ParamList ¶ms, const std::vector &cams, bool syncProperties, bool deepCopyCams) throw (ICLException){ if(m_data) delete m_data; m_data = new Data; m_data->camsDeeplyCopied = deepCopyCams; if(deepCopyCams){ std::vector copiedCams(cams.size()); for(unsigned int i=0;icams = copiedCams; }else{ m_data->cams = cams; } for(unsigned int i=0;idetectors.push_back(new FiducialDetector(pluginType,markersToLoad,params)); m_data->detectors[i]->setCamera(*m_data->cams[i]); if(!(i && syncProperties)){ addChildConfigurable(m_data->detectors[i], syncProperties ? str("") : str("detector ")+str(i)); } } if(syncProperties){ Configurable::registerCallback(function(this,&MultiCamFiducialDetector::property_callback)); } m_data->results.resize(cams.size()); } const std::vector &MultiCamFiducialDetector::detect(const std::vector &images, int minCamsFound) throw (ICLException){ ICLASSERT_THROW(m_data, ICLException(str(__FUNCTION__)+": this is null")); ICLASSERT_THROW(m_data->detectors.size() == images.size(), ICLException(str(__FUNCTION__)+ ": given image count is wrong (got " + str(images.size()) + " but expected " + str(m_data->detectors.size()) + ")" )); int maxID = -1; for(unsigned int i=0;idetectors.size();++i){ std::vector &r = m_data->results[i]; r = m_data->detectors[i]->detect(images[i]); for(unsigned int j=0;j maxID) maxID = id; } } if(maxID == -1){ m_data->output.clear(); return m_data->output; } m_data->numImplsUsed = maxID +1; if((int)m_data->impls.size() < m_data->numImplsUsed){ m_data->impls.resize(m_data->numImplsUsed); } for(int i=0;inumImplsUsed;++i){ m_data->impls[i].numFound = 0; } for(unsigned int i=0;iresults.size();++i){ std::vector &r = m_data->results[i]; for(unsigned int j=0;jimpls[id]; if(!m.numFound) { m.init(id); } ++m.numFound; m.fids.push_back(r[j]); m.cams.push_back(m_data->cams[i]); } } m_data->output.clear(); for(int i=0;inumImplsUsed;++i){ if(m_data->impls[i].numFound >= minCamsFound){ m_data->output.push_back(MultiCamFiducial(&m_data->impls[i])); } } return m_data->output; } const FiducialDetector &MultiCamFiducialDetector::getFiducialDetector(int idx) const{ ICLASSERT_THROW(m_data, ICLException(str(__FUNCTION__)+": this is null")); return *m_data->detectors[idx]; } FiducialDetector &MultiCamFiducialDetector::getFiducialDetector(int idx){ ICLASSERT_THROW(m_data, ICLException(str(__FUNCTION__)+": this is null")); return *m_data->detectors[idx]; } void MultiCamFiducialDetector::loadMarkers(const Any &which, const ParamList ¶ms) throw (ICLException){ ICLASSERT_THROW(m_data, ICLException(str(__FUNCTION__)+": this is null")); for(int i=0;idetectors[i]->loadMarkers(which,params); } } void MultiCamFiducialDetector::unloadMarkers(const Any &which){ ICLASSERT_THROW(m_data, ICLException(str(__FUNCTION__)+": this is null")); for(int i=0;idetectors[i]->unloadMarkers(which); } } std::string MultiCamFiducialDetector::getIntermediateImageNames() const{ ICLASSERT_THROW(m_data, ICLException(str(__FUNCTION__)+": this is null")); std::ostringstream str; for(int i=0;i iin = tok(m_data->detectors[i]->getIntermediateImageNames(),","); for(unsigned int j=0;j(name.substr(4)); } const ImgBase *MultiCamFiducialDetector::getIntermediateImage(const std::string &name) const throw (ICLException){ ICLASSERT_THROW(m_data, ICLException(str(__FUNCTION__)+": this is null")); int idx = parse(name.substr(4)); if(idx >= 0 && idx < getNumCameras()){ size_t colonPos = name.find(':'); return m_data->detectors[idx]->getIntermediateImage(name.substr(colonPos+1)); }else{ return 0; } } int MultiCamFiducialDetector::getNumCameras() const{ ICLASSERT_THROW(m_data, ICLException(str(__FUNCTION__)+": this is null")); return m_data->detectors.size(); } REGISTER_CONFIGURABLE_DEFAULT(MultiCamFiducialDetector); } // namespace markers }