You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

174 lines
5.3 KiB

8 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /************************************************************************
  2. BlobResult.h
  3. FUNCIONALITAT: Definici� de la classe CBlobResult
  4. AUTOR: Inspecta S.L.
  5. MODIFICACIONS (Modificaci�, Autor, Data):
  6. FUNCTIONALITY: Definition of the CBlobResult class
  7. AUTHOR: Inspecta S.L.
  8. MODIFICATIONS (Modification, Author, Date):
  9. **************************************************************************/
  10. #if !defined(_CLASSE_BLOBRESULT_INCLUDED)
  11. #define _CLASSE_BLOBRESULT_INCLUDED
  12. #if _MSC_VER > 1000
  13. #pragma once
  14. #endif // _MSC_VER > 1000
  15. #include "BlobLibraryConfiguration.h"
  16. #ifndef M_E
  17. #include <math.h>
  18. #endif
  19. #include <opencv/cv.h>
  20. #ifdef MATRIXCV_ACTIU
  21. #include "matrixCV.h"
  22. #else
  23. // llibreria STL
  24. #include <vector>
  25. //! Vector de doubles
  26. typedef std::vector<float> double_stl_vector;
  27. #endif
  28. #include <vector> // vectors de la STL
  29. #include <functional>
  30. #include "blob.h"
  31. #include "BlobOperators.h"
  32. #include "ComponentLabeling.h"
  33. /**************************************************************************
  34. Filtres / Filters
  35. **************************************************************************/
  36. //! accions que es poden fer amb els filtres
  37. //! Actions performed by a filter (include or exclude blobs)
  38. #define B_INCLUDE 1L
  39. #define B_EXCLUDE 2L
  40. //! condicions sobre els filtres
  41. //! Conditions to apply the filters
  42. #define B_EQUAL 3L
  43. #define B_NOT_EQUAL 4L
  44. #define B_GREATER 5L
  45. #define B_LESS 6L
  46. #define B_GREATER_OR_EQUAL 7L
  47. #define B_LESS_OR_EQUAL 8L
  48. #define B_INSIDE 9L
  49. #define B_OUTSIDE 10L
  50. /**************************************************************************
  51. Excepcions / Exceptions
  52. **************************************************************************/
  53. //! Excepcions llen�ades per les funcions:
  54. #define EXCEPTION_BLOB_OUT_OF_BOUNDS 1000
  55. #define EXCEPCIO_CALCUL_BLOBS 1001
  56. /**
  57. Classe que cont� un conjunt de blobs i permet extreure'n propietats
  58. o filtrar-los segons determinats criteris.
  59. Class to calculate the blobs of an image and calculate some properties
  60. on them. Also, the class provides functions to filter the blobs using
  61. some criteria.
  62. */
  63. class CBlobResult
  64. {
  65. public:
  66. //! constructor estandard, crea un conjunt buit de blobs
  67. //! Standard constructor, it creates an empty set of blobs
  68. CBlobResult();
  69. //! constructor a partir d'una imatge
  70. //! Image constructor, it creates an object with the blobs of the image
  71. CBlobResult(IplImage *source, IplImage *mask, uchar backgroundColor);
  72. //! constructor de c�pia
  73. //! Copy constructor
  74. CBlobResult( const CBlobResult &source );
  75. //! Destructor
  76. virtual ~CBlobResult();
  77. //! operador = per a fer assignacions entre CBlobResult
  78. //! Assigment operator
  79. CBlobResult& operator=(const CBlobResult& source);
  80. //! operador + per concatenar dos CBlobResult
  81. //! Addition operator to concatenate two sets of blobs
  82. CBlobResult operator+( const CBlobResult& source ) const;
  83. //! Afegeix un blob al conjunt
  84. //! Adds a blob to the set of blobs
  85. void AddBlob( BlobPtr blob );
  86. #ifdef MATRIXCV_ACTIU
  87. //! Calcula un valor sobre tots els blobs de la classe retornant una MatrixCV
  88. //! Computes some property on all the blobs of the class
  89. double_vector GetResult( funcio_calculBlob *evaluador ) const;
  90. #endif
  91. //! Calcula un valor sobre tots els blobs de la classe retornant un std::vector<float>
  92. //! Computes some property on all the blobs of the class
  93. double_stl_vector GetSTLResult( funcio_calculBlob *evaluador ) const;
  94. //! Calcula un valor sobre un blob de la classe
  95. //! Computes some property on one blob of the class
  96. float GetNumber( int indexblob, funcio_calculBlob *evaluador ) const;
  97. //! Retorna aquells blobs que compleixen les condicions del filtre en el destination
  98. //! Filters the blobs of the class using some property
  99. void Filter(CBlobResult &dst,
  100. int filterAction, funcio_calculBlob *evaluador,
  101. int condition, float lowLimit, float highLimit = 0 );
  102. //! Retorna l'en�ssim blob segons un determinat criteri
  103. //! Sorts the blobs of the class acording to some criteria and returns the n-th blob
  104. void GetNthBlob( funcio_calculBlob *criteri, int nBlob, CBlob &dst ) const;
  105. //! Retorna el blob en�ssim
  106. //! Gets the n-th blob of the class ( without sorting )
  107. CBlob GetBlob(int indexblob) const;
  108. BlobPtr GetBlobPtr(int indexblob);
  109. //! Elimina tots els blobs de l'objecte
  110. //! Clears all the blobs of the class
  111. void ClearBlobs();
  112. //! Escriu els blobs a un fitxer
  113. //! Prints some features of all the blobs in a file
  114. void PrintBlobs( char *nom_fitxer ) const;
  115. //Metodes GET/SET
  116. //! Retorna el total de blobs
  117. //! Gets the total number of blobs
  118. int GetNumBlobs() const
  119. {
  120. return(m_blobs.size());
  121. }
  122. //! Clears a calculated property from blobs
  123. void RemoveProperty( const std::string &name );
  124. private:
  125. //! Funci� per gestionar els errors
  126. //! Function to manage the errors
  127. void RaiseError(const int errorCode) const;
  128. //! Does the Filter method job
  129. void DoFilter(CBlobResult &dst,
  130. int filterAction, funcio_calculBlob *evaluador,
  131. int condition, bool inlineFilter, float lowLimit, float highLimit = 0);
  132. protected:
  133. //! Vector amb els blobs
  134. //! Vector with all the blobs
  135. Blob_vector m_blobs;
  136. };
  137. #endif // !defined(_CLASSE_BLOBRESULT_INCLUDED)