HClassSvm.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  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_HCLASSSVM
  8. #define HCPP_HCLASSSVM
  9. namespace HalconCpp
  10. {
  11. // Represents an instance of a support vector machine.
  12. class LIntExport HClassSvm : public HHandle
  13. {
  14. public:
  15. // Create an uninitialized instance
  16. HClassSvm():HHandle() {}
  17. // Copy constructor
  18. HClassSvm(const HClassSvm& source) : HHandle(source) {}
  19. // Copy constructor
  20. HClassSvm(const HHandle& handle);
  21. // Create HClassSvm from handle, taking ownership
  22. explicit HClassSvm(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_svm')!
  33. virtual void AssertType(Hphandle handle) const;
  34. public:
  35. // Deep copy of all data represented by this object instance
  36. HClassSvm Clone() const;
  37. /*****************************************************************************
  38. * Operator-based class constructors
  39. *****************************************************************************/
  40. // read_class_svm: Read a support vector machine from a file.
  41. explicit HClassSvm(const HString& FileName);
  42. // read_class_svm: Read a support vector machine from a file.
  43. explicit HClassSvm(const char* FileName);
  44. #ifdef _WIN32
  45. // read_class_svm: Read a support vector machine from a file.
  46. explicit HClassSvm(const wchar_t* FileName);
  47. #endif
  48. // create_class_svm: Create a support vector machine for pattern classification.
  49. explicit HClassSvm(Hlong NumFeatures, const HString& KernelType, double KernelParam, double Nu, Hlong NumClasses, const HString& Mode, const HString& Preprocessing, Hlong NumComponents);
  50. // create_class_svm: Create a support vector machine for pattern classification.
  51. explicit HClassSvm(Hlong NumFeatures, const char* KernelType, double KernelParam, double Nu, Hlong NumClasses, const char* Mode, const char* Preprocessing, Hlong NumComponents);
  52. #ifdef _WIN32
  53. // create_class_svm: Create a support vector machine for pattern classification.
  54. explicit HClassSvm(Hlong NumFeatures, const wchar_t* KernelType, double KernelParam, double Nu, Hlong NumClasses, const wchar_t* Mode, const wchar_t* Preprocessing, Hlong NumComponents);
  55. #endif
  56. /***************************************************************************
  57. * Operators *
  58. ***************************************************************************/
  59. // Classify an image with a support vector machine.
  60. HRegion ClassifyImageClassSvm(const HImage& Image) const;
  61. // Add training samples from an image to the training data of a support vector machine.
  62. void AddSamplesImageClassSvm(const HImage& Image, const HRegion& ClassRegions) const;
  63. // Get the training data of a support vector machine (SVM).
  64. HClassTrainData GetClassTrainDataSvm() const;
  65. // Add training data to a support vector machine (SVM).
  66. void AddClassTrainDataSvm(const HClassTrainData& ClassTrainDataHandle) const;
  67. // Selects an optimal combination of features to classify the provided data.
  68. HTuple SelectFeatureSetSvm(const HClassTrainData& ClassTrainDataHandle, const HString& SelectionMethod, const HTuple& GenParamName, const HTuple& GenParamValue, HTuple* Score);
  69. // Selects an optimal combination of features to classify the provided data.
  70. HTuple SelectFeatureSetSvm(const HClassTrainData& ClassTrainDataHandle, const HString& SelectionMethod, const HString& GenParamName, double GenParamValue, HTuple* Score);
  71. // Selects an optimal combination of features to classify the provided data.
  72. HTuple SelectFeatureSetSvm(const HClassTrainData& ClassTrainDataHandle, const char* SelectionMethod, const char* GenParamName, double GenParamValue, HTuple* Score);
  73. #ifdef _WIN32
  74. // Selects an optimal combination of features to classify the provided data.
  75. HTuple SelectFeatureSetSvm(const HClassTrainData& ClassTrainDataHandle, const wchar_t* SelectionMethod, const wchar_t* GenParamName, double GenParamValue, HTuple* Score);
  76. #endif
  77. // Create a look-up table using a Support-Vector-Machine to classify byte images.
  78. HClassLUT CreateClassLutSvm(const HTuple& GenParamName, const HTuple& GenParamValue) const;
  79. // Clear a support vector machine.
  80. static void ClearClassSvm(const HClassSvmArray& SVMHandle);
  81. // Clear a support vector machine.
  82. void ClearClassSvm() const;
  83. // Clear the training data of a support vector machine.
  84. static void ClearSamplesClassSvm(const HClassSvmArray& SVMHandle);
  85. // Clear the training data of a support vector machine.
  86. void ClearSamplesClassSvm() const;
  87. // Deserialize a serialized support vector machine (SVM).
  88. void DeserializeClassSvm(const HSerializedItem& SerializedItemHandle);
  89. // Serialize a support vector machine (SVM).
  90. HSerializedItem SerializeClassSvm() const;
  91. // Read a support vector machine from a file.
  92. void ReadClassSvm(const HString& FileName);
  93. // Read a support vector machine from a file.
  94. void ReadClassSvm(const char* FileName);
  95. #ifdef _WIN32
  96. // Read a support vector machine from a file.
  97. void ReadClassSvm(const wchar_t* FileName);
  98. #endif
  99. // Write a support vector machine to a file.
  100. void WriteClassSvm(const HString& FileName) const;
  101. // Write a support vector machine to a file.
  102. void WriteClassSvm(const char* FileName) const;
  103. #ifdef _WIN32
  104. // Write a support vector machine to a file.
  105. void WriteClassSvm(const wchar_t* FileName) const;
  106. #endif
  107. // Read the training data of a support vector machine from a file.
  108. void ReadSamplesClassSvm(const HString& FileName) const;
  109. // Read the training data of a support vector machine from a file.
  110. void ReadSamplesClassSvm(const char* FileName) const;
  111. #ifdef _WIN32
  112. // Read the training data of a support vector machine from a file.
  113. void ReadSamplesClassSvm(const wchar_t* FileName) const;
  114. #endif
  115. // Write the training data of a support vector machine to a file.
  116. void WriteSamplesClassSvm(const HString& FileName) const;
  117. // Write the training data of a support vector machine to a file.
  118. void WriteSamplesClassSvm(const char* FileName) const;
  119. #ifdef _WIN32
  120. // Write the training data of a support vector machine to a file.
  121. void WriteSamplesClassSvm(const wchar_t* FileName) const;
  122. #endif
  123. // Evaluate a feature vector by a support vector machine.
  124. HTuple EvaluateClassSvm(const HTuple& Features) const;
  125. // Classify a feature vector by a support vector machine.
  126. HTuple ClassifyClassSvm(const HTuple& Features, const HTuple& Num) const;
  127. // Approximate a trained support vector machine by a reduced support vector machine for faster classification.
  128. HClassSvm ReduceClassSvm(const HString& Method, Hlong MinRemainingSV, double MaxError) const;
  129. // Approximate a trained support vector machine by a reduced support vector machine for faster classification.
  130. HClassSvm ReduceClassSvm(const char* Method, Hlong MinRemainingSV, double MaxError) const;
  131. #ifdef _WIN32
  132. // Approximate a trained support vector machine by a reduced support vector machine for faster classification.
  133. HClassSvm ReduceClassSvm(const wchar_t* Method, Hlong MinRemainingSV, double MaxError) const;
  134. #endif
  135. // Train a support vector machine.
  136. void TrainClassSvm(double Epsilon, const HTuple& TrainMode) const;
  137. // Train a support vector machine.
  138. void TrainClassSvm(double Epsilon, const HString& TrainMode) const;
  139. // Train a support vector machine.
  140. void TrainClassSvm(double Epsilon, const char* TrainMode) const;
  141. #ifdef _WIN32
  142. // Train a support vector machine.
  143. void TrainClassSvm(double Epsilon, const wchar_t* TrainMode) const;
  144. #endif
  145. // Compute the information content of the preprocessed feature vectors of a support vector machine
  146. HTuple GetPrepInfoClassSvm(const HString& Preprocessing, HTuple* CumInformationCont) const;
  147. // Compute the information content of the preprocessed feature vectors of a support vector machine
  148. HTuple GetPrepInfoClassSvm(const char* Preprocessing, HTuple* CumInformationCont) const;
  149. #ifdef _WIN32
  150. // Compute the information content of the preprocessed feature vectors of a support vector machine
  151. HTuple GetPrepInfoClassSvm(const wchar_t* Preprocessing, HTuple* CumInformationCont) const;
  152. #endif
  153. // Return the number of support vectors of a support vector machine.
  154. Hlong GetSupportVectorNumClassSvm(HTuple* NumSVPerSVM) const;
  155. // Return the index of a support vector from a trained support vector machine.
  156. double GetSupportVectorClassSvm(Hlong IndexSupportVector) const;
  157. // Return the number of training samples stored in the training data of a support vector machine.
  158. Hlong GetSampleNumClassSvm() const;
  159. // Return a training sample from the training data of a support vector machine.
  160. HTuple GetSampleClassSvm(Hlong IndexSample, Hlong* Target) const;
  161. // Add a training sample to the training data of a support vector machine.
  162. void AddSampleClassSvm(const HTuple& Features, const HTuple& Class) const;
  163. // Add a training sample to the training data of a support vector machine.
  164. void AddSampleClassSvm(const HTuple& Features, Hlong Class) const;
  165. // Return the parameters of a support vector machine.
  166. Hlong GetParamsClassSvm(HString* KernelType, double* KernelParam, double* Nu, Hlong* NumClasses, HString* Mode, HString* Preprocessing, Hlong* NumComponents) const;
  167. // Create a support vector machine for pattern classification.
  168. void CreateClassSvm(Hlong NumFeatures, const HString& KernelType, double KernelParam, double Nu, Hlong NumClasses, const HString& Mode, const HString& Preprocessing, Hlong NumComponents);
  169. // Create a support vector machine for pattern classification.
  170. void CreateClassSvm(Hlong NumFeatures, const char* KernelType, double KernelParam, double Nu, Hlong NumClasses, const char* Mode, const char* Preprocessing, Hlong NumComponents);
  171. #ifdef _WIN32
  172. // Create a support vector machine for pattern classification.
  173. void CreateClassSvm(Hlong NumFeatures, const wchar_t* KernelType, double KernelParam, double Nu, Hlong NumClasses, const wchar_t* Mode, const wchar_t* Preprocessing, Hlong NumComponents);
  174. #endif
  175. };
  176. // forward declarations and types for internal array implementation
  177. template<class T> class HSmartPtr;
  178. template<class T> class HHandleBaseArrayRef;
  179. typedef HHandleBaseArrayRef<HClassSvm> HClassSvmArrayRef;
  180. typedef HSmartPtr< HClassSvmArrayRef > HClassSvmArrayPtr;
  181. // Represents multiple tool instances
  182. class LIntExport HClassSvmArray : public HHandleBaseArray
  183. {
  184. public:
  185. // Create empty array
  186. HClassSvmArray();
  187. // Create array from native array of tool instances
  188. HClassSvmArray(HClassSvm* classes, Hlong length);
  189. // Copy constructor
  190. HClassSvmArray(const HClassSvmArray &tool_array);
  191. // Destructor
  192. virtual ~HClassSvmArray();
  193. // Assignment operator
  194. HClassSvmArray &operator=(const HClassSvmArray &tool_array);
  195. // Clears array and all tool instances
  196. virtual void Clear();
  197. // Get array of native tool instances
  198. const HClassSvm* Tools() const;
  199. // Get number of tools
  200. virtual Hlong Length() const;
  201. // Create tool array from tuple of handles
  202. virtual void SetFromTuple(const HTuple& handles);
  203. // Get tuple of handles for tool array
  204. virtual HTuple ConvertToTuple() const;
  205. protected:
  206. // Smart pointer to internal data container
  207. HClassSvmArrayPtr *mArrayPtr;
  208. };
  209. }
  210. #endif