/******************************************************************** ** Image Component Library (ICL) ** ** ** ** Copyright (C) 2006-2012 CITEC, University of Bielefeld ** ** Neuroinformatics Group ** ** Website: www.iclcv.org and ** ** http://opensource.cit-ec.de/projects/icl ** ** ** ** File : ICLCV/src/DefaultColorBlobSearcher.cpp ** ** Module : ICLCV ** ** Authors: Christof Elbrechter, Robert Haschke ** ** ** ** ** ** Commercial License ** ** ICL can be used commercially, please refer to our website ** ** www.iclcv.org for more details. ** ** ** ** GNU General Public License Usage ** ** Alternatively, this file may be used under the terms of the ** ** GNU General Public License version 3.0 as published by the ** ** Free Software Foundation and appearing in the file LICENSE.GPL ** ** included in the packaging of this file. Please review the ** ** following information to ensure the GNU General Public License ** ** version 3.0 requirements will be met: ** ** http://www.gnu.org/copyleft/gpl.html. ** ** ** ** 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 using namespace icl::utils; using namespace icl::core; namespace icl{ namespace cv{ // {{{ RGBPixelRating class RGBPixelRating : public PixelRating{ public: RGBPixelRating(const icl8u ref[3], const icl8u thresh[3]){ for(int i=0;i<3;i++){ this->thresh[i] = thresh[i]; this->ref[i]=ref[i]; } } virtual bool rate(icl8u r, icl8u g, icl8u b){ return abs(ref[0]-r) < thresh[0] && abs(ref[1]-g) < thresh[1] && abs(ref[2]-b) < thresh[2]; } protected: icl8u thresh[3],ref[3]; }; // }}} // {{{ RatingGroupOR struct RatingGroupOR : public PixelRatingGroup{ virtual bool combineRatings(const vector &ratings){ for(vector::const_iterator it = ratings.begin();it!=ratings.end(); ++it){ if(*it)return true; } return false; } }; // }}} // {{{ RatingGroupAND struct RatingGroupAND : public PixelRatingGroup{ virtual bool combineRatings(const vector &ratings){ for(vector::const_iterator it = ratings.begin();it!=ratings.end(); ++it){ if(!(*it))return false; } return true; } }; // }}} // {{{ DefaultColorBlobSearcher DefaultColorBlobSearcher::DefaultColorBlobSearcher(const Size &imageSize):m_oImageSize(imageSize){ // {{{ open } // }}} DefaultColorBlobSearcher::~DefaultColorBlobSearcher(){ // {{{ open } // }}} void DefaultColorBlobSearcher::prepareForNewImage(Img8u *poImage, Img8u *poMask){ // {{{ open (void)poImage; (void)poMask; for(int i=0;i::search(poImage,poMask); } // }}} int DefaultColorBlobSearcher::addSubSearcher(const vector &rs, const vector &gs, const vector &bs, const icl8u thresholds[3], DefaultColorBlobSearcher::RatingCombinationType rct, DefaultColorBlobSearcher::CenterEstimationType cet){ // {{{ open PixelRatingGroup *rg; if(rct == rctOR) rg = new RatingGroupOR(); else rg = new RatingGroupAND(); icl8u ref[3]; for(unsigned int i=0;iaddPR(new RGBPixelRating(ref,thresholds)); } addPR(rg); m_vecCet.push_back(cet); return getNumPR() -1; } // }}} const Size &DefaultColorBlobSearcher::getImageSize() const { // {{{ open return m_oImageSize; } // }}} void DefaultColorBlobSearcher::setImageSize(const Size &size){ // {{{ open if(m_oImageSize != size){ m_oImageSize = size; unsigned int nPixelRatings = m_vecXMedianLists.size(); m_vecXMedianLists.clear(); m_vecYMedianLists.clear(); for(unsigned int i=0;i