KNearest.cs 9.7 KB

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