StatModel.cs 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  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 StatModel
  10. //javadoc: StatModel
  11. public class StatModel : Algorithm
  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_StatModel_delete (nativeObj);
  22. nativeObj = IntPtr.Zero;
  23. }
  24. } finally {
  25. base.Dispose (disposing);
  26. }
  27. #else
  28. return;
  29. #endif
  30. }
  31. protected internal StatModel (IntPtr addr)
  32. : base (addr)
  33. {
  34. }
  35. // internal usage only
  36. public static new StatModel __fromPtr__ (IntPtr addr)
  37. {
  38. return new StatModel (addr);
  39. }
  40. // C++: enum Flags
  41. public const int UPDATE_MODEL = 1;
  42. public const int RAW_OUTPUT = 1;
  43. public const int COMPRESSED_INPUT = 2;
  44. public const int PREPROCESSED_INPUT = 4;
  45. //
  46. // C++: bool cv::ml::StatModel::empty()
  47. //
  48. //javadoc: StatModel::empty()
  49. public override bool empty ()
  50. {
  51. ThrowIfDisposed ();
  52. #if ((UNITY_ANDROID || UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR) || UNITY_5 || UNITY_5_3_OR_NEWER
  53. bool retVal = ml_StatModel_empty_10 (nativeObj);
  54. return retVal;
  55. #else
  56. return false;
  57. #endif
  58. }
  59. //
  60. // C++: bool cv::ml::StatModel::isClassifier()
  61. //
  62. //javadoc: StatModel::isClassifier()
  63. public bool isClassifier ()
  64. {
  65. ThrowIfDisposed ();
  66. #if ((UNITY_ANDROID || UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR) || UNITY_5 || UNITY_5_3_OR_NEWER
  67. bool retVal = ml_StatModel_isClassifier_10 (nativeObj);
  68. return retVal;
  69. #else
  70. return false;
  71. #endif
  72. }
  73. //
  74. // C++: bool cv::ml::StatModel::isTrained()
  75. //
  76. //javadoc: StatModel::isTrained()
  77. public bool isTrained ()
  78. {
  79. ThrowIfDisposed ();
  80. #if ((UNITY_ANDROID || UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR) || UNITY_5 || UNITY_5_3_OR_NEWER
  81. bool retVal = ml_StatModel_isTrained_10 (nativeObj);
  82. return retVal;
  83. #else
  84. return false;
  85. #endif
  86. }
  87. //
  88. // C++: bool cv::ml::StatModel::train(Mat samples, int layout, Mat responses)
  89. //
  90. //javadoc: StatModel::train(samples, layout, responses)
  91. public bool train (Mat samples, int layout, Mat responses)
  92. {
  93. ThrowIfDisposed ();
  94. if (samples != null)
  95. samples.ThrowIfDisposed ();
  96. if (responses != null)
  97. responses.ThrowIfDisposed ();
  98. #if ((UNITY_ANDROID || UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR) || UNITY_5 || UNITY_5_3_OR_NEWER
  99. bool retVal = ml_StatModel_train_10 (nativeObj, samples.nativeObj, layout, responses.nativeObj);
  100. return retVal;
  101. #else
  102. return false;
  103. #endif
  104. }
  105. //
  106. // C++: bool cv::ml::StatModel::train(Ptr_TrainData trainData, int flags = 0)
  107. //
  108. //javadoc: StatModel::train(trainData, flags)
  109. public bool train (TrainData trainData, int flags)
  110. {
  111. ThrowIfDisposed ();
  112. if (trainData != null)
  113. trainData.ThrowIfDisposed ();
  114. #if ((UNITY_ANDROID || UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR) || UNITY_5 || UNITY_5_3_OR_NEWER
  115. bool retVal = ml_StatModel_train_11 (nativeObj, trainData.getNativeObjAddr (), flags);
  116. return retVal;
  117. #else
  118. return false;
  119. #endif
  120. }
  121. //javadoc: StatModel::train(trainData)
  122. public bool train (TrainData trainData)
  123. {
  124. ThrowIfDisposed ();
  125. if (trainData != null)
  126. trainData.ThrowIfDisposed ();
  127. #if ((UNITY_ANDROID || UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR) || UNITY_5 || UNITY_5_3_OR_NEWER
  128. bool retVal = ml_StatModel_train_12 (nativeObj, trainData.getNativeObjAddr ());
  129. return retVal;
  130. #else
  131. return false;
  132. #endif
  133. }
  134. //
  135. // C++: float cv::ml::StatModel::calcError(Ptr_TrainData data, bool test, Mat& resp)
  136. //
  137. //javadoc: StatModel::calcError(data, test, resp)
  138. public float calcError (TrainData data, bool test, Mat resp)
  139. {
  140. ThrowIfDisposed ();
  141. if (data != null)
  142. data.ThrowIfDisposed ();
  143. if (resp != null)
  144. resp.ThrowIfDisposed ();
  145. #if ((UNITY_ANDROID || UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR) || UNITY_5 || UNITY_5_3_OR_NEWER
  146. float retVal = ml_StatModel_calcError_10 (nativeObj, data.getNativeObjAddr (), test, resp.nativeObj);
  147. return retVal;
  148. #else
  149. return -1;
  150. #endif
  151. }
  152. //
  153. // C++: float cv::ml::StatModel::predict(Mat samples, Mat& results = Mat(), int flags = 0)
  154. //
  155. //javadoc: StatModel::predict(samples, results, flags)
  156. public virtual float predict (Mat samples, Mat results, int flags)
  157. {
  158. ThrowIfDisposed ();
  159. if (samples != null)
  160. samples.ThrowIfDisposed ();
  161. if (results != null)
  162. results.ThrowIfDisposed ();
  163. #if ((UNITY_ANDROID || UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR) || UNITY_5 || UNITY_5_3_OR_NEWER
  164. float retVal = ml_StatModel_predict_10 (nativeObj, samples.nativeObj, results.nativeObj, flags);
  165. return retVal;
  166. #else
  167. return -1;
  168. #endif
  169. }
  170. //javadoc: StatModel::predict(samples, results)
  171. public virtual float predict (Mat samples, Mat results)
  172. {
  173. ThrowIfDisposed ();
  174. if (samples != null)
  175. samples.ThrowIfDisposed ();
  176. if (results != null)
  177. results.ThrowIfDisposed ();
  178. #if ((UNITY_ANDROID || UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR) || UNITY_5 || UNITY_5_3_OR_NEWER
  179. float retVal = ml_StatModel_predict_11 (nativeObj, samples.nativeObj, results.nativeObj);
  180. return retVal;
  181. #else
  182. return -1;
  183. #endif
  184. }
  185. //javadoc: StatModel::predict(samples)
  186. public virtual float predict (Mat samples)
  187. {
  188. ThrowIfDisposed ();
  189. if (samples != null)
  190. samples.ThrowIfDisposed ();
  191. #if ((UNITY_ANDROID || UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR) || UNITY_5 || UNITY_5_3_OR_NEWER
  192. float retVal = ml_StatModel_predict_12 (nativeObj, samples.nativeObj);
  193. return retVal;
  194. #else
  195. return -1;
  196. #endif
  197. }
  198. //
  199. // C++: int cv::ml::StatModel::getVarCount()
  200. //
  201. //javadoc: StatModel::getVarCount()
  202. public int getVarCount ()
  203. {
  204. ThrowIfDisposed ();
  205. #if ((UNITY_ANDROID || UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR) || UNITY_5 || UNITY_5_3_OR_NEWER
  206. int retVal = ml_StatModel_getVarCount_10 (nativeObj);
  207. return retVal;
  208. #else
  209. return -1;
  210. #endif
  211. }
  212. #if (UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR
  213. const string LIBNAME = "__Internal";
  214. #else
  215. const string LIBNAME = "opencvforunity";
  216. #endif
  217. // C++: bool cv::ml::StatModel::empty()
  218. [DllImport (LIBNAME)]
  219. private static extern bool ml_StatModel_empty_10 (IntPtr nativeObj);
  220. // C++: bool cv::ml::StatModel::isClassifier()
  221. [DllImport (LIBNAME)]
  222. private static extern bool ml_StatModel_isClassifier_10 (IntPtr nativeObj);
  223. // C++: bool cv::ml::StatModel::isTrained()
  224. [DllImport (LIBNAME)]
  225. private static extern bool ml_StatModel_isTrained_10 (IntPtr nativeObj);
  226. // C++: bool cv::ml::StatModel::train(Mat samples, int layout, Mat responses)
  227. [DllImport (LIBNAME)]
  228. private static extern bool ml_StatModel_train_10 (IntPtr nativeObj, IntPtr samples_nativeObj, int layout, IntPtr responses_nativeObj);
  229. // C++: bool cv::ml::StatModel::train(Ptr_TrainData trainData, int flags = 0)
  230. [DllImport (LIBNAME)]
  231. private static extern bool ml_StatModel_train_11 (IntPtr nativeObj, IntPtr trainData_nativeObj, int flags);
  232. [DllImport (LIBNAME)]
  233. private static extern bool ml_StatModel_train_12 (IntPtr nativeObj, IntPtr trainData_nativeObj);
  234. // C++: float cv::ml::StatModel::calcError(Ptr_TrainData data, bool test, Mat& resp)
  235. [DllImport (LIBNAME)]
  236. private static extern float ml_StatModel_calcError_10 (IntPtr nativeObj, IntPtr data_nativeObj, bool test, IntPtr resp_nativeObj);
  237. // C++: float cv::ml::StatModel::predict(Mat samples, Mat& results = Mat(), int flags = 0)
  238. [DllImport (LIBNAME)]
  239. private static extern float ml_StatModel_predict_10 (IntPtr nativeObj, IntPtr samples_nativeObj, IntPtr results_nativeObj, int flags);
  240. [DllImport (LIBNAME)]
  241. private static extern float ml_StatModel_predict_11 (IntPtr nativeObj, IntPtr samples_nativeObj, IntPtr results_nativeObj);
  242. [DllImport (LIBNAME)]
  243. private static extern float ml_StatModel_predict_12 (IntPtr nativeObj, IntPtr samples_nativeObj);
  244. // C++: int cv::ml::StatModel::getVarCount()
  245. [DllImport (LIBNAME)]
  246. private static extern int ml_StatModel_getVarCount_10 (IntPtr nativeObj);
  247. // native support for java finalize()
  248. [DllImport (LIBNAME)]
  249. private static extern void ml_StatModel_delete (IntPtr nativeObj);
  250. }
  251. }