/ENB355Linux/Blob.h

https://bitbucket.org/rako/enb355linux · C Header · 172 lines · 78 code · 31 blank · 63 comment · 0 complexity · 7c194ff14fd2f6abe8ee2d273c23f615 MD5 · raw file

  1. /************************************************************************
  2. Blob.h
  3. FUNCIONALITAT: Definició de la classe CBlob
  4. AUTOR: Inspecta S.L.
  5. MODIFICACIONS (Modificació, Autor, Data):
  6. FUNCTIONALITY: Definition of the CBlob class and some helper classes to perform
  7. some calculations on it
  8. AUTHOR: Inspecta S.L.
  9. MODIFICATIONS (Modification, Author, Date):
  10. **************************************************************************/
  11. //! Disable warnings referred to 255 character truncation for the std:map
  12. #pragma warning( disable : 4786 )
  13. #ifndef CBLOB_INSPECTA_INCLUDED
  14. #define CBLOB_INSPECTA_INCLUDED
  15. #include "cxcore.h"
  16. #include "BlobLibraryConfiguration.h"
  17. #include "BlobContour.h"
  18. #ifdef BLOB_OBJECT_FACTORY
  19. //! Object factory pattern implementation
  20. #include "..\inspecta\DesignPatterns\ObjectFactory.h"
  21. #endif
  22. //! Type of labelled images
  23. typedef unsigned int t_labelType;
  24. //! Blob class
  25. class CBlob
  26. {
  27. typedef std::list<CBlobContour> t_contourList;
  28. public:
  29. CBlob();
  30. CBlob( t_labelType id, CvPoint startPoint, CvSize originalImageSize );
  31. ~CBlob();
  32. //! Copy constructor
  33. CBlob( const CBlob &src );
  34. CBlob( const CBlob *src );
  35. //! Operador d'assignació
  36. //! Assigment operator
  37. CBlob& operator=(const CBlob &src );
  38. //! Adds a new internal contour to the blob
  39. void AddInternalContour( const CBlobContour &newContour );
  40. //! Retrieves contour in Freeman's chain code
  41. CBlobContour *GetExternalContour()
  42. {
  43. return &m_externalContour;
  44. }
  45. //! Retrieves blob storage
  46. CvMemStorage *GetStorage()
  47. {
  48. return m_storage;
  49. }
  50. //! Get label ID
  51. t_labelType GetID()
  52. {
  53. return m_id;
  54. }
  55. //! > 0 for extern blobs, 0 if not
  56. int Exterior( IplImage *mask, bool xBorder = true, bool yBorder = true );
  57. //! Compute blob's area
  58. double Area();
  59. //! Compute blob's perimeter
  60. double Perimeter();
  61. //! Compute blob's moment (p,q up to MAX_CALCULATED_MOMENTS)
  62. double Moment(int p, int q);
  63. //! Compute extern perimeter
  64. double ExternPerimeter( IplImage *mask, bool xBorder = true, bool yBorder = true );
  65. //! Get mean grey color
  66. double Mean( IplImage *image );
  67. //! Get standard deviation grey color
  68. double StdDev( IplImage *image );
  69. //! Indica si el blob està buit ( no té cap info associada )
  70. //! Shows if the blob has associated information
  71. bool IsEmpty();
  72. //! Retorna el poligon convex del blob
  73. //! Calculates the convex hull of the blob
  74. t_PointList GetConvexHull();
  75. //! Pinta l'interior d'un blob d'un color determinat
  76. //! Paints the blob in an image
  77. void FillBlob( IplImage *imatge, CvScalar color, int offsetX = 0, int offsetY = 0 );
  78. //! Join a blob to current one (add's contour
  79. void JoinBlob( CBlob *blob );
  80. //! Get bounding box
  81. CvRect GetBoundingBox();
  82. //! Get bounding ellipse
  83. CvBox2D GetEllipse();
  84. //! Minimun X
  85. double MinX()
  86. {
  87. return GetBoundingBox().x;
  88. }
  89. //! Minimun Y
  90. double MinY()
  91. {
  92. return GetBoundingBox().y;
  93. }
  94. //! Maximun X
  95. double MaxX()
  96. {
  97. return GetBoundingBox().x + GetBoundingBox().width;
  98. }
  99. //! Maximun Y
  100. double MaxY()
  101. {
  102. return GetBoundingBox().y + GetBoundingBox().height;
  103. }
  104. private:
  105. //! Deallocates all contours
  106. void ClearContours();
  107. //////////////////////////////////////////////////////////////////////////
  108. // Blob contours
  109. //////////////////////////////////////////////////////////////////////////
  110. //! Contour storage memory
  111. CvMemStorage *m_storage;
  112. //! External contour of the blob (crack codes)
  113. CBlobContour m_externalContour;
  114. //! Internal contours (crack codes)
  115. t_contourList m_internalContours;
  116. //////////////////////////////////////////////////////////////////////////
  117. // Blob features
  118. //////////////////////////////////////////////////////////////////////////
  119. //! Label number
  120. t_labelType m_id;
  121. //! Area
  122. double m_area;
  123. //! Perimeter
  124. double m_perimeter;
  125. //! Extern perimeter from blob
  126. double m_externPerimeter;
  127. //! Mean gray color
  128. double m_meanGray;
  129. //! Standard deviation from gray color blob distribution
  130. double m_stdDevGray;
  131. //! Bounding box
  132. CvRect m_boundingBox;
  133. //! Bounding ellipse
  134. CvBox2D m_ellipse;
  135. //! Sizes from image where blob is extracted
  136. CvSize m_originalImageSize;
  137. };
  138. #endif //CBLOB_INSPECTA_INCLUDED