KNearest.cs 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  1. 
  2. using OpenCVForUnity.CoreModule;
  3. using OpenCVForUnity.UtilsModule;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Runtime.InteropServices;
  7. namespace OpenCVForUnity.MlModule {
  8. // C++: class KNearest
  9. //javadoc: KNearest
  10. public class KNearest : StatModel {
  11. protected override void Dispose(bool disposing) {
  12. #if (UNITY_ANDROID && !UNITY_EDITOR)
  13. try {
  14. if (disposing) {
  15. }
  16. if (IsEnabledDispose) {
  17. if (nativeObj != IntPtr.Zero)
  18. ml_KNearest_delete(nativeObj);
  19. nativeObj = IntPtr.Zero;
  20. }
  21. } finally {
  22. base.Dispose(disposing);
  23. }
  24. #else
  25. return;
  26. #endif
  27. }
  28. protected internal KNearest(IntPtr addr) : base(addr) { }
  29. // internal usage only
  30. public static new KNearest __fromPtr__(IntPtr addr) { return new KNearest(addr); }
  31. // C++: enum Types
  32. public const int BRUTE_FORCE = 1;
  33. public const int KDTREE = 2;
  34. //
  35. // C++: static Ptr_KNearest cv::ml::KNearest::create()
  36. //
  37. //javadoc: KNearest::create()
  38. public static KNearest create() {
  39. #if (UNITY_ANDROID && !UNITY_EDITOR)
  40. KNearest retVal = KNearest.__fromPtr__(ml_KNearest_create_10());
  41. return retVal;
  42. #else
  43. return null;
  44. #endif
  45. }
  46. //
  47. // C++: bool cv::ml::KNearest::getIsClassifier()
  48. //
  49. //javadoc: KNearest::getIsClassifier()
  50. public bool getIsClassifier() {
  51. ThrowIfDisposed();
  52. #if (UNITY_ANDROID && !UNITY_EDITOR)
  53. bool retVal = ml_KNearest_getIsClassifier_10(nativeObj);
  54. return retVal;
  55. #else
  56. return false;
  57. #endif
  58. }
  59. //
  60. // C++: float cv::ml::KNearest::findNearest(Mat samples, int k, Mat& results, Mat& neighborResponses = Mat(), Mat& dist = Mat())
  61. //
  62. //javadoc: KNearest::findNearest(samples, k, results, neighborResponses, dist)
  63. public float findNearest(Mat samples, int k, Mat results, Mat neighborResponses, Mat dist) {
  64. ThrowIfDisposed();
  65. if (samples != null) samples.ThrowIfDisposed();
  66. if (results != null) results.ThrowIfDisposed();
  67. if (neighborResponses != null) neighborResponses.ThrowIfDisposed();
  68. if (dist != null) dist.ThrowIfDisposed();
  69. #if (UNITY_ANDROID && !UNITY_EDITOR)
  70. float retVal = ml_KNearest_findNearest_10(nativeObj, samples.nativeObj, k, results.nativeObj, neighborResponses.nativeObj, dist.nativeObj);
  71. return retVal;
  72. #else
  73. return -1;
  74. #endif
  75. }
  76. //javadoc: KNearest::findNearest(samples, k, results, neighborResponses)
  77. public float findNearest(Mat samples, int k, Mat results, Mat neighborResponses) {
  78. ThrowIfDisposed();
  79. if (samples != null) samples.ThrowIfDisposed();
  80. if (results != null) results.ThrowIfDisposed();
  81. if (neighborResponses != null) neighborResponses.ThrowIfDisposed();
  82. #if (UNITY_ANDROID && !UNITY_EDITOR)
  83. float retVal = ml_KNearest_findNearest_11(nativeObj, samples.nativeObj, k, results.nativeObj, neighborResponses.nativeObj);
  84. return retVal;
  85. #else
  86. return -1;
  87. #endif
  88. }
  89. //javadoc: KNearest::findNearest(samples, k, results)
  90. public float findNearest(Mat samples, int k, Mat results) {
  91. ThrowIfDisposed();
  92. if (samples != null) samples.ThrowIfDisposed();
  93. if (results != null) results.ThrowIfDisposed();
  94. #if (UNITY_ANDROID && !UNITY_EDITOR)
  95. float retVal = ml_KNearest_findNearest_12(nativeObj, samples.nativeObj, k, results.nativeObj);
  96. return retVal;
  97. #else
  98. return -1;
  99. #endif
  100. }
  101. //
  102. // C++: int cv::ml::KNearest::getAlgorithmType()
  103. //
  104. //javadoc: KNearest::getAlgorithmType()
  105. public int getAlgorithmType() {
  106. ThrowIfDisposed();
  107. #if (UNITY_ANDROID && !UNITY_EDITOR)
  108. int retVal = ml_KNearest_getAlgorithmType_10(nativeObj);
  109. return retVal;
  110. #else
  111. return -1;
  112. #endif
  113. }
  114. //
  115. // C++: int cv::ml::KNearest::getDefaultK()
  116. //
  117. //javadoc: KNearest::getDefaultK()
  118. public int getDefaultK() {
  119. ThrowIfDisposed();
  120. #if (UNITY_ANDROID && !UNITY_EDITOR)
  121. int retVal = ml_KNearest_getDefaultK_10(nativeObj);
  122. return retVal;
  123. #else
  124. return -1;
  125. #endif
  126. }
  127. //
  128. // C++: int cv::ml::KNearest::getEmax()
  129. //
  130. //javadoc: KNearest::getEmax()
  131. public int getEmax() {
  132. ThrowIfDisposed();
  133. #if (UNITY_ANDROID && !UNITY_EDITOR)
  134. int retVal = ml_KNearest_getEmax_10(nativeObj);
  135. return retVal;
  136. #else
  137. return -1;
  138. #endif
  139. }
  140. //
  141. // C++: void cv::ml::KNearest::setAlgorithmType(int val)
  142. //
  143. //javadoc: KNearest::setAlgorithmType(val)
  144. public void setAlgorithmType(int val) {
  145. ThrowIfDisposed();
  146. #if (UNITY_ANDROID && !UNITY_EDITOR)
  147. ml_KNearest_setAlgorithmType_10(nativeObj, val);
  148. return;
  149. #else
  150. return;
  151. #endif
  152. }
  153. //
  154. // C++: void cv::ml::KNearest::setDefaultK(int val)
  155. //
  156. //javadoc: KNearest::setDefaultK(val)
  157. public void setDefaultK(int val) {
  158. ThrowIfDisposed();
  159. #if (UNITY_ANDROID && !UNITY_EDITOR)
  160. ml_KNearest_setDefaultK_10(nativeObj, val);
  161. return;
  162. #else
  163. return;
  164. #endif
  165. }
  166. //
  167. // C++: void cv::ml::KNearest::setEmax(int val)
  168. //
  169. //javadoc: KNearest::setEmax(val)
  170. public void setEmax(int val) {
  171. ThrowIfDisposed();
  172. #if (UNITY_ANDROID && !UNITY_EDITOR)
  173. ml_KNearest_setEmax_10(nativeObj, val);
  174. return;
  175. #else
  176. return;
  177. #endif
  178. }
  179. //
  180. // C++: void cv::ml::KNearest::setIsClassifier(bool val)
  181. //
  182. //javadoc: KNearest::setIsClassifier(val)
  183. public void setIsClassifier(bool val) {
  184. ThrowIfDisposed();
  185. #if (UNITY_ANDROID && !UNITY_EDITOR)
  186. ml_KNearest_setIsClassifier_10(nativeObj, val);
  187. return;
  188. #else
  189. return;
  190. #endif
  191. }
  192. #if (UNITY_ANDROID && !UNITY_EDITOR)
  193. const string LIBNAME = "opencvforunity";
  194. // C++: static Ptr_KNearest cv::ml::KNearest::create()
  195. [DllImport(LIBNAME)]
  196. private static extern IntPtr ml_KNearest_create_10();
  197. // C++: bool cv::ml::KNearest::getIsClassifier()
  198. [DllImport(LIBNAME)]
  199. private static extern bool ml_KNearest_getIsClassifier_10(IntPtr nativeObj);
  200. // C++: float cv::ml::KNearest::findNearest(Mat samples, int k, Mat& results, Mat& neighborResponses = Mat(), Mat& dist = Mat())
  201. [DllImport(LIBNAME)]
  202. private static extern float ml_KNearest_findNearest_10(IntPtr nativeObj, IntPtr samples_nativeObj, int k, IntPtr results_nativeObj, IntPtr neighborResponses_nativeObj, IntPtr dist_nativeObj);
  203. [DllImport(LIBNAME)]
  204. private static extern float ml_KNearest_findNearest_11(IntPtr nativeObj, IntPtr samples_nativeObj, int k, IntPtr results_nativeObj, IntPtr neighborResponses_nativeObj);
  205. [DllImport(LIBNAME)]
  206. private static extern float ml_KNearest_findNearest_12(IntPtr nativeObj, IntPtr samples_nativeObj, int k, IntPtr results_nativeObj);
  207. // C++: int cv::ml::KNearest::getAlgorithmType()
  208. [DllImport(LIBNAME)]
  209. private static extern int ml_KNearest_getAlgorithmType_10(IntPtr nativeObj);
  210. // C++: int cv::ml::KNearest::getDefaultK()
  211. [DllImport(LIBNAME)]
  212. private static extern int ml_KNearest_getDefaultK_10(IntPtr nativeObj);
  213. // C++: int cv::ml::KNearest::getEmax()
  214. [DllImport(LIBNAME)]
  215. private static extern int ml_KNearest_getEmax_10(IntPtr nativeObj);
  216. // C++: void cv::ml::KNearest::setAlgorithmType(int val)
  217. [DllImport(LIBNAME)]
  218. private static extern void ml_KNearest_setAlgorithmType_10(IntPtr nativeObj, int val);
  219. // C++: void cv::ml::KNearest::setDefaultK(int val)
  220. [DllImport(LIBNAME)]
  221. private static extern void ml_KNearest_setDefaultK_10(IntPtr nativeObj, int val);
  222. // C++: void cv::ml::KNearest::setEmax(int val)
  223. [DllImport(LIBNAME)]
  224. private static extern void ml_KNearest_setEmax_10(IntPtr nativeObj, int val);
  225. // C++: void cv::ml::KNearest::setIsClassifier(bool val)
  226. [DllImport(LIBNAME)]
  227. private static extern void ml_KNearest_setIsClassifier_10(IntPtr nativeObj, bool val);
  228. // native support for java finalize()
  229. [DllImport(LIBNAME)]
  230. private static extern void ml_KNearest_delete(IntPtr nativeObj);
  231. #endif
  232. }
  233. }