/******************************************************************** ** 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/MarkerGridEvaluater.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 namespace icl{ namespace markers{ using namespace utils; using namespace math; static float sprod2(const Point32f &a, const FixedColVector &b){ return a.x*b.x + a.y*b.y; } MarkerGridEvaluater::Line::PCAInfo MarkerGridEvaluater::Line::perform_pca(const std::vector &ps){ PCAInfo pca; pca.c[0] = pca.c[1] = 0; pca.isNull = true; int n = (int)ps.size(); if(ps.size() <= 2){ return pca; } for(int i=0;i &ps, float *error){ isNull = true; PCAInfo pca = perform_pca(ps); if(pca.isNull) return; if(error) *error = pca.getError(); // find min and max projection float min = 1, max = -1; Point32f pmin, pmax; PCAInfo::V v0 = pca.evecs.col(0); for(size_t i=0;i max){ max = pr; pmax = ps[i]; } } this->a.x = pca.c.x + v0.x * max; this->a.y = pca.c.y + v0.y * max; this->b.x = pca.c.x + v0.x * min; this->b.y = pca.c.y + v0.y * min; isNull = false; } template void MarkerGridEvaluater::updateLines(){ const int w = grid->getWidth(), h = grid->getHeight(); this->error = 0; std::vector > > ps; const size_t oHorz = 2*w, oDiag=2*w+2*h; /// vertical lines for(int x=0;x); std::vector &l = *ps.back(); ps.push_back(new std::vector); std::vector &r = *ps.back(); for(int y=0;y); std::vector &u = *ps.back(); ps.push_back(new std::vector); std::vector &b = *ps.back(); for(int x=0;x); std::vector &l = *ps.back(); ps.push_back(new std::vector); std::vector &c = *ps.back(); ps.push_back(new std::vector); std::vector &r = *ps.back(); ps.push_back(new std::vector); std::vector &lu = *ps.back(); ps.push_back(new std::vector); std::vector &cu = *ps.back(); ps.push_back(new std::vector); std::vector &ru = *ps.back(); for(int x=xs,y=ys; x<=xe;++x, --y){ const Marker &m = (*grid)(x,y), &mu = (*grid)(x,h-1-y); if(m.wasFound()){ const Marker::KeyPoints &ip = m.getImagePoints(); l.push_back(ip.ul); c.push_back(ip.ll); c.push_back(ip.ur); r.push_back(ip.lr); } if(mu.wasFound()){ const Marker::KeyPoints &ip = mu.getImagePoints(); lu.push_back(ip.ll); cu.push_back(ip.ul); cu.push_back(ip.lr); ru.push_back(ip.ur); } } if(++ys >= h){ ys = h-1; ++xs; } if(++xe >= w){ xe = w-1; ++ye; } if(ye == h-1) break; } /* 0 1 2 3 4 5 6 | | | | | | | 0- a b c d e f + 1- g h i j k l * 2- m n o p q r # 3- s t u v w x = 4- 0 1 2 3 4 5 & */ if(STORE_LINES){ lines.resize(ps.size()); } int nValid = 0; float e = 0; for(size_t i=0;isize()); std::cout << "points:" << std::endl; for(int j=0;jsize();++j){ std::cout << i << " :" << (*ps[i])[j] << std::endl; } throw 32; }*/ error += ::sqrt(p.getError()); ++nValid; } } } if(nValid){ error /= nValid; } } template void MarkerGridEvaluater::updateLines(); template void MarkerGridEvaluater::updateLines(); float MarkerGridEvaluater::evalError(bool storeLines) { if(storeLines){ updateLines(); }else{ updateLines(); } return error; } utils::VisualizationDescription MarkerGridEvaluater::vis() const{ VisualizationDescription vd; for(size_t i=0;i