/******************************************************************** ** 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 : ICLGeom/src/ICLGeom/CoPlanarityFeatureExtractor.cpp ** ** Module : ICLGeom ** ** Authors: Andre Ueckermann ** ** ** ** ** ** 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 namespace icl{ namespace geom{ math::DynMatrix CoPlanarityFeatureExtractor::apply(math::DynMatrix &initialMatrix, std::vector features, const core::Img32f &depthImage, std::vector > &surfaces, float maxAngle, float distanceTolerance, float outlierTolerance, int triangles, int scanlines){ math::DynMatrix coplanar = math::DynMatrix(initialMatrix.rows(),initialMatrix.rows(), true);//result matrix //initialize for(size_t i=0; i surface, int imgWidth){ int id=surface[rand()%surface.size()]; int y = (int)floor((float)id/(float)imgWidth); int x = id-y*imgWidth; utils::Point p(x,y); return p; } Vec CoPlanarityFeatureExtractor::getNormal(Vec p0, Vec p1, Vec p2){ Vec fa=p1-p0; Vec fb=p2-p0; Vec n1(fa[1]*fb[2]-fa[2]*fb[1],//normal fa[2]*fb[0]-fa[0]*fb[2], fa[0]*fb[1]-fa[1]*fb[0], 0); Vec n01=n1/norm3(n1);//normalized normal return n01; } bool CoPlanarityFeatureExtractor::criterion1(Vec n1, Vec n2, float maxAngle){ float angle=getAngle(n1,n2); if(angle>90) angle=180.-angle;//flip if(angle>maxAngle){ return false; } return true; } bool CoPlanarityFeatureExtractor::criterion2(const core::Img32f &depthImage, std::vector &surface1, std::vector &surface2, Vec n1, Vec n2, float maxAngle, int triangles){ std::vector a,b; int w = depthImage.getSize().width; if(surface1.size()>surface2.size()){//find bigger surface b=surface2; a=surface1; }else{ a=surface2; b=surface1; } Vec meanNormal((n1[0]+n2[0])/2., (n1[1]+n2[1])/2., (n1[2]+n2[2])/2., 0);//mean of both surface normals Vec meanComb(0,0,0,0);//mean of combined surface normals core::Channel32f depthImageC = depthImage[0]; for(int p=0; p90.){//flip n01*=-1; ang=180.-ang; } meanComb+=n01; } meanComb/=triangles; float ang=getAngle(meanNormal,meanComb); if(ang>maxAngle){ return false; } return true; } bool CoPlanarityFeatureExtractor::criterion3(const core::Img32f &depthImage, std::vector &surface1, std::vector &surface2, float distanceTolerance, float outlierTolerance, int scanlines){ int w = depthImage.getSize().width; int occlusions=0; for(int l=0; l