source: libs/magicsquares/applications/harvest/src/Blob.h @ 998

Revision 998, 4.2 KB checked in by dave, 10 years ago (diff)

select spirit, opencv updated to fix camera

Line 
1/************************************************************************
2                        Blob.h
3                       
4FUNCIONALITAT: Definició de la classe CBlob
5AUTOR: Inspecta S.L.
6MODIFICACIONS (Modificació, Autor, Data):
7
8FUNCTIONALITY: Definition of the CBlob class and some helper classes to perform
9                           some calculations on it
10AUTHOR: Inspecta S.L.
11MODIFICATIONS (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 "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
33typedef unsigned int t_labelType;
34
35typedef std::list<CBlobContour> t_contourList;
36
37//! Blob class
38class CBlob
39{
40public:
41        CBlob();
42        CBlob( t_labelType id, CvPoint startPoint, CvSize originalImageSize );
43        ~CBlob();
44
45        //! Copy constructor
46        CBlob( const CBlob &src );
47        CBlob( const CBlob *src );
48
49        //! Operador d'assignació
50        //! Assigment operator
51        CBlob& operator=(const CBlob &src );
52       
53        //! Adds a new internal contour to the blob
54        void AddInternalContour( const CBlobContour &newContour );
55       
56        //! Retrieves contour in Freeman's chain code
57        CBlobContour *GetExternalContour()
58        {
59                return &m_externalContour;
60        }
61
62        //! Retrieves blob storage
63        CvMemStorage *GetStorage()
64        {
65                return m_storage;
66        }
67
68        //! Get label ID
69        t_labelType GetID()
70        {
71                return m_id;
72        }
73        //! > 0 for extern blobs, 0 if not
74        int       Exterior( IplImage *mask, bool xBorder = true, bool yBorder = true );
75        //! Compute blob's area
76        double Area();
77        //! Compute blob's perimeter
78        double Perimeter();
79        //! Compute blob's moment (p,q up to MAX_CALCULATED_MOMENTS)
80        double Moment(int p, int q);
81
82        //! Compute extern perimeter
83        double ExternPerimeter( IplImage *mask, bool xBorder  = true, bool yBorder = true );
84       
85        //! Get mean grey color
86        double Mean( IplImage *image );
87
88        //! Get standard deviation grey color
89        double StdDev( IplImage *image );
90
91        //! Indica si el blob està buit ( no té cap info associada )
92        //! Shows if the blob has associated information
93        bool IsEmpty();
94
95        //! Retorna el poligon convex del blob
96        //! Calculates the convex hull of the blob
97        t_PointList GetConvexHull();
98
99        //! Pinta l'interior d'un blob d'un color determinat
100        //! Paints the blob in an image
101        void FillBlob( IplImage *imatge, CvScalar color, int offsetX = 0, int offsetY = 0 );
102
103        //! Join a blob to current one (add's contour
104        void JoinBlob( CBlob *blob );
105
106        //! Get bounding box
107        CvRect GetBoundingBox();
108        //! Get bounding ellipse
109        CvBox2D GetEllipse();
110
111        //! Minimun X   
112        double MinX()
113        {
114                return GetBoundingBox().x;
115        }
116        //! Minimun Y
117        double MinY()
118        {
119                return GetBoundingBox().y;
120        }
121        //! Maximun X
122        double MaxX()
123        {
124                return GetBoundingBox().x + GetBoundingBox().width;
125        }
126        //! Maximun Y
127        double MaxY()
128        {
129                return GetBoundingBox().y + GetBoundingBox().height;
130        }
131private:
132       
133        //! Deallocates all contours
134        void ClearContours();
135        //////////////////////////////////////////////////////////////////////////
136        // Blob contours
137        //////////////////////////////////////////////////////////////////////////
138
139
140        //! Contour storage memory
141        CvMemStorage *m_storage;
142        //! External contour of the blob (crack codes)
143        CBlobContour m_externalContour;
144        //! Internal contours (crack codes)
145        t_contourList m_internalContours;
146
147        //////////////////////////////////////////////////////////////////////////
148        // Blob features
149        //////////////////////////////////////////////////////////////////////////
150       
151        //! Label number
152        t_labelType m_id;
153        //! Area
154        double m_area;
155        //! Perimeter
156        double m_perimeter;
157        //! Extern perimeter from blob
158        double m_externPerimeter;
159        //! Mean gray color
160        double m_meanGray;
161        //! Standard deviation from gray color blob distribution
162        double m_stdDevGray;
163        //! Bounding box
164        CvRect m_boundingBox;
165        //! Bounding ellipse
166        CvBox2D m_ellipse;
167        //! Sizes from image where blob is extracted
168        CvSize m_originalImageSize;
169};
170
171#endif //CBLOB_INSPECTA_INCLUDED
Note: See TracBrowser for help on using the repository browser.