contour.h
Go to the documentation of this file.
1 
10 #ifndef CONTOUR_H
11 #define CONTOUR_H
12 
13 #include <vector>
14 #include <valarray>
15 
16 #include <opencv2/core/core.hpp>
17 
18 namespace tuw {
19 
20 
24 class Contour {
25 public:
26 
27  Contour();
28  ~Contour();
33  static const int ANGLE_8U;
38  static const int ANGLE_32F;
43  static const int ANGLE_64F;
44 
48  static const int MODE_SIMPLE;
52  static const int MODE_CONTOUR;
56  static const int MODE_GRAIDENT;
60  static const int MODE_COMPLEX;
61 
62 
63 
74  void Init ( unsigned int iImgWidth, unsigned int iImgHeight, bool bAllowToModifyTheSources = false, unsigned char iEdgeToProcess = 0xFF, unsigned char iEdgeInProcess = 0xFF-1, unsigned char iEdgeProcessed = 0xFF-2, unsigned char iEdgeStrengthRemoved = 0 );
89  void Perform ( unsigned char* pImgEdgeStrength, int defEdgeLinkMode = MODE_CONTOUR, void* pImgEdgeDirection = NULL, int defImgEdgeDirectionType = ANGLE_8U );
90 
95  void Draw( unsigned char* pImgRGB );
96 
102  unsigned int GetNrOfEdges() {
103  return mNrOfEdges;
104  };
105 
112  int GetEdgeListSplittedXY (std::vector<cv::Point_<int> > &rEdges, std::vector<unsigned char> **ppAngle8Bit = NULL);
113 
120  int getContours( std::vector<std::vector<cv::Point> > &contours, unsigned min_length = 0);
121 
126  std::vector<cv::Range> getSegmentIndexes();
127 
132  void GetAbnormitiesInEdgesImage ( IplImage *ptImgEdge, std::vector<CvPoint> *pAbnormities, uchar iEdgeStrength = 0 );
133 
134 private:
135  unsigned char *mpImgEdge;
142  unsigned char mEdgeToProcess;
143  unsigned char mEdgeInProcess;
144  unsigned char mEdgeProcessed;
145  static const int pppDirectionWeightsField[4][3][3];
146  static const int ppGradientWeightsField[4][9];
147  static const int pppCommingFromEdgeWeightsField[9][3][3];
148  static const int ppContourWeightsField[9][9];
149  static const float fPi;
150  static const double dPi;
151  //CvPoint *mpEdges;
152  std::vector<CvPoint> mEdges;
153  std::vector<unsigned char> mAngle8Bit;
154  unsigned int mNrOfEdges;
155  std::vector<cv::Range> mSegments;
156 
157  void AllocateMemory();
158  void RelaseMemory();
159  void Linking_Simple();
160  int GetImgDirectionIndex ( CvPoint tPoint );
161  void Trace_Simple ( CvPoint tPoint, int *pEnd );
162  void Linking_Complex();
163  void Trace_Complex ( CvPoint tPoint, int *pEnd, unsigned int iCommingFromEdge );
164  void Linking_Contour();
165  void Trace_Contour ( CvPoint tPoint, int *pEnd, unsigned int iCommingFromEdge );
166  void Linking_Gradient();
167  void Trace_Gradient ( CvPoint tPoint, int *pEnd );
168 
169  static const CvPoint GetNeighborPoint ( CvPoint pPtrCenter, int iNeighborIndex );
170  static const void SortArrayIndexes ( int *pArray, int *pIndexes, const int iSize );
171 
172 //Inlines
173  inline unsigned char* getImgEdge ( CvPoint tPoint ) {
174  return mpImgEdge + ( tPoint.y * mImgWidth + tPoint.x );
175  };
176  inline void SumArrayMatrix ( int *pMatrixA, int *pMatrixB, int *pSum, const int iSize ) {
177  for ( int i = 0; i < iSize; i++ ) pSum[i] = pMatrixA[i] + pMatrixB[i];
178  };
179  inline bool isInImage( const CvPoint &p){
180  return ( ( p.x > 0 ) && ( p.x < mImgWidth-1 ) && ( p.y > 0 ) && ( p.y < mImgHeight-1 ) );
181  }
182  inline void markNeighborEdgesAsProcessed(unsigned char *pPix){
183  pPix[ mImgWidth-1] = mEdgeProcessed;
184  pPix[ mImgWidth ] = mEdgeProcessed;
185  pPix[ mImgWidth+1] = mEdgeProcessed;
186  pPix[-1] = mEdgeProcessed;
187  pPix[ 1] = mEdgeProcessed;
188  pPix[-mImgWidth-1] = mEdgeProcessed;
189  pPix[-mImgWidth ] = mEdgeProcessed;
190  pPix[-mImgWidth+1] = mEdgeProcessed;
191  }
192 };
193 
194 }
195 
196 #endif //CONTOUR_H
197 // kate: indent-mode cstyle; space-indent on; indent-width 4;
int GetEdgeListSplittedXY(std::vector< cv::Point_< int > > &rEdges, std::vector< unsigned char > **ppAngle8Bit=NULL)
Returns number of edges and edges in the arguments.
Definition: contour.cpp:648
void Linking_Contour()
Definition: contour.cpp:401
static const float fPi
Definition: contour.h:149
int mImgWidth
Definition: contour.h:139
static const int pppDirectionWeightsField[4][3][3]
Definition: contour.h:145
void markNeighborEdgesAsProcessed(unsigned char *pPix)
Definition: contour.h:182
int GetImgDirectionIndex(CvPoint tPoint)
Definition: contour.cpp:193
static const CvPoint GetNeighborPoint(CvPoint pPtrCenter, int iNeighborIndex)
Definition: contour.cpp:607
void Trace_Simple(CvPoint tPoint, int *pEnd)
Definition: contour.cpp:323
std::vector< cv::Range > getSegmentIndexes()
the indexes of the contour segments
Definition: contour.cpp:752
void Perform(unsigned char *pImgEdgeStrength, int defEdgeLinkMode=MODE_CONTOUR, void *pImgEdgeDirection=NULL, int defImgEdgeDirectionType=ANGLE_8U)
Starts the edge linking with a certain mode.
Definition: contour.cpp:235
static const void SortArrayIndexes(int *pArray, int *pIndexes, const int iSize)
Definition: contour.cpp:660
std::vector< CvPoint > mEdges
Definition: contour.h:152
void Init(unsigned int iImgWidth, unsigned int iImgHeight, bool bAllowToModifyTheSources=false, unsigned char iEdgeToProcess=0xFF, unsigned char iEdgeInProcess=0xFF-1, unsigned char iEdgeProcessed=0xFF-2, unsigned char iEdgeStrengthRemoved=0)
Inititalized the class and reserves the momory needed.
Definition: contour.cpp:178
static const int ANGLE_32F
Static const variable used to define the source format of a gradient image as atan2(dy, dx) of the edge The format ANGLE_32F means values from -PI to +PI.
Definition: contour.h:38
unsigned char mEdgeInProcess
Definition: contour.h:143
static const int ppGradientWeightsField[4][9]
Definition: contour.h:146
static const int ANGLE_64F
Static const variable used to define the source format of a gradient image as atan2(dy, dx) of the edge The format ANGLE_64F means values from -PI to +PI.
Definition: contour.h:43
int mdefEdgeLinkMode
Definition: contour.h:138
std::vector< unsigned char > mAngle8Bit
Definition: contour.h:153
unsigned int mNrOfEdges
Definition: contour.h:154
int mdImgEdgeDirectionType
Definition: contour.h:137
int getContours(std::vector< std::vector< cv::Point > > &contours, unsigned min_length=0)
Returns the contour as vector of vector points.
Definition: contour.cpp:147
void GetAbnormitiesInEdgesImage(IplImage *ptImgEdge, std::vector< CvPoint > *pAbnormities, uchar iEdgeStrength=0)
Find egde contour Abnormities in edge image.
Definition: contour.cpp:680
void Trace_Contour(CvPoint tPoint, int *pEnd, unsigned int iCommingFromEdge)
Definition: contour.cpp:419
int mImgHeight
Definition: contour.h:140
static const int MODE_COMPLEX
Static const variable used to define the methode used to find the contour (linked edges) ...
Definition: contour.h:60
static const int pppCommingFromEdgeWeightsField[9][3][3]
Definition: contour.h:147
unsigned char mEdgeProcessed
Definition: contour.h:144
static const double dPi
Definition: contour.h:150
void Linking_Gradient()
Definition: contour.cpp:487
void Linking_Simple()
Definition: contour.cpp:271
unsigned char * getImgEdge(CvPoint tPoint)
Definition: contour.h:173
unsigned char * mpImgEdge
Definition: contour.h:135
unsigned int GetNrOfEdges()
Returns a number of edges used to linke edges to semgents.
Definition: contour.h:102
void RelaseMemory()
Definition: contour.cpp:132
void Trace_Complex(CvPoint tPoint, int *pEnd, unsigned int iCommingFromEdge)
Definition: contour.cpp:562
std::vector< cv::Range > mSegments
Definition: contour.h:155
void Draw(unsigned char *pImgRGB)
Draws the detected contours in a RGB image with radom colours.
Definition: contour.cpp:163
void * mpImgEdgeDirection
Definition: contour.h:136
static const int MODE_GRAIDENT
Static const variable used to define the methode used to find the contour (linked edges) ...
Definition: contour.h:56
void SumArrayMatrix(int *pMatrixA, int *pMatrixB, int *pSum, const int iSize)
Definition: contour.h:176
bool mbAllowToModifyTheSources
Definition: contour.h:141
static const int MODE_CONTOUR
Static const variable used to define the methode used to find the contour (linked edges) ...
Definition: contour.h:52
Class to link detected images edges a typical source can be a cvCanny image.
Definition: contour.h:24
void AllocateMemory()
Definition: contour.cpp:122
static const int ppContourWeightsField[9][9]
Definition: contour.h:148
bool isInImage(const CvPoint &p)
Definition: contour.h:179
void Trace_Gradient(CvPoint tPoint, int *pEnd)
Definition: contour.cpp:505
static const int MODE_SIMPLE
Static const variable used to define the methode used to find the contour (linked edges) ...
Definition: contour.h:48
unsigned char mEdgeToProcess
Definition: contour.h:142
void Linking_Complex()
Definition: contour.cpp:544
static const int ANGLE_8U
Static const variable used to define the source format of a gradient image as atan2(dy, dx) of the edge The format ANGLE_8U means zero rad are 0, +PI and -PI are 0x7F.
Definition: contour.h:33


tuw_ellipses
Author(s): Markus Bader
autogenerated on Mon Jun 10 2019 15:42:10