LogisticRegression.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470
  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 LogisticRegression
  9. //javadoc: LogisticRegression
  10. public class LogisticRegression : 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_LogisticRegression_delete(nativeObj);
  19. nativeObj = IntPtr.Zero;
  20. }
  21. } finally {
  22. base.Dispose(disposing);
  23. }
  24. #else
  25. return;
  26. #endif
  27. }
  28. protected internal LogisticRegression(IntPtr addr)
  29. : base(addr) {
  30. }
  31. // internal usage only
  32. public static new LogisticRegression __fromPtr__(IntPtr addr) {
  33. return new LogisticRegression(addr);
  34. }
  35. // C++: enum RegKinds
  36. public const int REG_DISABLE = -1;
  37. public const int REG_L1 = 0;
  38. public const int REG_L2 = 1;
  39. // C++: enum Methods
  40. public const int BATCH = 0;
  41. public const int MINI_BATCH = 1;
  42. //
  43. // C++: Mat cv::ml::LogisticRegression::get_learnt_thetas()
  44. //
  45. //javadoc: LogisticRegression::get_learnt_thetas()
  46. public Mat get_learnt_thetas() {
  47. ThrowIfDisposed();
  48. #if (UNITY_ANDROID && !UNITY_EDITOR)
  49. Mat retVal = new Mat(ml_LogisticRegression_get_1learnt_1thetas_10(nativeObj));
  50. return retVal;
  51. #else
  52. return null;
  53. #endif
  54. }
  55. //
  56. // C++: static Ptr_LogisticRegression cv::ml::LogisticRegression::create()
  57. //
  58. //javadoc: LogisticRegression::create()
  59. public static LogisticRegression create() {
  60. #if (UNITY_ANDROID && !UNITY_EDITOR)
  61. LogisticRegression retVal = LogisticRegression.__fromPtr__(ml_LogisticRegression_create_10());
  62. return retVal;
  63. #else
  64. return null;
  65. #endif
  66. }
  67. //
  68. // C++: static Ptr_LogisticRegression cv::ml::LogisticRegression::load(String filepath, String nodeName = String())
  69. //
  70. //javadoc: LogisticRegression::load(filepath, nodeName)
  71. public static LogisticRegression load(string filepath, string nodeName) {
  72. #if (UNITY_ANDROID && !UNITY_EDITOR)
  73. LogisticRegression retVal = LogisticRegression.__fromPtr__(ml_LogisticRegression_load_10(filepath, nodeName));
  74. return retVal;
  75. #else
  76. return null;
  77. #endif
  78. }
  79. //javadoc: LogisticRegression::load(filepath)
  80. public static LogisticRegression load(string filepath) {
  81. #if (UNITY_ANDROID && !UNITY_EDITOR)
  82. LogisticRegression retVal = LogisticRegression.__fromPtr__(ml_LogisticRegression_load_11(filepath));
  83. return retVal;
  84. #else
  85. return null;
  86. #endif
  87. }
  88. //
  89. // C++: TermCriteria cv::ml::LogisticRegression::getTermCriteria()
  90. //
  91. //javadoc: LogisticRegression::getTermCriteria()
  92. public TermCriteria getTermCriteria() {
  93. ThrowIfDisposed();
  94. #if (UNITY_ANDROID && !UNITY_EDITOR)
  95. double[] tmpArray = new double[3];
  96. ml_LogisticRegression_getTermCriteria_10(nativeObj, tmpArray);
  97. TermCriteria retVal = new TermCriteria(tmpArray);
  98. return retVal;
  99. #else
  100. return null;
  101. #endif
  102. }
  103. //
  104. // C++: double cv::ml::LogisticRegression::getLearningRate()
  105. //
  106. //javadoc: LogisticRegression::getLearningRate()
  107. public double getLearningRate() {
  108. ThrowIfDisposed();
  109. #if (UNITY_ANDROID && !UNITY_EDITOR)
  110. double retVal = ml_LogisticRegression_getLearningRate_10(nativeObj);
  111. return retVal;
  112. #else
  113. return -1;
  114. #endif
  115. }
  116. //
  117. // C++: float cv::ml::LogisticRegression::predict(Mat samples, Mat& results = Mat(), int flags = 0)
  118. //
  119. //javadoc: LogisticRegression::predict(samples, results, flags)
  120. public override float predict(Mat samples, Mat results, int flags) {
  121. ThrowIfDisposed();
  122. if (samples != null)
  123. samples.ThrowIfDisposed();
  124. if (results != null)
  125. results.ThrowIfDisposed();
  126. #if (UNITY_ANDROID && !UNITY_EDITOR)
  127. float retVal = ml_LogisticRegression_predict_10(nativeObj, samples.nativeObj, results.nativeObj, flags);
  128. return retVal;
  129. #else
  130. return -1;
  131. #endif
  132. }
  133. //javadoc: LogisticRegression::predict(samples, results)
  134. public override float predict(Mat samples, Mat results) {
  135. ThrowIfDisposed();
  136. if (samples != null)
  137. samples.ThrowIfDisposed();
  138. if (results != null)
  139. results.ThrowIfDisposed();
  140. #if (UNITY_ANDROID && !UNITY_EDITOR)
  141. float retVal = ml_LogisticRegression_predict_11(nativeObj, samples.nativeObj, results.nativeObj);
  142. return retVal;
  143. #else
  144. return -1;
  145. #endif
  146. }
  147. //javadoc: LogisticRegression::predict(samples)
  148. public override float predict(Mat samples) {
  149. ThrowIfDisposed();
  150. if (samples != null)
  151. samples.ThrowIfDisposed();
  152. #if (UNITY_ANDROID && !UNITY_EDITOR)
  153. float retVal = ml_LogisticRegression_predict_12(nativeObj, samples.nativeObj);
  154. return retVal;
  155. #else
  156. return -1;
  157. #endif
  158. }
  159. //
  160. // C++: int cv::ml::LogisticRegression::getIterations()
  161. //
  162. //javadoc: LogisticRegression::getIterations()
  163. public int getIterations() {
  164. ThrowIfDisposed();
  165. #if (UNITY_ANDROID && !UNITY_EDITOR)
  166. int retVal = ml_LogisticRegression_getIterations_10(nativeObj);
  167. return retVal;
  168. #else
  169. return -1;
  170. #endif
  171. }
  172. //
  173. // C++: int cv::ml::LogisticRegression::getMiniBatchSize()
  174. //
  175. //javadoc: LogisticRegression::getMiniBatchSize()
  176. public int getMiniBatchSize() {
  177. ThrowIfDisposed();
  178. #if (UNITY_ANDROID && !UNITY_EDITOR)
  179. int retVal = ml_LogisticRegression_getMiniBatchSize_10(nativeObj);
  180. return retVal;
  181. #else
  182. return -1;
  183. #endif
  184. }
  185. //
  186. // C++: int cv::ml::LogisticRegression::getRegularization()
  187. //
  188. //javadoc: LogisticRegression::getRegularization()
  189. public int getRegularization() {
  190. ThrowIfDisposed();
  191. #if (UNITY_ANDROID && !UNITY_EDITOR)
  192. int retVal = ml_LogisticRegression_getRegularization_10(nativeObj);
  193. return retVal;
  194. #else
  195. return -1;
  196. #endif
  197. }
  198. //
  199. // C++: int cv::ml::LogisticRegression::getTrainMethod()
  200. //
  201. //javadoc: LogisticRegression::getTrainMethod()
  202. public int getTrainMethod() {
  203. ThrowIfDisposed();
  204. #if (UNITY_ANDROID && !UNITY_EDITOR)
  205. int retVal = ml_LogisticRegression_getTrainMethod_10(nativeObj);
  206. return retVal;
  207. #else
  208. return -1;
  209. #endif
  210. }
  211. //
  212. // C++: void cv::ml::LogisticRegression::setIterations(int val)
  213. //
  214. //javadoc: LogisticRegression::setIterations(val)
  215. public void setIterations(int val) {
  216. ThrowIfDisposed();
  217. #if (UNITY_ANDROID && !UNITY_EDITOR)
  218. ml_LogisticRegression_setIterations_10(nativeObj, val);
  219. return;
  220. #else
  221. return;
  222. #endif
  223. }
  224. //
  225. // C++: void cv::ml::LogisticRegression::setLearningRate(double val)
  226. //
  227. //javadoc: LogisticRegression::setLearningRate(val)
  228. public void setLearningRate(double val) {
  229. ThrowIfDisposed();
  230. #if (UNITY_ANDROID && !UNITY_EDITOR)
  231. ml_LogisticRegression_setLearningRate_10(nativeObj, val);
  232. return;
  233. #else
  234. return;
  235. #endif
  236. }
  237. //
  238. // C++: void cv::ml::LogisticRegression::setMiniBatchSize(int val)
  239. //
  240. //javadoc: LogisticRegression::setMiniBatchSize(val)
  241. public void setMiniBatchSize(int val) {
  242. ThrowIfDisposed();
  243. #if (UNITY_ANDROID && !UNITY_EDITOR)
  244. ml_LogisticRegression_setMiniBatchSize_10(nativeObj, val);
  245. return;
  246. #else
  247. return;
  248. #endif
  249. }
  250. //
  251. // C++: void cv::ml::LogisticRegression::setRegularization(int val)
  252. //
  253. //javadoc: LogisticRegression::setRegularization(val)
  254. public void setRegularization(int val) {
  255. ThrowIfDisposed();
  256. #if (UNITY_ANDROID && !UNITY_EDITOR)
  257. ml_LogisticRegression_setRegularization_10(nativeObj, val);
  258. return;
  259. #else
  260. return;
  261. #endif
  262. }
  263. //
  264. // C++: void cv::ml::LogisticRegression::setTermCriteria(TermCriteria val)
  265. //
  266. //javadoc: LogisticRegression::setTermCriteria(val)
  267. public void setTermCriteria(TermCriteria val) {
  268. ThrowIfDisposed();
  269. #if (UNITY_ANDROID && !UNITY_EDITOR)
  270. ml_LogisticRegression_setTermCriteria_10(nativeObj, val.type, val.maxCount, val.epsilon);
  271. return;
  272. #else
  273. return;
  274. #endif
  275. }
  276. //
  277. // C++: void cv::ml::LogisticRegression::setTrainMethod(int val)
  278. //
  279. //javadoc: LogisticRegression::setTrainMethod(val)
  280. public void setTrainMethod(int val) {
  281. ThrowIfDisposed();
  282. #if (UNITY_ANDROID && !UNITY_EDITOR)
  283. ml_LogisticRegression_setTrainMethod_10(nativeObj, val);
  284. return;
  285. #else
  286. return;
  287. #endif
  288. }
  289. #if (UNITY_ANDROID && !UNITY_EDITOR)
  290. const string LIBNAME = "opencvforunity";
  291. // C++: Mat cv::ml::LogisticRegression::get_learnt_thetas()
  292. [DllImport(LIBNAME)]
  293. private static extern IntPtr ml_LogisticRegression_get_1learnt_1thetas_10(IntPtr nativeObj);
  294. // C++: static Ptr_LogisticRegression cv::ml::LogisticRegression::create()
  295. [DllImport(LIBNAME)]
  296. private static extern IntPtr ml_LogisticRegression_create_10();
  297. // C++: static Ptr_LogisticRegression cv::ml::LogisticRegression::load(String filepath, String nodeName = String())
  298. [DllImport(LIBNAME)]
  299. private static extern IntPtr ml_LogisticRegression_load_10(string filepath, string nodeName);
  300. [DllImport(LIBNAME)]
  301. private static extern IntPtr ml_LogisticRegression_load_11(string filepath);
  302. // C++: TermCriteria cv::ml::LogisticRegression::getTermCriteria()
  303. [DllImport(LIBNAME)]
  304. private static extern void ml_LogisticRegression_getTermCriteria_10(IntPtr nativeObj, double[] retVal);
  305. // C++: double cv::ml::LogisticRegression::getLearningRate()
  306. [DllImport(LIBNAME)]
  307. private static extern double ml_LogisticRegression_getLearningRate_10(IntPtr nativeObj);
  308. // C++: float cv::ml::LogisticRegression::predict(Mat samples, Mat& results = Mat(), int flags = 0)
  309. [DllImport(LIBNAME)]
  310. private static extern float ml_LogisticRegression_predict_10(IntPtr nativeObj, IntPtr samples_nativeObj, IntPtr results_nativeObj, int flags);
  311. [DllImport(LIBNAME)]
  312. private static extern float ml_LogisticRegression_predict_11(IntPtr nativeObj, IntPtr samples_nativeObj, IntPtr results_nativeObj);
  313. [DllImport(LIBNAME)]
  314. private static extern float ml_LogisticRegression_predict_12(IntPtr nativeObj, IntPtr samples_nativeObj);
  315. // C++: int cv::ml::LogisticRegression::getIterations()
  316. [DllImport(LIBNAME)]
  317. private static extern int ml_LogisticRegression_getIterations_10(IntPtr nativeObj);
  318. // C++: int cv::ml::LogisticRegression::getMiniBatchSize()
  319. [DllImport(LIBNAME)]
  320. private static extern int ml_LogisticRegression_getMiniBatchSize_10(IntPtr nativeObj);
  321. // C++: int cv::ml::LogisticRegression::getRegularization()
  322. [DllImport(LIBNAME)]
  323. private static extern int ml_LogisticRegression_getRegularization_10(IntPtr nativeObj);
  324. // C++: int cv::ml::LogisticRegression::getTrainMethod()
  325. [DllImport(LIBNAME)]
  326. private static extern int ml_LogisticRegression_getTrainMethod_10(IntPtr nativeObj);
  327. // C++: void cv::ml::LogisticRegression::setIterations(int val)
  328. [DllImport(LIBNAME)]
  329. private static extern void ml_LogisticRegression_setIterations_10(IntPtr nativeObj, int val);
  330. // C++: void cv::ml::LogisticRegression::setLearningRate(double val)
  331. [DllImport(LIBNAME)]
  332. private static extern void ml_LogisticRegression_setLearningRate_10(IntPtr nativeObj, double val);
  333. // C++: void cv::ml::LogisticRegression::setMiniBatchSize(int val)
  334. [DllImport(LIBNAME)]
  335. private static extern void ml_LogisticRegression_setMiniBatchSize_10(IntPtr nativeObj, int val);
  336. // C++: void cv::ml::LogisticRegression::setRegularization(int val)
  337. [DllImport(LIBNAME)]
  338. private static extern void ml_LogisticRegression_setRegularization_10(IntPtr nativeObj, int val);
  339. // C++: void cv::ml::LogisticRegression::setTermCriteria(TermCriteria val)
  340. [DllImport(LIBNAME)]
  341. private static extern void ml_LogisticRegression_setTermCriteria_10(IntPtr nativeObj, int val_type, int val_maxCount, double val_epsilon);
  342. // C++: void cv::ml::LogisticRegression::setTrainMethod(int val)
  343. [DllImport(LIBNAME)]
  344. private static extern void ml_LogisticRegression_setTrainMethod_10(IntPtr nativeObj, int val);
  345. // native support for java finalize()
  346. [DllImport(LIBNAME)]
  347. private static extern void ml_LogisticRegression_delete(IntPtr nativeObj);
  348. #endif
  349. }
  350. }