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 : ICLCV/src/ICLCV/ContourDetector.h ** 00010 ** Module : ICLCV ** 00011 ** Authors: Sergius Gaulik, Christof Elbrechter ** 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 <ICLUtils/Uncopyable.h> 00035 #include <ICLCore/Img.h> 00036 00037 #include <vector> 00038 00039 namespace icl{ 00040 namespace cv{ 00041 00042 struct ContourImpl{ 00043 virtual bool hasHierarchy() const = 0; 00044 virtual int getID() const = 0; 00045 virtual bool isHole() const = 0; 00046 virtual const std::vector<int> &getChildren() const = 0; 00047 virtual const utils::Point *begin() const = 0; 00048 virtual const utils::Point *end() const = 0; 00049 }; 00050 00052 class ICLCV_API Contour{ 00053 ContourImpl *impl; 00054 00055 public: 00056 Contour(ContourImpl *impl = 0):impl(impl){} 00057 00058 inline bool isNull() const { 00059 return !impl; 00060 } 00061 inline operator bool() const { 00062 return !!impl; 00063 } 00064 inline bool hasHierarchy() const{ 00065 return impl->hasHierarchy(); 00066 } 00067 inline int getID() const { 00068 return impl->getID(); 00069 } 00070 bool isHole() const{ 00071 return impl->isHole(); 00072 } 00073 const std::vector<int> &getChildren() const{ 00074 return impl->getChildren(); 00075 } 00076 const utils::Point *begin() const{ 00077 return impl->begin(); 00078 } 00079 const utils::Point *end() const{ 00080 return impl->end(); 00081 } 00082 const int getSize() const{ 00083 return (int)(end() - begin()); 00084 } 00085 // draws the contour in the first channel of the given image 00086 void drawTo(core::ImgBase *img, const icl64f &value); 00087 }; 00088 00090 00112 class ICLCV_API ContourDetector : public utils::Uncopyable{ 00113 00115 struct Data; 00116 00118 Data *m_data; 00119 00120 public: 00121 00123 enum Algorithm{ 00124 Fast, 00125 Accurate, 00126 AccurateWithHierarchy 00127 }; 00128 00129 // contructor 00133 ContourDetector(const icl8u thresh=128, Algorithm a = Fast); 00134 00135 // destructor 00136 virtual ~ContourDetector(); 00137 00138 // draws all contours to the first channel of the given image with the given value 00139 void drawAllContours(core::ImgBase *img, const icl64f &value); 00140 00141 // calculates all contours (creates a deep copy/conversion to Img8u of the input image) 00142 const std::vector<Contour> &detect(const core::ImgBase *image); 00143 00144 // calculates all controus (alters the values of the input image) 00145 const std::vector<Contour> &detect(core::Img8u &image); 00146 00148 void setThreshold(const icl8u &threshold); 00149 00151 void setAlgorithm(Algorithm a); 00152 }; 00153 00154 } // namespace cv 00155 }