Image Component Library (ICL)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Segmentation3D.h
Go to the documentation of this file.
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.GPL  **
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 <ICLGeom/GeomDefs.h>
00034 #include <ICLCore/Img.h>
00035 #include <ICLGeom/PointCloudObjectBase.h>
00036 #include <ICLCV/RegionDetector.h>
00037 
00038 #ifdef HAVE_OPENCL    
00039 #include <CL/cl.hpp>
00040 #endif
00041 
00042 namespace icl{
00043   namespace geom{
00046     class Segmentation3D{
00047         
00048      public:
00050 
00052       Segmentation3D(utils::Size size); 
00053         
00055       ~Segmentation3D();
00056         
00058 
00062       core::Img8u segmentation(DataSegment<float,4> xyz, const core::Img8u &edgeImg, const core::Img32f &depthImg);
00063       
00065 
00069       core::Img8u segmentationBlobs(DataSegment<float,4> xyz, const core::Img8u &edgeImg, const core::Img32f &depthImg);
00070                         
00072 
00073       void setUseCL(bool use);
00074                 
00076 
00077                 void setUseROI(bool use);
00078       
00080 
00084       void setROI(float xMin, float xMax, float yMin, float yMax);
00085                 
00087 
00088       void setMinClusterSize(unsigned int size);
00089       
00091 
00092       void setUseFastGrowing(bool use);
00093       
00095 
00096       void setAssignmentRadius(int radius);
00097       
00099 
00100       void setAssignmentMaxDistance(float maxDistance);
00101       
00103 
00104       void setRANSACeuclDistance(int distance);
00105       
00107 
00108       void setRANSACpasses(int passes); 
00109       
00111 
00112       void setRANSACtolerance(int tolerance); 
00113       
00115 
00116       void setRANSACsubset(int subset);
00117                 
00119 
00120       void setBLOBSeuclDistance(int distance);
00121       
00123 
00124       bool isCLReady();
00125         
00127 
00128       bool isCLActive();
00129       
00131 
00132       core::Img8u getSegmentColorImage();
00133       
00135 
00136       std::vector<std::vector<int> > getCluster();
00137       
00139 
00140       std::vector<std::vector<int> > getBlobs();
00141       
00143 
00144       math::DynMatrix<bool> getNeigboursMatrix();
00145       
00147 
00148       math::DynMatrix<float> getProbabilityMatrix();
00149       
00151 
00152       void setXYZH(DataSegment<float,4> xyz);
00153       
00155 
00156       void setEdgeImage(const core::Img8u &edgeImage);
00157       
00159 
00160       void setDepthImage(const core::Img32f &depth);
00161       
00163       void clearData();
00164                 
00166       void regionGrow();
00167                 
00169       void calculatePointAssignmentAndAdjacency();
00170                 
00172       void calculateCutfreeMatrix();
00173                 
00175       void greedyComposition();
00176                 
00178       void calculateRemainingPoints();
00179                 
00181       void blobSegmentation();
00182                 
00184       void colorPointcloud();
00185       
00186      private:
00187      
00188       int w,h,dim;
00189       utils::Size s;
00190       
00191       float xMinROI, xMaxROI, yMinROI, yMaxROI;
00192       bool useROI;
00193       
00194       bool* elements;
00195                   int* assignment;
00196                   int* assignmentRemaining;
00197                   bool* elementsBlobs;
00198                   int* assignmentBlobs;
00199       
00200       DataSegment<float,4> xyzData;
00201       core::Img8u normalEdgeImage;
00202       core::Img32f depthImage;
00203       
00204       core::Img8u segmentColorImage;
00205       
00206       std::vector<std::vector<int> > cluster;
00207       std::vector<std::vector<int> > blobs;
00208       unsigned int minClusterSize;
00209       bool useFastGrowing;
00210       int assignmentRadius;
00211       float assignmentMaxDistance;
00212       int RANSACeuclDistance; 
00213       int RANSACpasses; 
00214       int RANSACtolerance; 
00215       int RANSACsubset;
00216       int BLOBSeuclDistance;
00217       
00218       math::DynMatrix<bool> neighbours;
00219       math::DynMatrix<bool> cutfree;
00220       math::DynMatrix<float> probabilities;
00221       
00222       cv::RegionDetector* region;
00223    
00224       bool clReady;
00225       bool useCL;
00226       
00227       void checkNeighbourGrayThreshold(int x, int y, int zuw, int threshold, std::vector<int> *data);
00228       
00229       void checkNeighbourDistanceRemaining(int x, int y, int zuw, std::vector<int> *data);
00230       
00231       void regionGrowBlobs();
00232       
00233       void checkNeighbourDistance(int x, int y, int zuw, std::vector<int> *data);
00234       
00235       bool checkNotExist(int zw, std::vector<int> &nb);
00236       
00237       float dist3(const Vec &a, const Vec &b);
00238       
00239     #ifdef HAVE_OPENCL
00240       //OpenCL data
00241       cl_uchar* segmentColorImageRArray;
00242       cl_uchar* segmentColorImageGArray;
00243       cl_uchar* segmentColorImageBArray;
00244       
00245       //OpenCL    
00246       cl::Context context;
00247       std::vector<cl::Device> devices;
00248       cl::Program program;
00249       cl::CommandQueue queue;
00250       
00251       cl::Kernel kernelSegmentColoring; 
00252       cl::Kernel kernelPointAssignment; 
00253       cl::Kernel kernelCheckRANSAC; 
00254       cl::Kernel kernelAssignRANSAC; 
00255 
00256       //OpenCL buffer
00257       cl::Buffer segmentColorImageRBuffer;
00258       cl::Buffer segmentColorImageGBuffer;
00259       cl::Buffer segmentColorImageBBuffer;
00260       cl::Buffer assignmentBuffer;      
00261       cl::Buffer neighboursBuffer;
00262       cl::Buffer elementsBuffer;
00263       cl::Buffer assignmentOutBuffer;
00264       cl::Buffer xyzBuffer;
00265       cl::Buffer assignmentBlobsBuffer;
00266       cl::Buffer elementsBlobsBuffer;
00267     #endif
00268     };
00269   } // namespace geom
00270 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines