HClassKnn.h 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  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_HCLASSKNN
  8. #define HCPP_HCLASSKNN
  9. namespace HalconCpp
  10. {
  11. // Represents an instance of a k-NearestNeighbor classifier.
  12. class LIntExport HClassKnn : public HHandle
  13. {
  14. public:
  15. // Create an uninitialized instance
  16. HClassKnn():HHandle() {}
  17. // Copy constructor
  18. HClassKnn(const HClassKnn& source) : HHandle(source) {}
  19. // Copy constructor
  20. HClassKnn(const HHandle& handle);
  21. // Create HClassKnn from handle, taking ownership
  22. explicit HClassKnn(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_knn')!
  33. virtual void AssertType(Hphandle handle) const;
  34. public:
  35. // Deep copy of all data represented by this object instance
  36. HClassKnn Clone() const;
  37. /*****************************************************************************
  38. * Operator-based class constructors
  39. *****************************************************************************/
  40. // read_class_knn: Read the k-NN classifier from a file.
  41. explicit HClassKnn(const HString& FileName);
  42. // read_class_knn: Read the k-NN classifier from a file.
  43. explicit HClassKnn(const char* FileName);
  44. #ifdef _WIN32
  45. // read_class_knn: Read the k-NN classifier from a file.
  46. explicit HClassKnn(const wchar_t* FileName);
  47. #endif
  48. // create_class_knn: Create a k-nearest neighbors (k-NN) classifier.
  49. explicit HClassKnn(const HTuple& NumDim);
  50. /***************************************************************************
  51. * Operators *
  52. ***************************************************************************/
  53. // Classify an image with a k-Nearest-Neighbor classifier.
  54. HRegion ClassifyImageClassKnn(const HImage& Image, HImage* DistanceImage, double RejectionThreshold) const;
  55. // Add training samples from an image to the training data of a k-Nearest-Neighbor classifier.
  56. void AddSamplesImageClassKnn(const HImage& Image, const HRegion& ClassRegions) const;
  57. // Get the training data of a k-nearest neighbors (k-NN) classifier.
  58. HClassTrainData GetClassTrainDataKnn() const;
  59. // Add training data to a k-nearest neighbors (k-NN) classifier.
  60. void AddClassTrainDataKnn(const HClassTrainData& ClassTrainDataHandle) const;
  61. // Selects an optimal subset from a set of features to solve a certain classification problem.
  62. HTuple SelectFeatureSetKnn(const HClassTrainData& ClassTrainDataHandle, const HString& SelectionMethod, const HTuple& GenParamName, const HTuple& GenParamValue, HTuple* Score);
  63. // Selects an optimal subset from a set of features to solve a certain classification problem.
  64. HTuple SelectFeatureSetKnn(const HClassTrainData& ClassTrainDataHandle, const HString& SelectionMethod, const HString& GenParamName, double GenParamValue, HTuple* Score);
  65. // Selects an optimal subset from a set of features to solve a certain classification problem.
  66. HTuple SelectFeatureSetKnn(const HClassTrainData& ClassTrainDataHandle, const char* SelectionMethod, const char* GenParamName, double GenParamValue, HTuple* Score);
  67. #ifdef _WIN32
  68. // Selects an optimal subset from a set of features to solve a certain classification problem.
  69. HTuple SelectFeatureSetKnn(const HClassTrainData& ClassTrainDataHandle, const wchar_t* SelectionMethod, const wchar_t* GenParamName, double GenParamValue, HTuple* Score);
  70. #endif
  71. // Clear a k-NN classifier.
  72. void ClearClassKnn() const;
  73. // Return the number of training samples stored in the training data of a k-nearest neighbors (k-NN) classifier.
  74. Hlong GetSampleNumClassKnn() const;
  75. // Return a training sample from the training data of a k-nearest neighbors (k-NN) classifier.
  76. HTuple GetSampleClassKnn(Hlong IndexSample, HTuple* ClassID) const;
  77. // Deserialize a serialized k-NN classifier.
  78. void DeserializeClassKnn(const HSerializedItem& SerializedItemHandle);
  79. // Serialize a k-NN classifier.
  80. HSerializedItem SerializeClassKnn() const;
  81. // Read the k-NN classifier from a file.
  82. void ReadClassKnn(const HString& FileName);
  83. // Read the k-NN classifier from a file.
  84. void ReadClassKnn(const char* FileName);
  85. #ifdef _WIN32
  86. // Read the k-NN classifier from a file.
  87. void ReadClassKnn(const wchar_t* FileName);
  88. #endif
  89. // Save the k-NN classifier in a file.
  90. void WriteClassKnn(const HString& FileName) const;
  91. // Save the k-NN classifier in a file.
  92. void WriteClassKnn(const char* FileName) const;
  93. #ifdef _WIN32
  94. // Save the k-NN classifier in a file.
  95. void WriteClassKnn(const wchar_t* FileName) const;
  96. #endif
  97. // Get parameters of a k-NN classification.
  98. HTuple GetParamsClassKnn(const HTuple& GenParamName) const;
  99. // Set parameters for k-NN classification.
  100. void SetParamsClassKnn(const HTuple& GenParamName, const HTuple& GenParamValue) const;
  101. // Search for the next neighbors for a given feature vector.
  102. HTuple ClassifyClassKnn(const HTuple& Features, HTuple* Rating) const;
  103. // Creates the search trees for a k-NN classifier.
  104. void TrainClassKnn(const HTuple& GenParamName, const HTuple& GenParamValue) const;
  105. // Add a sample to a k-nearest neighbors (k-NN) classifier.
  106. void AddSampleClassKnn(const HTuple& Features, const HTuple& ClassID) const;
  107. // Add a sample to a k-nearest neighbors (k-NN) classifier.
  108. void AddSampleClassKnn(double Features, Hlong ClassID) const;
  109. // Create a k-nearest neighbors (k-NN) classifier.
  110. void CreateClassKnn(const HTuple& NumDim);
  111. // Create a look-up table using a k-nearest neighbors classifier (k-NN) to classify byte images.
  112. HClassLUT CreateClassLutKnn(const HTuple& GenParamName, const HTuple& GenParamValue) const;
  113. };
  114. // forward declarations and types for internal array implementation
  115. template<class T> class HSmartPtr;
  116. template<class T> class HHandleBaseArrayRef;
  117. typedef HHandleBaseArrayRef<HClassKnn> HClassKnnArrayRef;
  118. typedef HSmartPtr< HClassKnnArrayRef > HClassKnnArrayPtr;
  119. // Represents multiple tool instances
  120. class LIntExport HClassKnnArray : public HHandleBaseArray
  121. {
  122. public:
  123. // Create empty array
  124. HClassKnnArray();
  125. // Create array from native array of tool instances
  126. HClassKnnArray(HClassKnn* classes, Hlong length);
  127. // Copy constructor
  128. HClassKnnArray(const HClassKnnArray &tool_array);
  129. // Destructor
  130. virtual ~HClassKnnArray();
  131. // Assignment operator
  132. HClassKnnArray &operator=(const HClassKnnArray &tool_array);
  133. // Clears array and all tool instances
  134. virtual void Clear();
  135. // Get array of native tool instances
  136. const HClassKnn* Tools() const;
  137. // Get number of tools
  138. virtual Hlong Length() const;
  139. // Create tool array from tuple of handles
  140. virtual void SetFromTuple(const HTuple& handles);
  141. // Get tuple of handles for tool array
  142. virtual HTuple ConvertToTuple() const;
  143. protected:
  144. // Smart pointer to internal data container
  145. HClassKnnArrayPtr *mArrayPtr;
  146. };
  147. }
  148. #endif