HClassGmm.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  1. /***********************************************************
  2. * File generated by the HALCON-Compiler hcomp version 20.11
  3. * Usage: Interface to C++
  4. *
  5. * Software by: MVTec Software GmbH, www.mvtec.com
  6. ***********************************************************/
  7. #ifndef HCPP_HCLASSGMM
  8. #define HCPP_HCLASSGMM
  9. namespace HalconCpp
  10. {
  11. // Represents an instance of a Gaussian mixture model.
  12. class LIntExport HClassGmm : public HHandle
  13. {
  14. public:
  15. // Create an uninitialized instance
  16. HClassGmm():HHandle() {}
  17. // Copy constructor
  18. HClassGmm(const HClassGmm& source) : HHandle(source) {}
  19. // Copy constructor
  20. HClassGmm(const HHandle& handle);
  21. // Create HClassGmm from handle, taking ownership
  22. explicit HClassGmm(Hlong handle);
  23. bool operator==(const HHandle& obj) const
  24. {
  25. return HHandleBase::operator==(obj);
  26. }
  27. bool operator!=(const HHandle& obj) const
  28. {
  29. return HHandleBase::operator!=(obj);
  30. }
  31. protected:
  32. // Verify matching semantic type ('class_gmm')!
  33. virtual void AssertType(Hphandle handle) const;
  34. public:
  35. // Deep copy of all data represented by this object instance
  36. HClassGmm Clone() const;
  37. /*****************************************************************************
  38. * Operator-based class constructors
  39. *****************************************************************************/
  40. // read_class_gmm: Read a Gaussian Mixture Model from a file.
  41. explicit HClassGmm(const HString& FileName);
  42. // read_class_gmm: Read a Gaussian Mixture Model from a file.
  43. explicit HClassGmm(const char* FileName);
  44. #ifdef _WIN32
  45. // read_class_gmm: Read a Gaussian Mixture Model from a file.
  46. explicit HClassGmm(const wchar_t* FileName);
  47. #endif
  48. // create_class_gmm: Create a Gaussian Mixture Model for classification
  49. explicit HClassGmm(Hlong NumDim, Hlong NumClasses, const HTuple& NumCenters, const HString& CovarType, const HString& Preprocessing, Hlong NumComponents, Hlong RandSeed);
  50. // create_class_gmm: Create a Gaussian Mixture Model for classification
  51. explicit HClassGmm(Hlong NumDim, Hlong NumClasses, Hlong NumCenters, const HString& CovarType, const HString& Preprocessing, Hlong NumComponents, Hlong RandSeed);
  52. // create_class_gmm: Create a Gaussian Mixture Model for classification
  53. explicit HClassGmm(Hlong NumDim, Hlong NumClasses, Hlong NumCenters, const char* CovarType, const char* Preprocessing, Hlong NumComponents, Hlong RandSeed);
  54. #ifdef _WIN32
  55. // create_class_gmm: Create a Gaussian Mixture Model for classification
  56. explicit HClassGmm(Hlong NumDim, Hlong NumClasses, Hlong NumCenters, const wchar_t* CovarType, const wchar_t* Preprocessing, Hlong NumComponents, Hlong RandSeed);
  57. #endif
  58. /***************************************************************************
  59. * Operators *
  60. ***************************************************************************/
  61. // Classify an image with a Gaussian Mixture Model.
  62. HRegion ClassifyImageClassGmm(const HImage& Image, double RejectionThreshold) const;
  63. // Add training samples from an image to the training data of a Gaussian Mixture Model.
  64. void AddSamplesImageClassGmm(const HImage& Image, const HRegion& ClassRegions, double Randomize) const;
  65. // Get the training data of a Gaussian Mixture Model (GMM).
  66. HClassTrainData GetClassTrainDataGmm() const;
  67. // Add training data to a Gaussian Mixture Model (GMM).
  68. void AddClassTrainDataGmm(const HClassTrainData& ClassTrainDataHandle) const;
  69. // Selects an optimal combination from a set of features to classify the provided data.
  70. HTuple SelectFeatureSetGmm(const HClassTrainData& ClassTrainDataHandle, const HString& SelectionMethod, const HTuple& GenParamName, const HTuple& GenParamValue, HTuple* Score);
  71. // Selects an optimal combination from a set of features to classify the provided data.
  72. HTuple SelectFeatureSetGmm(const HClassTrainData& ClassTrainDataHandle, const HString& SelectionMethod, const HString& GenParamName, double GenParamValue, HTuple* Score);
  73. // Selects an optimal combination from a set of features to classify the provided data.
  74. HTuple SelectFeatureSetGmm(const HClassTrainData& ClassTrainDataHandle, const char* SelectionMethod, const char* GenParamName, double GenParamValue, HTuple* Score);
  75. #ifdef _WIN32
  76. // Selects an optimal combination from a set of features to classify the provided data.
  77. HTuple SelectFeatureSetGmm(const HClassTrainData& ClassTrainDataHandle, const wchar_t* SelectionMethod, const wchar_t* GenParamName, double GenParamValue, HTuple* Score);
  78. #endif
  79. // Create a look-up table using a gaussian mixture model to classify byte images.
  80. HClassLUT CreateClassLutGmm(const HTuple& GenParamName, const HTuple& GenParamValue) const;
  81. // Clear a Gaussian Mixture Model.
  82. static void ClearClassGmm(const HClassGmmArray& GMMHandle);
  83. // Clear a Gaussian Mixture Model.
  84. void ClearClassGmm() const;
  85. // Clear the training data of a Gaussian Mixture Model.
  86. static void ClearSamplesClassGmm(const HClassGmmArray& GMMHandle);
  87. // Clear the training data of a Gaussian Mixture Model.
  88. void ClearSamplesClassGmm() const;
  89. // Deserialize a serialized Gaussian Mixture Model.
  90. void DeserializeClassGmm(const HSerializedItem& SerializedItemHandle);
  91. // Serialize a Gaussian Mixture Model (GMM).
  92. HSerializedItem SerializeClassGmm() const;
  93. // Read a Gaussian Mixture Model from a file.
  94. void ReadClassGmm(const HString& FileName);
  95. // Read a Gaussian Mixture Model from a file.
  96. void ReadClassGmm(const char* FileName);
  97. #ifdef _WIN32
  98. // Read a Gaussian Mixture Model from a file.
  99. void ReadClassGmm(const wchar_t* FileName);
  100. #endif
  101. // Write a Gaussian Mixture Model to a file.
  102. void WriteClassGmm(const HString& FileName) const;
  103. // Write a Gaussian Mixture Model to a file.
  104. void WriteClassGmm(const char* FileName) const;
  105. #ifdef _WIN32
  106. // Write a Gaussian Mixture Model to a file.
  107. void WriteClassGmm(const wchar_t* FileName) const;
  108. #endif
  109. // Read the training data of a Gaussian Mixture Model from a file.
  110. void ReadSamplesClassGmm(const HString& FileName) const;
  111. // Read the training data of a Gaussian Mixture Model from a file.
  112. void ReadSamplesClassGmm(const char* FileName) const;
  113. #ifdef _WIN32
  114. // Read the training data of a Gaussian Mixture Model from a file.
  115. void ReadSamplesClassGmm(const wchar_t* FileName) const;
  116. #endif
  117. // Write the training data of a Gaussian Mixture Model to a file.
  118. void WriteSamplesClassGmm(const HString& FileName) const;
  119. // Write the training data of a Gaussian Mixture Model to a file.
  120. void WriteSamplesClassGmm(const char* FileName) const;
  121. #ifdef _WIN32
  122. // Write the training data of a Gaussian Mixture Model to a file.
  123. void WriteSamplesClassGmm(const wchar_t* FileName) const;
  124. #endif
  125. // Calculate the class of a feature vector by a Gaussian Mixture Model.
  126. HTuple ClassifyClassGmm(const HTuple& Features, Hlong Num, HTuple* ClassProb, HTuple* Density, HTuple* KSigmaProb) const;
  127. // Evaluate a feature vector by a Gaussian Mixture Model.
  128. HTuple EvaluateClassGmm(const HTuple& Features, double* Density, double* KSigmaProb) const;
  129. // Train a Gaussian Mixture Model.
  130. HTuple TrainClassGmm(Hlong MaxIter, double Threshold, const HString& ClassPriors, double Regularize, HTuple* Iter) const;
  131. // Train a Gaussian Mixture Model.
  132. HTuple TrainClassGmm(Hlong MaxIter, double Threshold, const char* ClassPriors, double Regularize, HTuple* Iter) const;
  133. #ifdef _WIN32
  134. // Train a Gaussian Mixture Model.
  135. HTuple TrainClassGmm(Hlong MaxIter, double Threshold, const wchar_t* ClassPriors, double Regularize, HTuple* Iter) const;
  136. #endif
  137. // Compute the information content of the preprocessed feature vectors of a GMM.
  138. HTuple GetPrepInfoClassGmm(const HString& Preprocessing, HTuple* CumInformationCont) const;
  139. // Compute the information content of the preprocessed feature vectors of a GMM.
  140. HTuple GetPrepInfoClassGmm(const char* Preprocessing, HTuple* CumInformationCont) const;
  141. #ifdef _WIN32
  142. // Compute the information content of the preprocessed feature vectors of a GMM.
  143. HTuple GetPrepInfoClassGmm(const wchar_t* Preprocessing, HTuple* CumInformationCont) const;
  144. #endif
  145. // Return the number of training samples stored in the training data of a Gaussian Mixture Model (GMM).
  146. Hlong GetSampleNumClassGmm() const;
  147. // Return a training sample from the training data of a Gaussian Mixture Models (GMM).
  148. HTuple GetSampleClassGmm(Hlong NumSample, Hlong* ClassID) const;
  149. // Add a training sample to the training data of a Gaussian Mixture Model.
  150. void AddSampleClassGmm(const HTuple& Features, Hlong ClassID, double Randomize) const;
  151. // Return the parameters of a Gaussian Mixture Model.
  152. Hlong GetParamsClassGmm(Hlong* NumClasses, HTuple* MinCenters, HTuple* MaxCenters, HString* CovarType) const;
  153. // Create a Gaussian Mixture Model for classification
  154. void CreateClassGmm(Hlong NumDim, Hlong NumClasses, const HTuple& NumCenters, const HString& CovarType, const HString& Preprocessing, Hlong NumComponents, Hlong RandSeed);
  155. // Create a Gaussian Mixture Model for classification
  156. void CreateClassGmm(Hlong NumDim, Hlong NumClasses, Hlong NumCenters, const HString& CovarType, const HString& Preprocessing, Hlong NumComponents, Hlong RandSeed);
  157. // Create a Gaussian Mixture Model for classification
  158. void CreateClassGmm(Hlong NumDim, Hlong NumClasses, Hlong NumCenters, const char* CovarType, const char* Preprocessing, Hlong NumComponents, Hlong RandSeed);
  159. #ifdef _WIN32
  160. // Create a Gaussian Mixture Model for classification
  161. void CreateClassGmm(Hlong NumDim, Hlong NumClasses, Hlong NumCenters, const wchar_t* CovarType, const wchar_t* Preprocessing, Hlong NumComponents, Hlong RandSeed);
  162. #endif
  163. };
  164. // forward declarations and types for internal array implementation
  165. template<class T> class HSmartPtr;
  166. template<class T> class HHandleBaseArrayRef;
  167. typedef HHandleBaseArrayRef<HClassGmm> HClassGmmArrayRef;
  168. typedef HSmartPtr< HClassGmmArrayRef > HClassGmmArrayPtr;
  169. // Represents multiple tool instances
  170. class LIntExport HClassGmmArray : public HHandleBaseArray
  171. {
  172. public:
  173. // Create empty array
  174. HClassGmmArray();
  175. // Create array from native array of tool instances
  176. HClassGmmArray(HClassGmm* classes, Hlong length);
  177. // Copy constructor
  178. HClassGmmArray(const HClassGmmArray &tool_array);
  179. // Destructor
  180. virtual ~HClassGmmArray();
  181. // Assignment operator
  182. HClassGmmArray &operator=(const HClassGmmArray &tool_array);
  183. // Clears array and all tool instances
  184. virtual void Clear();
  185. // Get array of native tool instances
  186. const HClassGmm* Tools() const;
  187. // Get number of tools
  188. virtual Hlong Length() const;
  189. // Create tool array from tuple of handles
  190. virtual void SetFromTuple(const HTuple& handles);
  191. // Get tuple of handles for tool array
  192. virtual HTuple ConvertToTuple() const;
  193. protected:
  194. // Smart pointer to internal data container
  195. HClassGmmArrayPtr *mArrayPtr;
  196. };
  197. }
  198. #endif