SVM.cs 27 KB

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