Image Component Library (ICL)
ContourDetector.h
Go to the documentation of this file.
1 /********************************************************************
2 ** Image Component Library (ICL) **
3 ** **
4 ** Copyright (C) 2006-2013 CITEC, University of Bielefeld **
5 ** Neuroinformatics Group **
6 ** Website: www.iclcv.org and **
7 ** http://opensource.cit-ec.de/projects/icl **
8 ** **
9 ** File : ICLCV/src/ICLCV/ContourDetector.h **
10 ** Module : ICLCV **
11 ** Authors: Sergius Gaulik, Christof Elbrechter **
12 ** **
13 ** **
14 ** GNU LESSER GENERAL PUBLIC LICENSE **
15 ** This file may be used under the terms of the GNU Lesser General **
16 ** Public License version 3.0 as published by the **
17 ** **
18 ** Free Software Foundation and appearing in the file LICENSE.LGPL **
19 ** included in the packaging of this file. Please review the **
20 ** following information to ensure the license requirements will **
21 ** be met: http://www.gnu.org/licenses/lgpl-3.0.txt **
22 ** **
23 ** The development of this software was supported by the **
24 ** Excellence Cluster EXC 277 Cognitive Interaction Technology. **
25 ** The Excellence Cluster EXC 277 is a grant of the Deutsche **
26 ** Forschungsgemeinschaft (DFG) in the context of the German **
27 ** Excellence Initiative. **
28 ** **
29 ********************************************************************/
30 
31 #pragma once
32 
33 #include <ICLUtils/CompatMacros.h>
34 #include <ICLUtils/Uncopyable.h>
35 #include <ICLCore/Img.h>
36 
37 #include <vector>
38 
39 namespace icl{
40  namespace cv{
41 
42  struct ContourImpl{
43  virtual bool hasHierarchy() const = 0;
44  virtual int getID() const = 0;
45  virtual bool isHole() const = 0;
46  virtual const std::vector<int> &getChildren() const = 0;
47  virtual const utils::Point *begin() const = 0;
48  virtual const utils::Point *end() const = 0;
49  };
50 
54 
55  public:
56  Contour(ContourImpl *impl = 0):impl(impl){}
57 
58  inline bool isNull() const {
59  return !impl;
60  }
61  inline operator bool() const {
62  return !!impl;
63  }
64  inline bool hasHierarchy() const{
65  return impl->hasHierarchy();
66  }
67  inline int getID() const {
68  return impl->getID();
69  }
70  bool isHole() const{
71  return impl->isHole();
72  }
73  const std::vector<int> &getChildren() const{
74  return impl->getChildren();
75  }
76  const utils::Point *begin() const{
77  return impl->begin();
78  }
79  const utils::Point *end() const{
80  return impl->end();
81  }
82  const int getSize() const{
83  return (int)(end() - begin());
84  }
85  // draws the contour in the first channel of the given image
86  void drawTo(core::ImgBase *img, const icl64f &value);
87  };
88 
90 
113 
115  struct Data;
116 
118  Data *m_data;
119 
120  public:
121 
123  enum Algorithm{
126  AccurateWithHierarchy
127  };
128 
129  // contructor
133  ContourDetector(const icl8u thresh=128, Algorithm a = Fast);
134 
135  // destructor
136  virtual ~ContourDetector();
137 
138  // draws all contours to the first channel of the given image with the given value
139  void drawAllContours(core::ImgBase *img, const icl64f &value);
140 
141  // calculates all contours (creates a deep copy/conversion to Img8u of the input image)
142  const std::vector<Contour> &detect(const core::ImgBase *image);
143 
144  // calculates all controus (alters the values of the input image)
145  const std::vector<Contour> &detect(core::Img8u &image);
146 
148  void setThreshold(const icl8u &threshold);
149 
151  void setAlgorithm(Algorithm a);
152  };
153 
154  } // namespace cv
155 }
accurate contour detection algorithm (using 8-point neighborhood)
Definition: ContourDetector.h:125
undocument this line if you encounter any issues!
Definition: Any.h:37
Class interface for un-copyable classes.
Definition: Uncopyable.h:64
The ContourDetector extracts all contours of a given image.
Definition: ContourDetector.h:112
Ipp8u icl8u
8Bit unsigned integer type for the ICL
Definition: BasicTypes.h:64
Data * m_data
internal data pointer
Definition: ContourDetector.h:115
virtual const utils::Point * end() const =0
int getID() const
Definition: ContourDetector.h:67
const utils::Point * end() const
Definition: ContourDetector.h:79
const int getSize() const
Definition: ContourDetector.h:82
Algorithm
contour tracing algorithm used
Definition: ContourDetector.h:123
const std::vector< int > & getChildren() const
Definition: ContourDetector.h:73
virtual bool isHole() const =0
const utils::Point * begin() const
Definition: ContourDetector.h:76
virtual const utils::Point * begin() const =0
#define ICLCV_API
Definition: CompatMacros.h:177
Utility class used by the ContourDetector.
Definition: ContourDetector.h:52
Ipp64f icl64f
64Bit floating point type for the ICL
Definition: BasicTypes.h:52
fast contour detection algorithm (using 4-point neighbourhood)
Definition: ContourDetector.h:124
ICLQt_API ImgQ thresh(const ImgQ &image, float threshold)
performs an image binarisation for each channel with given threshold
ContourImpl * impl
Definition: ContourDetector.h:53
virtual const std::vector< int > & getChildren() const =0
bool isHole() const
Definition: ContourDetector.h:70
Point class of the ICL used e.g. for the Images ROI offset.
Definition: Point.h:58
bool isNull() const
Definition: ContourDetector.h:58
Definition: ContourDetector.h:42
bool hasHierarchy() const
Definition: ContourDetector.h:64
ImgBase is the Image-Interface class that provides save access to underlying Img-template .
Definition: ImgBase.h:131
virtual int getID() const =0
virtual bool hasHierarchy() const =0
Contour(ContourImpl *impl=0)
Definition: ContourDetector.h:56