Project

General

Profile

Statistics
| Branch: | Revision:

root / vision / cvblobs8.3 / blob.h @ b11b2b30

History | View | Annotate | Download (4.26 KB)

1
/************************************************************************
2
                          Blob.h
3
                          
4
FUNCIONALITAT: Definici? de la classe CBlob
5
AUTOR: Inspecta S.L.
6
MODIFICACIONS (Modificaci?, Autor, Data):
7

8
FUNCTIONALITY: Definition of the CBlob class and some helper classes to perform
9
                           some calculations on it
10
AUTHOR: Inspecta S.L.
11
MODIFICATIONS (Modification, Author, Date):
12

13
**************************************************************************/
14

    
15
//! Disable warnings referred to 255 character truncation for the std:map
16
#pragma warning( disable : 4786 ) 
17

    
18
#ifndef CBLOB_INSPECTA_INCLUDED
19
#define CBLOB_INSPECTA_INCLUDED
20

    
21
#include <opencv/cxcore.h>
22
#include "BlobLibraryConfiguration.h"
23
#include "BlobContour.h"
24

    
25

    
26
#ifdef BLOB_OBJECT_FACTORY
27
        //! Object factory pattern implementation
28
        #include "..\inspecta\DesignPatterns\ObjectFactory.h"
29
#endif
30

    
31

    
32
//! Type of labelled images
33
typedef unsigned int t_labelType;
34

    
35

    
36
//! Blob class
37
class CBlob
38
{
39
        typedef std::list<CBlobContour> t_contourList;
40

    
41
public:
42
        CBlob();
43
        CBlob( t_labelType id, CvPoint startPoint, CvSize originalImageSize );
44
        ~CBlob();
45

    
46
        //! Copy constructor
47
        CBlob( const CBlob &src );
48
        CBlob( const CBlob *src );
49

    
50
        //! Operador d'assignaci?
51
        //! Assigment operator
52
        CBlob& operator=(const CBlob &src );
53
        
54
        //! Adds a new internal contour to the blob
55
        void AddInternalContour( const CBlobContour &newContour );
56
        
57
        //! Retrieves contour in Freeman's chain code
58
        CBlobContour *GetExternalContour()
59
        {
60
                return &m_externalContour;
61
        }
62

    
63
        //! Retrieves blob storage
64
        CvMemStorage *GetStorage()
65
        {
66
                return m_storage;
67
        }
68

    
69
        //! Get label ID
70
        t_labelType GetID()
71
        {
72
                return m_id;
73
        }
74
        //! > 0 for extern blobs, 0 if not
75
        int          Exterior( IplImage *mask, bool xBorder = true, bool yBorder = true );
76
        //! Compute blob's area
77
        double Area();
78
        //! Compute blob's perimeter
79
        double Perimeter();
80
        //! Compute blob's moment (p,q up to MAX_CALCULATED_MOMENTS)
81
        double Moment(int p, int q);
82

    
83
        //! Compute extern perimeter 
84
        double ExternPerimeter( IplImage *mask, bool xBorder  = true, bool yBorder = true );
85
        
86
        //! Get mean grey color
87
        double Mean( IplImage *image );
88

    
89
        //! Get standard deviation grey color
90
        double StdDev( IplImage *image );
91

    
92
        //! Indica si el blob est? buit ( no t? cap info associada )
93
        //! Shows if the blob has associated information
94
        bool IsEmpty();
95

    
96
        //! Retorna el poligon convex del blob
97
        //! Calculates the convex hull of the blob
98
        t_PointList GetConvexHull();
99

    
100
        //! Pinta l'interior d'un blob d'un color determinat
101
        //! Paints the blob in an image
102
        void FillBlob( IplImage *imatge, CvScalar color, int offsetX = 0, int offsetY = 0 );
103

    
104
        //! Join a blob to current one (add's contour
105
        void JoinBlob( CBlob *blob );
106

    
107
        //! Get bounding box
108
        CvRect GetBoundingBox();
109
        //! Get bounding ellipse
110
        CvBox2D GetEllipse();
111

    
112
        //! Minimun X        
113
        double MinX()
114
        {
115
                return GetBoundingBox().x;
116
        }
117
        //! Minimun Y
118
        double MinY()
119
        {
120
                return GetBoundingBox().y;
121
        }
122
        //! Maximun X
123
        double MaxX()
124
        {
125
                return GetBoundingBox().x + GetBoundingBox().width;
126
        }
127
        //! Maximun Y
128
        double MaxY()
129
        {
130
                return GetBoundingBox().y + GetBoundingBox().height;
131
        }
132
private:
133
        
134
        //! Deallocates all contours
135
        void ClearContours();
136
        //////////////////////////////////////////////////////////////////////////
137
        // Blob contours
138
        //////////////////////////////////////////////////////////////////////////
139

    
140

    
141
        //! Contour storage memory
142
        CvMemStorage *m_storage;
143
        //! External contour of the blob (crack codes)
144
        CBlobContour m_externalContour;
145
        //! Internal contours (crack codes)
146
        t_contourList m_internalContours;
147

    
148
        //////////////////////////////////////////////////////////////////////////
149
        // Blob features
150
        //////////////////////////////////////////////////////////////////////////
151
        
152
        //! Label number
153
        t_labelType m_id;
154
        //! Area
155
        double m_area;
156
        //! Perimeter
157
        double m_perimeter;
158
        //! Extern perimeter from blob
159
        double m_externPerimeter;
160
        //! Mean gray color
161
        double m_meanGray;
162
        //! Standard deviation from gray color blob distribution
163
        double m_stdDevGray;
164
        //! Bounding box
165
        CvRect m_boundingBox;
166
        //! Bounding ellipse
167
        CvBox2D m_ellipse;
168
        //! Sizes from image where blob is extracted
169
        CvSize m_originalImageSize;
170
};
171

    
172
#endif //CBLOB_INSPECTA_INCLUDED