SVM.cs 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871
  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 SVM
  10. //javadoc: SVM
  11. public class SVM : 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_SVM_delete(nativeObj);
  22. nativeObj = IntPtr.Zero;
  23. }
  24. } finally {
  25. base.Dispose (disposing);
  26. }
  27. #else
  28. return;
  29. #endif
  30. }
  31. protected internal SVM (IntPtr addr) : base (addr) { }
  32. // internal usage only
  33. public static new SVM __fromPtr__ (IntPtr addr) { return new SVM (addr); }
  34. // C++: enum ParamTypes
  35. public const int C = 0;
  36. public const int GAMMA = 1;
  37. public const int P = 2;
  38. public const int NU = 3;
  39. public const int COEF = 4;
  40. public const int DEGREE = 5;
  41. // C++: enum Types
  42. public const int C_SVC = 100;
  43. public const int NU_SVC = 101;
  44. public const int ONE_CLASS = 102;
  45. public const int EPS_SVR = 103;
  46. public const int NU_SVR = 104;
  47. // C++: enum KernelTypes
  48. public const int CUSTOM = -1;
  49. public const int LINEAR = 0;
  50. public const int POLY = 1;
  51. public const int RBF = 2;
  52. public const int SIGMOID = 3;
  53. public const int CHI2 = 4;
  54. public const int INTER = 5;
  55. //
  56. // C++: Mat cv::ml::SVM::getClassWeights()
  57. //
  58. //javadoc: SVM::getClassWeights()
  59. public Mat getClassWeights ()
  60. {
  61. ThrowIfDisposed ();
  62. #if ((UNITY_ANDROID || UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR) || UNITY_5 || UNITY_5_3_OR_NEWER
  63. Mat retVal = new Mat(ml_SVM_getClassWeights_10(nativeObj));
  64. return retVal;
  65. #else
  66. return null;
  67. #endif
  68. }
  69. //
  70. // C++: Mat cv::ml::SVM::getSupportVectors()
  71. //
  72. //javadoc: SVM::getSupportVectors()
  73. public Mat getSupportVectors ()
  74. {
  75. ThrowIfDisposed ();
  76. #if ((UNITY_ANDROID || UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR) || UNITY_5 || UNITY_5_3_OR_NEWER
  77. Mat retVal = new Mat(ml_SVM_getSupportVectors_10(nativeObj));
  78. return retVal;
  79. #else
  80. return null;
  81. #endif
  82. }
  83. //
  84. // C++: Mat cv::ml::SVM::getUncompressedSupportVectors()
  85. //
  86. //javadoc: SVM::getUncompressedSupportVectors()
  87. public Mat getUncompressedSupportVectors ()
  88. {
  89. ThrowIfDisposed ();
  90. #if ((UNITY_ANDROID || UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR) || UNITY_5 || UNITY_5_3_OR_NEWER
  91. Mat retVal = new Mat(ml_SVM_getUncompressedSupportVectors_10(nativeObj));
  92. return retVal;
  93. #else
  94. return null;
  95. #endif
  96. }
  97. //
  98. // C++: static Ptr_ParamGrid cv::ml::SVM::getDefaultGridPtr(int param_id)
  99. //
  100. //javadoc: SVM::getDefaultGridPtr(param_id)
  101. public static ParamGrid getDefaultGridPtr (int param_id)
  102. {
  103. #if ((UNITY_ANDROID || UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR) || UNITY_5 || UNITY_5_3_OR_NEWER
  104. ParamGrid retVal = ParamGrid.__fromPtr__(ml_SVM_getDefaultGridPtr_10(param_id));
  105. return retVal;
  106. #else
  107. return null;
  108. #endif
  109. }
  110. //
  111. // C++: static Ptr_SVM cv::ml::SVM::create()
  112. //
  113. //javadoc: SVM::create()
  114. public static SVM create ()
  115. {
  116. #if ((UNITY_ANDROID || UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR) || UNITY_5 || UNITY_5_3_OR_NEWER
  117. SVM retVal = SVM.__fromPtr__(ml_SVM_create_10());
  118. return retVal;
  119. #else
  120. return null;
  121. #endif
  122. }
  123. //
  124. // C++: static Ptr_SVM cv::ml::SVM::load(String filepath)
  125. //
  126. //javadoc: SVM::load(filepath)
  127. public static SVM load (string filepath)
  128. {
  129. #if ((UNITY_ANDROID || UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR) || UNITY_5 || UNITY_5_3_OR_NEWER
  130. SVM retVal = SVM.__fromPtr__(ml_SVM_load_10(filepath));
  131. return retVal;
  132. #else
  133. return null;
  134. #endif
  135. }
  136. //
  137. // C++: TermCriteria cv::ml::SVM::getTermCriteria()
  138. //
  139. //javadoc: SVM::getTermCriteria()
  140. public TermCriteria getTermCriteria ()
  141. {
  142. ThrowIfDisposed ();
  143. #if ((UNITY_ANDROID || UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR) || UNITY_5 || UNITY_5_3_OR_NEWER
  144. double[] tmpArray = new double[3];
  145. ml_SVM_getTermCriteria_10(nativeObj, tmpArray);
  146. TermCriteria retVal = new TermCriteria (tmpArray);
  147. return retVal;
  148. #else
  149. return null;
  150. #endif
  151. }
  152. //
  153. // C++: bool cv::ml::SVM::trainAuto(Mat samples, int layout, Mat responses, int kFold = 10, Ptr_ParamGrid Cgrid = SVM::getDefaultGridPtr(SVM::C), Ptr_ParamGrid gammaGrid = SVM::getDefaultGridPtr(SVM::GAMMA), Ptr_ParamGrid pGrid = SVM::getDefaultGridPtr(SVM::P), Ptr_ParamGrid nuGrid = SVM::getDefaultGridPtr(SVM::NU), Ptr_ParamGrid coeffGrid = SVM::getDefaultGridPtr(SVM::COEF), Ptr_ParamGrid degreeGrid = SVM::getDefaultGridPtr(SVM::DEGREE), bool balanced = false)
  154. //
  155. //javadoc: SVM::trainAuto(samples, layout, responses, kFold, Cgrid, gammaGrid, pGrid, nuGrid, coeffGrid, degreeGrid, balanced)
  156. public bool trainAuto (Mat samples, int layout, Mat responses, int kFold, ParamGrid Cgrid, ParamGrid gammaGrid, ParamGrid pGrid, ParamGrid nuGrid, ParamGrid coeffGrid, ParamGrid degreeGrid, bool balanced)
  157. {
  158. ThrowIfDisposed ();
  159. if (samples != null) samples.ThrowIfDisposed ();
  160. if (responses != null) responses.ThrowIfDisposed ();
  161. if (Cgrid != null) Cgrid.ThrowIfDisposed ();
  162. if (gammaGrid != null) gammaGrid.ThrowIfDisposed ();
  163. if (pGrid != null) pGrid.ThrowIfDisposed ();
  164. if (nuGrid != null) nuGrid.ThrowIfDisposed ();
  165. if (coeffGrid != null) coeffGrid.ThrowIfDisposed ();
  166. if (degreeGrid != null) degreeGrid.ThrowIfDisposed ();
  167. #if ((UNITY_ANDROID || UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR) || UNITY_5 || UNITY_5_3_OR_NEWER
  168. bool retVal = ml_SVM_trainAuto_10(nativeObj, samples.nativeObj, layout, responses.nativeObj, kFold, Cgrid.getNativeObjAddr(), gammaGrid.getNativeObjAddr(), pGrid.getNativeObjAddr(), nuGrid.getNativeObjAddr(), coeffGrid.getNativeObjAddr(), degreeGrid.getNativeObjAddr(), balanced);
  169. return retVal;
  170. #else
  171. return false;
  172. #endif
  173. }
  174. //javadoc: SVM::trainAuto(samples, layout, responses, kFold, Cgrid, gammaGrid, pGrid, nuGrid, coeffGrid, degreeGrid)
  175. public bool trainAuto (Mat samples, int layout, Mat responses, int kFold, ParamGrid Cgrid, ParamGrid gammaGrid, ParamGrid pGrid, ParamGrid nuGrid, ParamGrid coeffGrid, ParamGrid degreeGrid)
  176. {
  177. ThrowIfDisposed ();
  178. if (samples != null) samples.ThrowIfDisposed ();
  179. if (responses != null) responses.ThrowIfDisposed ();
  180. if (Cgrid != null) Cgrid.ThrowIfDisposed ();
  181. if (gammaGrid != null) gammaGrid.ThrowIfDisposed ();
  182. if (pGrid != null) pGrid.ThrowIfDisposed ();
  183. if (nuGrid != null) nuGrid.ThrowIfDisposed ();
  184. if (coeffGrid != null) coeffGrid.ThrowIfDisposed ();
  185. if (degreeGrid != null) degreeGrid.ThrowIfDisposed ();
  186. #if ((UNITY_ANDROID || UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR) || UNITY_5 || UNITY_5_3_OR_NEWER
  187. bool retVal = ml_SVM_trainAuto_11(nativeObj, samples.nativeObj, layout, responses.nativeObj, kFold, Cgrid.getNativeObjAddr(), gammaGrid.getNativeObjAddr(), pGrid.getNativeObjAddr(), nuGrid.getNativeObjAddr(), coeffGrid.getNativeObjAddr(), degreeGrid.getNativeObjAddr());
  188. return retVal;
  189. #else
  190. return false;
  191. #endif
  192. }
  193. //javadoc: SVM::trainAuto(samples, layout, responses, kFold, Cgrid, gammaGrid, pGrid, nuGrid, coeffGrid)
  194. public bool trainAuto (Mat samples, int layout, Mat responses, int kFold, ParamGrid Cgrid, ParamGrid gammaGrid, ParamGrid pGrid, ParamGrid nuGrid, ParamGrid coeffGrid)
  195. {
  196. ThrowIfDisposed ();
  197. if (samples != null) samples.ThrowIfDisposed ();
  198. if (responses != null) responses.ThrowIfDisposed ();
  199. if (Cgrid != null) Cgrid.ThrowIfDisposed ();
  200. if (gammaGrid != null) gammaGrid.ThrowIfDisposed ();
  201. if (pGrid != null) pGrid.ThrowIfDisposed ();
  202. if (nuGrid != null) nuGrid.ThrowIfDisposed ();
  203. if (coeffGrid != null) coeffGrid.ThrowIfDisposed ();
  204. #if ((UNITY_ANDROID || UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR) || UNITY_5 || UNITY_5_3_OR_NEWER
  205. bool retVal = ml_SVM_trainAuto_12(nativeObj, samples.nativeObj, layout, responses.nativeObj, kFold, Cgrid.getNativeObjAddr(), gammaGrid.getNativeObjAddr(), pGrid.getNativeObjAddr(), nuGrid.getNativeObjAddr(), coeffGrid.getNativeObjAddr());
  206. return retVal;
  207. #else
  208. return false;
  209. #endif
  210. }
  211. //javadoc: SVM::trainAuto(samples, layout, responses, kFold, Cgrid, gammaGrid, pGrid, nuGrid)
  212. public bool trainAuto (Mat samples, int layout, Mat responses, int kFold, ParamGrid Cgrid, ParamGrid gammaGrid, ParamGrid pGrid, ParamGrid nuGrid)
  213. {
  214. ThrowIfDisposed ();
  215. if (samples != null) samples.ThrowIfDisposed ();
  216. if (responses != null) responses.ThrowIfDisposed ();
  217. if (Cgrid != null) Cgrid.ThrowIfDisposed ();
  218. if (gammaGrid != null) gammaGrid.ThrowIfDisposed ();
  219. if (pGrid != null) pGrid.ThrowIfDisposed ();
  220. if (nuGrid != null) nuGrid.ThrowIfDisposed ();
  221. #if ((UNITY_ANDROID || UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR) || UNITY_5 || UNITY_5_3_OR_NEWER
  222. bool retVal = ml_SVM_trainAuto_13(nativeObj, samples.nativeObj, layout, responses.nativeObj, kFold, Cgrid.getNativeObjAddr(), gammaGrid.getNativeObjAddr(), pGrid.getNativeObjAddr(), nuGrid.getNativeObjAddr());
  223. return retVal;
  224. #else
  225. return false;
  226. #endif
  227. }
  228. //javadoc: SVM::trainAuto(samples, layout, responses, kFold, Cgrid, gammaGrid, pGrid)
  229. public bool trainAuto (Mat samples, int layout, Mat responses, int kFold, ParamGrid Cgrid, ParamGrid gammaGrid, ParamGrid pGrid)
  230. {
  231. ThrowIfDisposed ();
  232. if (samples != null) samples.ThrowIfDisposed ();
  233. if (responses != null) responses.ThrowIfDisposed ();
  234. if (Cgrid != null) Cgrid.ThrowIfDisposed ();
  235. if (gammaGrid != null) gammaGrid.ThrowIfDisposed ();
  236. if (pGrid != null) pGrid.ThrowIfDisposed ();
  237. #if ((UNITY_ANDROID || UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR) || UNITY_5 || UNITY_5_3_OR_NEWER
  238. bool retVal = ml_SVM_trainAuto_14(nativeObj, samples.nativeObj, layout, responses.nativeObj, kFold, Cgrid.getNativeObjAddr(), gammaGrid.getNativeObjAddr(), pGrid.getNativeObjAddr());
  239. return retVal;
  240. #else
  241. return false;
  242. #endif
  243. }
  244. //javadoc: SVM::trainAuto(samples, layout, responses, kFold, Cgrid, gammaGrid)
  245. public bool trainAuto (Mat samples, int layout, Mat responses, int kFold, ParamGrid Cgrid, ParamGrid gammaGrid)
  246. {
  247. ThrowIfDisposed ();
  248. if (samples != null) samples.ThrowIfDisposed ();
  249. if (responses != null) responses.ThrowIfDisposed ();
  250. if (Cgrid != null) Cgrid.ThrowIfDisposed ();
  251. if (gammaGrid != null) gammaGrid.ThrowIfDisposed ();
  252. #if ((UNITY_ANDROID || UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR) || UNITY_5 || UNITY_5_3_OR_NEWER
  253. bool retVal = ml_SVM_trainAuto_15(nativeObj, samples.nativeObj, layout, responses.nativeObj, kFold, Cgrid.getNativeObjAddr(), gammaGrid.getNativeObjAddr());
  254. return retVal;
  255. #else
  256. return false;
  257. #endif
  258. }
  259. //javadoc: SVM::trainAuto(samples, layout, responses, kFold, Cgrid)
  260. public bool trainAuto (Mat samples, int layout, Mat responses, int kFold, ParamGrid Cgrid)
  261. {
  262. ThrowIfDisposed ();
  263. if (samples != null) samples.ThrowIfDisposed ();
  264. if (responses != null) responses.ThrowIfDisposed ();
  265. if (Cgrid != null) Cgrid.ThrowIfDisposed ();
  266. #if ((UNITY_ANDROID || UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR) || UNITY_5 || UNITY_5_3_OR_NEWER
  267. bool retVal = ml_SVM_trainAuto_16(nativeObj, samples.nativeObj, layout, responses.nativeObj, kFold, Cgrid.getNativeObjAddr());
  268. return retVal;
  269. #else
  270. return false;
  271. #endif
  272. }
  273. //javadoc: SVM::trainAuto(samples, layout, responses, kFold)
  274. public bool trainAuto (Mat samples, int layout, Mat responses, int kFold)
  275. {
  276. ThrowIfDisposed ();
  277. if (samples != null) samples.ThrowIfDisposed ();
  278. if (responses != null) responses.ThrowIfDisposed ();
  279. #if ((UNITY_ANDROID || UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR) || UNITY_5 || UNITY_5_3_OR_NEWER
  280. bool retVal = ml_SVM_trainAuto_17(nativeObj, samples.nativeObj, layout, responses.nativeObj, kFold);
  281. return retVal;
  282. #else
  283. return false;
  284. #endif
  285. }
  286. //javadoc: SVM::trainAuto(samples, layout, responses)
  287. public bool trainAuto (Mat samples, int layout, Mat responses)
  288. {
  289. ThrowIfDisposed ();
  290. if (samples != null) samples.ThrowIfDisposed ();
  291. if (responses != null) responses.ThrowIfDisposed ();
  292. #if ((UNITY_ANDROID || UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR) || UNITY_5 || UNITY_5_3_OR_NEWER
  293. bool retVal = ml_SVM_trainAuto_18(nativeObj, samples.nativeObj, layout, responses.nativeObj);
  294. return retVal;
  295. #else
  296. return false;
  297. #endif
  298. }
  299. //
  300. // C++: double cv::ml::SVM::getC()
  301. //
  302. //javadoc: SVM::getC()
  303. public double getC ()
  304. {
  305. ThrowIfDisposed ();
  306. #if ((UNITY_ANDROID || UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR) || UNITY_5 || UNITY_5_3_OR_NEWER
  307. double retVal = ml_SVM_getC_10(nativeObj);
  308. return retVal;
  309. #else
  310. return -1;
  311. #endif
  312. }
  313. //
  314. // C++: double cv::ml::SVM::getCoef0()
  315. //
  316. //javadoc: SVM::getCoef0()
  317. public double getCoef0 ()
  318. {
  319. ThrowIfDisposed ();
  320. #if ((UNITY_ANDROID || UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR) || UNITY_5 || UNITY_5_3_OR_NEWER
  321. double retVal = ml_SVM_getCoef0_10(nativeObj);
  322. return retVal;
  323. #else
  324. return -1;
  325. #endif
  326. }
  327. //
  328. // C++: double cv::ml::SVM::getDecisionFunction(int i, Mat& alpha, Mat& svidx)
  329. //
  330. //javadoc: SVM::getDecisionFunction(i, alpha, svidx)
  331. public double getDecisionFunction (int i, Mat alpha, Mat svidx)
  332. {
  333. ThrowIfDisposed ();
  334. if (alpha != null) alpha.ThrowIfDisposed ();
  335. if (svidx != null) svidx.ThrowIfDisposed ();
  336. #if ((UNITY_ANDROID || UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR) || UNITY_5 || UNITY_5_3_OR_NEWER
  337. double retVal = ml_SVM_getDecisionFunction_10(nativeObj, i, alpha.nativeObj, svidx.nativeObj);
  338. return retVal;
  339. #else
  340. return -1;
  341. #endif
  342. }
  343. //
  344. // C++: double cv::ml::SVM::getDegree()
  345. //
  346. //javadoc: SVM::getDegree()
  347. public double getDegree ()
  348. {
  349. ThrowIfDisposed ();
  350. #if ((UNITY_ANDROID || UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR) || UNITY_5 || UNITY_5_3_OR_NEWER
  351. double retVal = ml_SVM_getDegree_10(nativeObj);
  352. return retVal;
  353. #else
  354. return -1;
  355. #endif
  356. }
  357. //
  358. // C++: double cv::ml::SVM::getGamma()
  359. //
  360. //javadoc: SVM::getGamma()
  361. public double getGamma ()
  362. {
  363. ThrowIfDisposed ();
  364. #if ((UNITY_ANDROID || UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR) || UNITY_5 || UNITY_5_3_OR_NEWER
  365. double retVal = ml_SVM_getGamma_10(nativeObj);
  366. return retVal;
  367. #else
  368. return -1;
  369. #endif
  370. }
  371. //
  372. // C++: double cv::ml::SVM::getNu()
  373. //
  374. //javadoc: SVM::getNu()
  375. public double getNu ()
  376. {
  377. ThrowIfDisposed ();
  378. #if ((UNITY_ANDROID || UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR) || UNITY_5 || UNITY_5_3_OR_NEWER
  379. double retVal = ml_SVM_getNu_10(nativeObj);
  380. return retVal;
  381. #else
  382. return -1;
  383. #endif
  384. }
  385. //
  386. // C++: double cv::ml::SVM::getP()
  387. //
  388. //javadoc: SVM::getP()
  389. public double getP ()
  390. {
  391. ThrowIfDisposed ();
  392. #if ((UNITY_ANDROID || UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR) || UNITY_5 || UNITY_5_3_OR_NEWER
  393. double retVal = ml_SVM_getP_10(nativeObj);
  394. return retVal;
  395. #else
  396. return -1;
  397. #endif
  398. }
  399. //
  400. // C++: int cv::ml::SVM::getKernelType()
  401. //
  402. //javadoc: SVM::getKernelType()
  403. public int getKernelType ()
  404. {
  405. ThrowIfDisposed ();
  406. #if ((UNITY_ANDROID || UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR) || UNITY_5 || UNITY_5_3_OR_NEWER
  407. int retVal = ml_SVM_getKernelType_10(nativeObj);
  408. return retVal;
  409. #else
  410. return -1;
  411. #endif
  412. }
  413. //
  414. // C++: int cv::ml::SVM::getType()
  415. //
  416. //javadoc: SVM::getType()
  417. public int getType ()
  418. {
  419. ThrowIfDisposed ();
  420. #if ((UNITY_ANDROID || UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR) || UNITY_5 || UNITY_5_3_OR_NEWER
  421. int retVal = ml_SVM_getType_10(nativeObj);
  422. return retVal;
  423. #else
  424. return -1;
  425. #endif
  426. }
  427. //
  428. // C++: void cv::ml::SVM::setC(double val)
  429. //
  430. //javadoc: SVM::setC(val)
  431. public void setC (double val)
  432. {
  433. ThrowIfDisposed ();
  434. #if ((UNITY_ANDROID || UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR) || UNITY_5 || UNITY_5_3_OR_NEWER
  435. ml_SVM_setC_10(nativeObj, val);
  436. return;
  437. #else
  438. return;
  439. #endif
  440. }
  441. //
  442. // C++: void cv::ml::SVM::setClassWeights(Mat val)
  443. //
  444. //javadoc: SVM::setClassWeights(val)
  445. public void setClassWeights (Mat val)
  446. {
  447. ThrowIfDisposed ();
  448. if (val != null) val.ThrowIfDisposed ();
  449. #if ((UNITY_ANDROID || UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR) || UNITY_5 || UNITY_5_3_OR_NEWER
  450. ml_SVM_setClassWeights_10(nativeObj, val.nativeObj);
  451. return;
  452. #else
  453. return;
  454. #endif
  455. }
  456. //
  457. // C++: void cv::ml::SVM::setCoef0(double val)
  458. //
  459. //javadoc: SVM::setCoef0(val)
  460. public void setCoef0 (double val)
  461. {
  462. ThrowIfDisposed ();
  463. #if ((UNITY_ANDROID || UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR) || UNITY_5 || UNITY_5_3_OR_NEWER
  464. ml_SVM_setCoef0_10(nativeObj, val);
  465. return;
  466. #else
  467. return;
  468. #endif
  469. }
  470. //
  471. // C++: void cv::ml::SVM::setDegree(double val)
  472. //
  473. //javadoc: SVM::setDegree(val)
  474. public void setDegree (double val)
  475. {
  476. ThrowIfDisposed ();
  477. #if ((UNITY_ANDROID || UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR) || UNITY_5 || UNITY_5_3_OR_NEWER
  478. ml_SVM_setDegree_10(nativeObj, val);
  479. return;
  480. #else
  481. return;
  482. #endif
  483. }
  484. //
  485. // C++: void cv::ml::SVM::setGamma(double val)
  486. //
  487. //javadoc: SVM::setGamma(val)
  488. public void setGamma (double val)
  489. {
  490. ThrowIfDisposed ();
  491. #if ((UNITY_ANDROID || UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR) || UNITY_5 || UNITY_5_3_OR_NEWER
  492. ml_SVM_setGamma_10(nativeObj, val);
  493. return;
  494. #else
  495. return;
  496. #endif
  497. }
  498. //
  499. // C++: void cv::ml::SVM::setKernel(int kernelType)
  500. //
  501. //javadoc: SVM::setKernel(kernelType)
  502. public void setKernel (int kernelType)
  503. {
  504. ThrowIfDisposed ();
  505. #if ((UNITY_ANDROID || UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR) || UNITY_5 || UNITY_5_3_OR_NEWER
  506. ml_SVM_setKernel_10(nativeObj, kernelType);
  507. return;
  508. #else
  509. return;
  510. #endif
  511. }
  512. //
  513. // C++: void cv::ml::SVM::setNu(double val)
  514. //
  515. //javadoc: SVM::setNu(val)
  516. public void setNu (double val)
  517. {
  518. ThrowIfDisposed ();
  519. #if ((UNITY_ANDROID || UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR) || UNITY_5 || UNITY_5_3_OR_NEWER
  520. ml_SVM_setNu_10(nativeObj, val);
  521. return;
  522. #else
  523. return;
  524. #endif
  525. }
  526. //
  527. // C++: void cv::ml::SVM::setP(double val)
  528. //
  529. //javadoc: SVM::setP(val)
  530. public void setP (double val)
  531. {
  532. ThrowIfDisposed ();
  533. #if ((UNITY_ANDROID || UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR) || UNITY_5 || UNITY_5_3_OR_NEWER
  534. ml_SVM_setP_10(nativeObj, val);
  535. return;
  536. #else
  537. return;
  538. #endif
  539. }
  540. //
  541. // C++: void cv::ml::SVM::setTermCriteria(TermCriteria val)
  542. //
  543. //javadoc: SVM::setTermCriteria(val)
  544. public void setTermCriteria (TermCriteria val)
  545. {
  546. ThrowIfDisposed ();
  547. #if ((UNITY_ANDROID || UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR) || UNITY_5 || UNITY_5_3_OR_NEWER
  548. ml_SVM_setTermCriteria_10(nativeObj, val.type, val.maxCount, val.epsilon);
  549. return;
  550. #else
  551. return;
  552. #endif
  553. }
  554. //
  555. // C++: void cv::ml::SVM::setType(int val)
  556. //
  557. //javadoc: SVM::setType(val)
  558. public void setType (int val)
  559. {
  560. ThrowIfDisposed ();
  561. #if ((UNITY_ANDROID || UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR) || UNITY_5 || UNITY_5_3_OR_NEWER
  562. ml_SVM_setType_10(nativeObj, val);
  563. return;
  564. #else
  565. return;
  566. #endif
  567. }
  568. #if (UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR
  569. const string LIBNAME = "__Internal";
  570. #else
  571. const string LIBNAME = "opencvforunity";
  572. #endif
  573. // C++: Mat cv::ml::SVM::getClassWeights()
  574. [DllImport (LIBNAME)]
  575. private static extern IntPtr ml_SVM_getClassWeights_10 (IntPtr nativeObj);
  576. // C++: Mat cv::ml::SVM::getSupportVectors()
  577. [DllImport (LIBNAME)]
  578. private static extern IntPtr ml_SVM_getSupportVectors_10 (IntPtr nativeObj);
  579. // C++: Mat cv::ml::SVM::getUncompressedSupportVectors()
  580. [DllImport (LIBNAME)]
  581. private static extern IntPtr ml_SVM_getUncompressedSupportVectors_10 (IntPtr nativeObj);
  582. // C++: static Ptr_ParamGrid cv::ml::SVM::getDefaultGridPtr(int param_id)
  583. [DllImport (LIBNAME)]
  584. private static extern IntPtr ml_SVM_getDefaultGridPtr_10 (int param_id);
  585. // C++: static Ptr_SVM cv::ml::SVM::create()
  586. [DllImport (LIBNAME)]
  587. private static extern IntPtr ml_SVM_create_10 ();
  588. // C++: static Ptr_SVM cv::ml::SVM::load(String filepath)
  589. [DllImport (LIBNAME)]
  590. private static extern IntPtr ml_SVM_load_10 (string filepath);
  591. // C++: TermCriteria cv::ml::SVM::getTermCriteria()
  592. [DllImport (LIBNAME)]
  593. private static extern void ml_SVM_getTermCriteria_10 (IntPtr nativeObj, double[] retVal);
  594. // C++: bool cv::ml::SVM::trainAuto(Mat samples, int layout, Mat responses, int kFold = 10, Ptr_ParamGrid Cgrid = SVM::getDefaultGridPtr(SVM::C), Ptr_ParamGrid gammaGrid = SVM::getDefaultGridPtr(SVM::GAMMA), Ptr_ParamGrid pGrid = SVM::getDefaultGridPtr(SVM::P), Ptr_ParamGrid nuGrid = SVM::getDefaultGridPtr(SVM::NU), Ptr_ParamGrid coeffGrid = SVM::getDefaultGridPtr(SVM::COEF), Ptr_ParamGrid degreeGrid = SVM::getDefaultGridPtr(SVM::DEGREE), bool balanced = false)
  595. [DllImport (LIBNAME)]
  596. private static extern bool ml_SVM_trainAuto_10 (IntPtr nativeObj, IntPtr samples_nativeObj, int layout, IntPtr responses_nativeObj, int kFold, IntPtr Cgrid_nativeObj, IntPtr gammaGrid_nativeObj, IntPtr pGrid_nativeObj, IntPtr nuGrid_nativeObj, IntPtr coeffGrid_nativeObj, IntPtr degreeGrid_nativeObj, bool balanced);
  597. [DllImport (LIBNAME)]
  598. private static extern bool ml_SVM_trainAuto_11 (IntPtr nativeObj, IntPtr samples_nativeObj, int layout, IntPtr responses_nativeObj, int kFold, IntPtr Cgrid_nativeObj, IntPtr gammaGrid_nativeObj, IntPtr pGrid_nativeObj, IntPtr nuGrid_nativeObj, IntPtr coeffGrid_nativeObj, IntPtr degreeGrid_nativeObj);
  599. [DllImport (LIBNAME)]
  600. private static extern bool ml_SVM_trainAuto_12 (IntPtr nativeObj, IntPtr samples_nativeObj, int layout, IntPtr responses_nativeObj, int kFold, IntPtr Cgrid_nativeObj, IntPtr gammaGrid_nativeObj, IntPtr pGrid_nativeObj, IntPtr nuGrid_nativeObj, IntPtr coeffGrid_nativeObj);
  601. [DllImport (LIBNAME)]
  602. private static extern bool ml_SVM_trainAuto_13 (IntPtr nativeObj, IntPtr samples_nativeObj, int layout, IntPtr responses_nativeObj, int kFold, IntPtr Cgrid_nativeObj, IntPtr gammaGrid_nativeObj, IntPtr pGrid_nativeObj, IntPtr nuGrid_nativeObj);
  603. [DllImport (LIBNAME)]
  604. private static extern bool ml_SVM_trainAuto_14 (IntPtr nativeObj, IntPtr samples_nativeObj, int layout, IntPtr responses_nativeObj, int kFold, IntPtr Cgrid_nativeObj, IntPtr gammaGrid_nativeObj, IntPtr pGrid_nativeObj);
  605. [DllImport (LIBNAME)]
  606. private static extern bool ml_SVM_trainAuto_15 (IntPtr nativeObj, IntPtr samples_nativeObj, int layout, IntPtr responses_nativeObj, int kFold, IntPtr Cgrid_nativeObj, IntPtr gammaGrid_nativeObj);
  607. [DllImport (LIBNAME)]
  608. private static extern bool ml_SVM_trainAuto_16 (IntPtr nativeObj, IntPtr samples_nativeObj, int layout, IntPtr responses_nativeObj, int kFold, IntPtr Cgrid_nativeObj);
  609. [DllImport (LIBNAME)]
  610. private static extern bool ml_SVM_trainAuto_17 (IntPtr nativeObj, IntPtr samples_nativeObj, int layout, IntPtr responses_nativeObj, int kFold);
  611. [DllImport (LIBNAME)]
  612. private static extern bool ml_SVM_trainAuto_18 (IntPtr nativeObj, IntPtr samples_nativeObj, int layout, IntPtr responses_nativeObj);
  613. // C++: double cv::ml::SVM::getC()
  614. [DllImport (LIBNAME)]
  615. private static extern double ml_SVM_getC_10 (IntPtr nativeObj);
  616. // C++: double cv::ml::SVM::getCoef0()
  617. [DllImport (LIBNAME)]
  618. private static extern double ml_SVM_getCoef0_10 (IntPtr nativeObj);
  619. // C++: double cv::ml::SVM::getDecisionFunction(int i, Mat& alpha, Mat& svidx)
  620. [DllImport (LIBNAME)]
  621. private static extern double ml_SVM_getDecisionFunction_10 (IntPtr nativeObj, int i, IntPtr alpha_nativeObj, IntPtr svidx_nativeObj);
  622. // C++: double cv::ml::SVM::getDegree()
  623. [DllImport (LIBNAME)]
  624. private static extern double ml_SVM_getDegree_10 (IntPtr nativeObj);
  625. // C++: double cv::ml::SVM::getGamma()
  626. [DllImport (LIBNAME)]
  627. private static extern double ml_SVM_getGamma_10 (IntPtr nativeObj);
  628. // C++: double cv::ml::SVM::getNu()
  629. [DllImport (LIBNAME)]
  630. private static extern double ml_SVM_getNu_10 (IntPtr nativeObj);
  631. // C++: double cv::ml::SVM::getP()
  632. [DllImport (LIBNAME)]
  633. private static extern double ml_SVM_getP_10 (IntPtr nativeObj);
  634. // C++: int cv::ml::SVM::getKernelType()
  635. [DllImport (LIBNAME)]
  636. private static extern int ml_SVM_getKernelType_10 (IntPtr nativeObj);
  637. // C++: int cv::ml::SVM::getType()
  638. [DllImport (LIBNAME)]
  639. private static extern int ml_SVM_getType_10 (IntPtr nativeObj);
  640. // C++: void cv::ml::SVM::setC(double val)
  641. [DllImport (LIBNAME)]
  642. private static extern void ml_SVM_setC_10 (IntPtr nativeObj, double val);
  643. // C++: void cv::ml::SVM::setClassWeights(Mat val)
  644. [DllImport (LIBNAME)]
  645. private static extern void ml_SVM_setClassWeights_10 (IntPtr nativeObj, IntPtr val_nativeObj);
  646. // C++: void cv::ml::SVM::setCoef0(double val)
  647. [DllImport (LIBNAME)]
  648. private static extern void ml_SVM_setCoef0_10 (IntPtr nativeObj, double val);
  649. // C++: void cv::ml::SVM::setDegree(double val)
  650. [DllImport (LIBNAME)]
  651. private static extern void ml_SVM_setDegree_10 (IntPtr nativeObj, double val);
  652. // C++: void cv::ml::SVM::setGamma(double val)
  653. [DllImport (LIBNAME)]
  654. private static extern void ml_SVM_setGamma_10 (IntPtr nativeObj, double val);
  655. // C++: void cv::ml::SVM::setKernel(int kernelType)
  656. [DllImport (LIBNAME)]
  657. private static extern void ml_SVM_setKernel_10 (IntPtr nativeObj, int kernelType);
  658. // C++: void cv::ml::SVM::setNu(double val)
  659. [DllImport (LIBNAME)]
  660. private static extern void ml_SVM_setNu_10 (IntPtr nativeObj, double val);
  661. // C++: void cv::ml::SVM::setP(double val)
  662. [DllImport (LIBNAME)]
  663. private static extern void ml_SVM_setP_10 (IntPtr nativeObj, double val);
  664. // C++: void cv::ml::SVM::setTermCriteria(TermCriteria val)
  665. [DllImport (LIBNAME)]
  666. private static extern void ml_SVM_setTermCriteria_10 (IntPtr nativeObj, int val_type, int val_maxCount, double val_epsilon);
  667. // C++: void cv::ml::SVM::setType(int val)
  668. [DllImport (LIBNAME)]
  669. private static extern void ml_SVM_setType_10 (IntPtr nativeObj, int val);
  670. // native support for java finalize()
  671. [DllImport (LIBNAME)]
  672. private static extern void ml_SVM_delete (IntPtr nativeObj);
  673. }
  674. }