/******************************************************************** ** 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/FiducialDetectorPluginAmoeba ** ** .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 #include using namespace icl::utils; using namespace icl::math; using namespace icl::core; using namespace icl::geom; using namespace icl::cv; namespace icl{ namespace markers{ class FiducialDetectorPluginAmoeba::Data{ public: std::vector rs; std::vector matchingRegions; std::vector fids; }; FiducialDetectorPluginAmoeba::FiducialDetectorPluginAmoeba():data(new Data){ } FiducialDetectorPluginAmoeba::~FiducialDetectorPluginAmoeba(){ delete data; } void FiducialDetectorPluginAmoeba::getFeatures(Fiducial::FeatureSet &dst){ static const Fiducial::FeatureSet f = ( Fiducial::Center2D | Fiducial::Rotation2D | Fiducial::Corners2D ); dst = f; } void FiducialDetectorPluginAmoeba::getCorners2D(std::vector &dst, FiducialImpl &impl){ const std::vector &b = data->matchingRegions[impl.index].getBoundary(); dst.resize(b.size()); std::copy(b.begin(),b.end(),dst.begin()); } void FiducialDetectorPluginAmoeba::getRotation2D(float &dst, FiducialImpl &impl){ const ImageRegion &r = data->matchingRegions[impl.index]; Point32f meanAll,meanWhite; const std::vector &allChildren = r.getSubRegions(); int nWhite = 0; int nAll = 0; for(unsigned int i=0;i &s=c.getSubRegions(); if(s.size()){ for(unsigned int j=0;j &dst, const std::vector ®ions){ static const Fiducial::FeatureSet supported = ( Fiducial::Center2D | Fiducial::Rotation2D | Fiducial::Corners2D | Fiducial::ImageRegion ); static Fiducial::FeatureSet computed = ( 1<fids.size();++i){ delete data->fids[i]; } for(unsigned int i=0;irs.size();++j){ if(data->rs[j].match(regions[i])){ FiducialImpl* fids = new FiducialImpl(this, supported, computed, j, data->matchingRegions.size(), Size::null); fids->imageRegion = regions[i]; dst.push_back(fids); dst.back()->ensure2D()->infoCenter = regions[i].getCOG(); dst.back()->info2D->infoRotation = 0; // TODO how to define the orientation ?? data->matchingRegions.push_back(regions[i]); break; } } } data->fids = dst; } void FiducialDetectorPluginAmoeba::addOrRemoveMarkers(bool add, const Any &which, const ParamList ¶ms){ File f(which); std::vector rs; if(f.exists()){ f.open(File::readText); while(f.hasMoreLines()){ try{ rs.push_back(f.readLine()); }catch(const ICLException &ex){ ERROR_LOG("caught exception: " << ex.what()); } } }else{ std::vector ts = tok(which,"\n, "); for(unsigned int i=0;irs.begin(),data->rs.end(),rs[i]) == data->rs.end()){ data->rs.push_back(rs[i]); }else{ ERROR_LOG("TwoLevelRegionStructure with code '" << rs[i].code << "' was already added before"); } } }else{ for(unsigned int i=0;i::iterator it = std::find(data->rs.begin(),data->rs.end(),rs[i]); if(it != data->rs.end()){ data->rs.erase(it); // if not contained, no message } } } } } // namespace markers }