Image Component Library (ICL)
|
00001 /******************************************************************** 00002 ** Image Component Library (ICL) ** 00003 ** ** 00004 ** Copyright (C) 2006-2013 CITEC, University of Bielefeld ** 00005 ** Neuroinformatics Group ** 00006 ** Website: www.iclcv.org and ** 00007 ** http://opensource.cit-ec.de/projects/icl ** 00008 ** ** 00009 ** File : ICLGeom/src/ICLGeom/Segmentation3D.h ** 00010 ** Module : ICLGeom ** 00011 ** Authors: Andre Ueckermann ** 00012 ** ** 00013 ** ** 00014 ** GNU LESSER GENERAL PUBLIC LICENSE ** 00015 ** This file may be used under the terms of the GNU Lesser General ** 00016 ** Public License version 3.0 as published by the ** 00017 ** ** 00018 ** Free Software Foundation and appearing in the file LICENSE.LGPL ** 00019 ** included in the packaging of this file. Please review the ** 00020 ** following information to ensure the license requirements will ** 00021 ** be met: http://www.gnu.org/licenses/lgpl-3.0.txt ** 00022 ** ** 00023 ** The development of this software was supported by the ** 00024 ** Excellence Cluster EXC 277 Cognitive Interaction Technology. ** 00025 ** The Excellence Cluster EXC 277 is a grant of the Deutsche ** 00026 ** Forschungsgemeinschaft (DFG) in the context of the German ** 00027 ** Excellence Initiative. ** 00028 ** ** 00029 ********************************************************************/ 00030 00031 #pragma once 00032 00033 #include <ICLUtils/CompatMacros.h> 00034 #include <ICLGeom/GeomDefs.h> 00035 #include <ICLCore/Img.h> 00036 #include <ICLGeom/PointCloudObjectBase.h> 00037 #include <ICLCV/RegionDetector.h> 00038 00039 #ifdef ICL_HAVE_OPENCL 00040 #include <ICLUtils/CLProgram.h> 00041 #include <ICLUtils/CLBuffer.h> 00042 #include <ICLUtils/CLKernel.h> 00043 #endif 00044 00045 namespace icl{ 00046 namespace geom{ 00049 class ICLGeom_API Segmentation3D{ 00050 00051 public: 00053 00055 Segmentation3D(utils::Size size); 00056 00058 ~Segmentation3D(); 00059 00061 00065 core::Img8u segmentation(core::DataSegment<float,4> xyz, const core::Img8u &edgeImg, const core::Img32f &depthImg); 00066 00068 00072 core::Img8u segmentationBlobs(core::DataSegment<float,4> xyz, const core::Img8u &edgeImg, const core::Img32f &depthImg); 00073 00075 00076 void setUseCL(bool use); 00077 00079 00080 void setUseROI(bool use); 00081 00083 00087 void setROI(float xMin, float xMax, float yMin, float yMax); 00088 00090 00091 void setMinClusterSize(unsigned int size); 00092 00094 00095 void setUseFastGrowing(bool use); 00096 00098 00099 void setAssignmentRadius(int radius); 00100 00102 00103 void setAssignmentMaxDistance(float maxDistance); 00104 00106 00107 void setRANSACeuclDistance(int distance); 00108 00110 00111 void setRANSACpasses(int passes); 00112 00114 00115 void setRANSACtolerance(int tolerance); 00116 00118 00119 void setRANSACsubset(int subset); 00120 00122 00123 void setBLOBSeuclDistance(int distance); 00124 00126 00127 bool isCLReady(); 00128 00130 00131 bool isCLActive(); 00132 00134 00135 core::Img8u getSegmentColorImage(); 00136 00138 00139 std::vector<std::vector<int> > getCluster(); 00140 00142 00143 std::vector<std::vector<int> > getBlobs(); 00144 00146 00147 const int* getAssignment(); 00148 00150 00151 math::DynMatrix<bool> getNeigboursMatrix(); 00152 00154 00155 math::DynMatrix<float> getProbabilityMatrix(); 00156 00158 00159 void setXYZH(core::DataSegment<float,4> xyz); 00160 00162 00163 void setEdgeImage(const core::Img8u &edgeImage); 00164 00166 00167 void setDepthImage(const core::Img32f &depth); 00168 00170 void clearData(); 00171 00173 void regionGrow(); 00174 00176 void calculatePointAssignmentAndAdjacency(); 00177 00179 void calculateCutfreeMatrix(); 00180 00182 void greedyComposition(); 00183 00185 void calculateRemainingPoints(); 00186 00188 void blobSegmentation(); 00189 00191 void colorPointcloud(); 00192 00193 private: 00194 00195 int w,h,dim; 00196 utils::Size s; 00197 00198 float xMinROI, xMaxROI, yMinROI, yMaxROI; 00199 bool useROI; 00200 00201 bool* elements; 00202 int* assignment; 00203 int* assignmentRemaining; 00204 bool* elementsBlobs; 00205 int* assignmentBlobs; 00206 00207 core::DataSegment<float,4> xyzData; 00208 core::Img8u normalEdgeImage; 00209 core::Img32f depthImage; 00210 00211 core::Img8u segmentColorImage; 00212 00213 std::vector<std::vector<int> > cluster; 00214 std::vector<std::vector<int> > blobs; 00215 unsigned int minClusterSize; 00216 bool useFastGrowing; 00217 int assignmentRadius; 00218 float assignmentMaxDistance; 00219 int RANSACeuclDistance; 00220 int RANSACpasses; 00221 int RANSACtolerance; 00222 int RANSACsubset; 00223 int BLOBSeuclDistance; 00224 00225 math::DynMatrix<bool> neighbours; 00226 math::DynMatrix<bool> cutfree; 00227 math::DynMatrix<float> probabilities; 00228 00229 cv::RegionDetector* region; 00230 00231 bool clReady; 00232 bool useCL; 00233 00234 void checkNeighbourGrayThreshold(int x, int y, int zuw, int threshold, std::vector<int> *data); 00235 00236 void checkNeighbourDistanceRemaining(int x, int y, int zuw, std::vector<int> *data); 00237 00238 void regionGrowBlobs(); 00239 00240 void checkNeighbourDistance(int x, int y, int zuw, std::vector<int> *data); 00241 00242 bool checkNotExist(int zw, std::vector<int> &nb); 00243 00244 float dist3(const Vec &a, const Vec &b); 00245 00246 #ifdef ICL_HAVE_OPENCL 00247 //OpenCL data 00248 unsigned char* segmentColorImageRArray; 00249 unsigned char* segmentColorImageGArray; 00250 unsigned char* segmentColorImageBArray; 00251 00252 //OpenCL 00253 utils::CLProgram program; 00254 utils::CLKernel kernelSegmentColoring; 00255 utils::CLKernel kernelPointAssignment; 00256 utils::CLKernel kernelCheckRANSAC; 00257 utils::CLKernel kernelAssignRANSAC; 00258 00259 //OpenCL buffer 00260 utils::CLBuffer segmentColorImageRBuffer; 00261 utils::CLBuffer segmentColorImageGBuffer; 00262 utils::CLBuffer segmentColorImageBBuffer; 00263 utils::CLBuffer assignmentBuffer; 00264 utils::CLBuffer neighboursBuffer; 00265 utils::CLBuffer elementsBuffer; 00266 utils::CLBuffer assignmentOutBuffer; 00267 utils::CLBuffer xyzBuffer; 00268 utils::CLBuffer assignmentBlobsBuffer; 00269 utils::CLBuffer elementsBlobsBuffer; 00270 #endif 00271 }; 00272 } // namespace geom 00273 }