TrainData.cs 38 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108
  1. using OpenCVForUnity.CoreModule;
  2. using OpenCVForUnity.UtilsModule;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Runtime.InteropServices;
  6. namespace OpenCVForUnity.MlModule
  7. {
  8. // C++: class TrainData
  9. /**
  10. * Class encapsulating training data.
  11. *
  12. * Please note that the class only specifies the interface of training data, but not implementation.
  13. * All the statistical model classes in _ml_ module accepts Ptr<TrainData> as parameter. In other
  14. * words, you can create your own class derived from TrainData and pass smart pointer to the instance
  15. * of this class into StatModel::train.
  16. *
  17. * SEE: REF: ml_intro_data
  18. */
  19. public class TrainData : DisposableOpenCVObject
  20. {
  21. protected override void Dispose(bool disposing)
  22. {
  23. try
  24. {
  25. if (disposing)
  26. {
  27. }
  28. if (IsEnabledDispose)
  29. {
  30. if (nativeObj != IntPtr.Zero)
  31. ml_TrainData_delete(nativeObj);
  32. nativeObj = IntPtr.Zero;
  33. }
  34. }
  35. finally
  36. {
  37. base.Dispose(disposing);
  38. }
  39. }
  40. protected internal TrainData(IntPtr addr) : base(addr) { }
  41. public IntPtr getNativeObjAddr() { return nativeObj; }
  42. // internal usage only
  43. public static TrainData __fromPtr__(IntPtr addr) { return new TrainData(addr); }
  44. //
  45. // C++: int cv::ml::TrainData::getLayout()
  46. //
  47. public int getLayout()
  48. {
  49. ThrowIfDisposed();
  50. return ml_TrainData_getLayout_10(nativeObj);
  51. }
  52. //
  53. // C++: int cv::ml::TrainData::getNTrainSamples()
  54. //
  55. public int getNTrainSamples()
  56. {
  57. ThrowIfDisposed();
  58. return ml_TrainData_getNTrainSamples_10(nativeObj);
  59. }
  60. //
  61. // C++: int cv::ml::TrainData::getNTestSamples()
  62. //
  63. public int getNTestSamples()
  64. {
  65. ThrowIfDisposed();
  66. return ml_TrainData_getNTestSamples_10(nativeObj);
  67. }
  68. //
  69. // C++: int cv::ml::TrainData::getNSamples()
  70. //
  71. public int getNSamples()
  72. {
  73. ThrowIfDisposed();
  74. return ml_TrainData_getNSamples_10(nativeObj);
  75. }
  76. //
  77. // C++: int cv::ml::TrainData::getNVars()
  78. //
  79. public int getNVars()
  80. {
  81. ThrowIfDisposed();
  82. return ml_TrainData_getNVars_10(nativeObj);
  83. }
  84. //
  85. // C++: int cv::ml::TrainData::getNAllVars()
  86. //
  87. public int getNAllVars()
  88. {
  89. ThrowIfDisposed();
  90. return ml_TrainData_getNAllVars_10(nativeObj);
  91. }
  92. //
  93. // C++: void cv::ml::TrainData::getSample(Mat varIdx, int sidx, float* buf)
  94. //
  95. public void getSample(Mat varIdx, int sidx, float buf)
  96. {
  97. ThrowIfDisposed();
  98. if (varIdx != null) varIdx.ThrowIfDisposed();
  99. ml_TrainData_getSample_10(nativeObj, varIdx.nativeObj, sidx, buf);
  100. }
  101. //
  102. // C++: Mat cv::ml::TrainData::getSamples()
  103. //
  104. public Mat getSamples()
  105. {
  106. ThrowIfDisposed();
  107. return new Mat(DisposableObject.ThrowIfNullIntPtr(ml_TrainData_getSamples_10(nativeObj)));
  108. }
  109. //
  110. // C++: Mat cv::ml::TrainData::getMissing()
  111. //
  112. public Mat getMissing()
  113. {
  114. ThrowIfDisposed();
  115. return new Mat(DisposableObject.ThrowIfNullIntPtr(ml_TrainData_getMissing_10(nativeObj)));
  116. }
  117. //
  118. // C++: Mat cv::ml::TrainData::getTrainSamples(int layout = ROW_SAMPLE, bool compressSamples = true, bool compressVars = true)
  119. //
  120. /**
  121. * Returns matrix of train samples
  122. *
  123. * param layout The requested layout. If it's different from the initial one, the matrix is
  124. * transposed. See ml::SampleTypes.
  125. * param compressSamples if true, the function returns only the training samples (specified by
  126. * sampleIdx)
  127. * param compressVars if true, the function returns the shorter training samples, containing only
  128. * the active variables.
  129. *
  130. * In current implementation the function tries to avoid physical data copying and returns the
  131. * matrix stored inside TrainData (unless the transposition or compression is needed).
  132. * return automatically generated
  133. */
  134. public Mat getTrainSamples(int layout, bool compressSamples, bool compressVars)
  135. {
  136. ThrowIfDisposed();
  137. return new Mat(DisposableObject.ThrowIfNullIntPtr(ml_TrainData_getTrainSamples_10(nativeObj, layout, compressSamples, compressVars)));
  138. }
  139. /**
  140. * Returns matrix of train samples
  141. *
  142. * param layout The requested layout. If it's different from the initial one, the matrix is
  143. * transposed. See ml::SampleTypes.
  144. * param compressSamples if true, the function returns only the training samples (specified by
  145. * sampleIdx)
  146. * the active variables.
  147. *
  148. * In current implementation the function tries to avoid physical data copying and returns the
  149. * matrix stored inside TrainData (unless the transposition or compression is needed).
  150. * return automatically generated
  151. */
  152. public Mat getTrainSamples(int layout, bool compressSamples)
  153. {
  154. ThrowIfDisposed();
  155. return new Mat(DisposableObject.ThrowIfNullIntPtr(ml_TrainData_getTrainSamples_11(nativeObj, layout, compressSamples)));
  156. }
  157. /**
  158. * Returns matrix of train samples
  159. *
  160. * param layout The requested layout. If it's different from the initial one, the matrix is
  161. * transposed. See ml::SampleTypes.
  162. * sampleIdx)
  163. * the active variables.
  164. *
  165. * In current implementation the function tries to avoid physical data copying and returns the
  166. * matrix stored inside TrainData (unless the transposition or compression is needed).
  167. * return automatically generated
  168. */
  169. public Mat getTrainSamples(int layout)
  170. {
  171. ThrowIfDisposed();
  172. return new Mat(DisposableObject.ThrowIfNullIntPtr(ml_TrainData_getTrainSamples_12(nativeObj, layout)));
  173. }
  174. /**
  175. * Returns matrix of train samples
  176. *
  177. * transposed. See ml::SampleTypes.
  178. * sampleIdx)
  179. * the active variables.
  180. *
  181. * In current implementation the function tries to avoid physical data copying and returns the
  182. * matrix stored inside TrainData (unless the transposition or compression is needed).
  183. * return automatically generated
  184. */
  185. public Mat getTrainSamples()
  186. {
  187. ThrowIfDisposed();
  188. return new Mat(DisposableObject.ThrowIfNullIntPtr(ml_TrainData_getTrainSamples_13(nativeObj)));
  189. }
  190. //
  191. // C++: Mat cv::ml::TrainData::getTrainResponses()
  192. //
  193. /**
  194. * Returns the vector of responses
  195. *
  196. * The function returns ordered or the original categorical responses. Usually it's used in
  197. * regression algorithms.
  198. * return automatically generated
  199. */
  200. public Mat getTrainResponses()
  201. {
  202. ThrowIfDisposed();
  203. return new Mat(DisposableObject.ThrowIfNullIntPtr(ml_TrainData_getTrainResponses_10(nativeObj)));
  204. }
  205. //
  206. // C++: Mat cv::ml::TrainData::getTrainNormCatResponses()
  207. //
  208. /**
  209. * Returns the vector of normalized categorical responses
  210. *
  211. * The function returns vector of responses. Each response is integer from {code 0} to `<number of
  212. * classes>-1`. The actual label value can be retrieved then from the class label vector, see
  213. * TrainData::getClassLabels.
  214. * return automatically generated
  215. */
  216. public Mat getTrainNormCatResponses()
  217. {
  218. ThrowIfDisposed();
  219. return new Mat(DisposableObject.ThrowIfNullIntPtr(ml_TrainData_getTrainNormCatResponses_10(nativeObj)));
  220. }
  221. //
  222. // C++: Mat cv::ml::TrainData::getTestResponses()
  223. //
  224. public Mat getTestResponses()
  225. {
  226. ThrowIfDisposed();
  227. return new Mat(DisposableObject.ThrowIfNullIntPtr(ml_TrainData_getTestResponses_10(nativeObj)));
  228. }
  229. //
  230. // C++: Mat cv::ml::TrainData::getTestNormCatResponses()
  231. //
  232. public Mat getTestNormCatResponses()
  233. {
  234. ThrowIfDisposed();
  235. return new Mat(DisposableObject.ThrowIfNullIntPtr(ml_TrainData_getTestNormCatResponses_10(nativeObj)));
  236. }
  237. //
  238. // C++: Mat cv::ml::TrainData::getResponses()
  239. //
  240. public Mat getResponses()
  241. {
  242. ThrowIfDisposed();
  243. return new Mat(DisposableObject.ThrowIfNullIntPtr(ml_TrainData_getResponses_10(nativeObj)));
  244. }
  245. //
  246. // C++: Mat cv::ml::TrainData::getNormCatResponses()
  247. //
  248. public Mat getNormCatResponses()
  249. {
  250. ThrowIfDisposed();
  251. return new Mat(DisposableObject.ThrowIfNullIntPtr(ml_TrainData_getNormCatResponses_10(nativeObj)));
  252. }
  253. //
  254. // C++: Mat cv::ml::TrainData::getSampleWeights()
  255. //
  256. public Mat getSampleWeights()
  257. {
  258. ThrowIfDisposed();
  259. return new Mat(DisposableObject.ThrowIfNullIntPtr(ml_TrainData_getSampleWeights_10(nativeObj)));
  260. }
  261. //
  262. // C++: Mat cv::ml::TrainData::getTrainSampleWeights()
  263. //
  264. public Mat getTrainSampleWeights()
  265. {
  266. ThrowIfDisposed();
  267. return new Mat(DisposableObject.ThrowIfNullIntPtr(ml_TrainData_getTrainSampleWeights_10(nativeObj)));
  268. }
  269. //
  270. // C++: Mat cv::ml::TrainData::getTestSampleWeights()
  271. //
  272. public Mat getTestSampleWeights()
  273. {
  274. ThrowIfDisposed();
  275. return new Mat(DisposableObject.ThrowIfNullIntPtr(ml_TrainData_getTestSampleWeights_10(nativeObj)));
  276. }
  277. //
  278. // C++: Mat cv::ml::TrainData::getVarIdx()
  279. //
  280. public Mat getVarIdx()
  281. {
  282. ThrowIfDisposed();
  283. return new Mat(DisposableObject.ThrowIfNullIntPtr(ml_TrainData_getVarIdx_10(nativeObj)));
  284. }
  285. //
  286. // C++: Mat cv::ml::TrainData::getVarType()
  287. //
  288. public Mat getVarType()
  289. {
  290. ThrowIfDisposed();
  291. return new Mat(DisposableObject.ThrowIfNullIntPtr(ml_TrainData_getVarType_10(nativeObj)));
  292. }
  293. //
  294. // C++: Mat cv::ml::TrainData::getVarSymbolFlags()
  295. //
  296. public Mat getVarSymbolFlags()
  297. {
  298. ThrowIfDisposed();
  299. return new Mat(DisposableObject.ThrowIfNullIntPtr(ml_TrainData_getVarSymbolFlags_10(nativeObj)));
  300. }
  301. //
  302. // C++: int cv::ml::TrainData::getResponseType()
  303. //
  304. public int getResponseType()
  305. {
  306. ThrowIfDisposed();
  307. return ml_TrainData_getResponseType_10(nativeObj);
  308. }
  309. //
  310. // C++: Mat cv::ml::TrainData::getTrainSampleIdx()
  311. //
  312. public Mat getTrainSampleIdx()
  313. {
  314. ThrowIfDisposed();
  315. return new Mat(DisposableObject.ThrowIfNullIntPtr(ml_TrainData_getTrainSampleIdx_10(nativeObj)));
  316. }
  317. //
  318. // C++: Mat cv::ml::TrainData::getTestSampleIdx()
  319. //
  320. public Mat getTestSampleIdx()
  321. {
  322. ThrowIfDisposed();
  323. return new Mat(DisposableObject.ThrowIfNullIntPtr(ml_TrainData_getTestSampleIdx_10(nativeObj)));
  324. }
  325. //
  326. // C++: void cv::ml::TrainData::getValues(int vi, Mat sidx, float* values)
  327. //
  328. public void getValues(int vi, Mat sidx, float values)
  329. {
  330. ThrowIfDisposed();
  331. if (sidx != null) sidx.ThrowIfDisposed();
  332. ml_TrainData_getValues_10(nativeObj, vi, sidx.nativeObj, values);
  333. }
  334. //
  335. // C++: Mat cv::ml::TrainData::getDefaultSubstValues()
  336. //
  337. public Mat getDefaultSubstValues()
  338. {
  339. ThrowIfDisposed();
  340. return new Mat(DisposableObject.ThrowIfNullIntPtr(ml_TrainData_getDefaultSubstValues_10(nativeObj)));
  341. }
  342. //
  343. // C++: int cv::ml::TrainData::getCatCount(int vi)
  344. //
  345. public int getCatCount(int vi)
  346. {
  347. ThrowIfDisposed();
  348. return ml_TrainData_getCatCount_10(nativeObj, vi);
  349. }
  350. //
  351. // C++: Mat cv::ml::TrainData::getClassLabels()
  352. //
  353. /**
  354. * Returns the vector of class labels
  355. *
  356. * The function returns vector of unique labels occurred in the responses.
  357. * return automatically generated
  358. */
  359. public Mat getClassLabels()
  360. {
  361. ThrowIfDisposed();
  362. return new Mat(DisposableObject.ThrowIfNullIntPtr(ml_TrainData_getClassLabels_10(nativeObj)));
  363. }
  364. //
  365. // C++: Mat cv::ml::TrainData::getCatOfs()
  366. //
  367. public Mat getCatOfs()
  368. {
  369. ThrowIfDisposed();
  370. return new Mat(DisposableObject.ThrowIfNullIntPtr(ml_TrainData_getCatOfs_10(nativeObj)));
  371. }
  372. //
  373. // C++: Mat cv::ml::TrainData::getCatMap()
  374. //
  375. public Mat getCatMap()
  376. {
  377. ThrowIfDisposed();
  378. return new Mat(DisposableObject.ThrowIfNullIntPtr(ml_TrainData_getCatMap_10(nativeObj)));
  379. }
  380. //
  381. // C++: void cv::ml::TrainData::setTrainTestSplit(int count, bool shuffle = true)
  382. //
  383. /**
  384. * Splits the training data into the training and test parts
  385. * SEE: TrainData::setTrainTestSplitRatio
  386. * param count automatically generated
  387. * param shuffle automatically generated
  388. */
  389. public void setTrainTestSplit(int count, bool shuffle)
  390. {
  391. ThrowIfDisposed();
  392. ml_TrainData_setTrainTestSplit_10(nativeObj, count, shuffle);
  393. }
  394. /**
  395. * Splits the training data into the training and test parts
  396. * SEE: TrainData::setTrainTestSplitRatio
  397. * param count automatically generated
  398. */
  399. public void setTrainTestSplit(int count)
  400. {
  401. ThrowIfDisposed();
  402. ml_TrainData_setTrainTestSplit_11(nativeObj, count);
  403. }
  404. //
  405. // C++: void cv::ml::TrainData::setTrainTestSplitRatio(double ratio, bool shuffle = true)
  406. //
  407. /**
  408. * Splits the training data into the training and test parts
  409. *
  410. * The function selects a subset of specified relative size and then returns it as the training
  411. * set. If the function is not called, all the data is used for training. Please, note that for
  412. * each of TrainData::getTrain\* there is corresponding TrainData::getTest\*, so that the test
  413. * subset can be retrieved and processed as well.
  414. * SEE: TrainData::setTrainTestSplit
  415. * param ratio automatically generated
  416. * param shuffle automatically generated
  417. */
  418. public void setTrainTestSplitRatio(double ratio, bool shuffle)
  419. {
  420. ThrowIfDisposed();
  421. ml_TrainData_setTrainTestSplitRatio_10(nativeObj, ratio, shuffle);
  422. }
  423. /**
  424. * Splits the training data into the training and test parts
  425. *
  426. * The function selects a subset of specified relative size and then returns it as the training
  427. * set. If the function is not called, all the data is used for training. Please, note that for
  428. * each of TrainData::getTrain\* there is corresponding TrainData::getTest\*, so that the test
  429. * subset can be retrieved and processed as well.
  430. * SEE: TrainData::setTrainTestSplit
  431. * param ratio automatically generated
  432. */
  433. public void setTrainTestSplitRatio(double ratio)
  434. {
  435. ThrowIfDisposed();
  436. ml_TrainData_setTrainTestSplitRatio_11(nativeObj, ratio);
  437. }
  438. //
  439. // C++: void cv::ml::TrainData::shuffleTrainTest()
  440. //
  441. public void shuffleTrainTest()
  442. {
  443. ThrowIfDisposed();
  444. ml_TrainData_shuffleTrainTest_10(nativeObj);
  445. }
  446. //
  447. // C++: Mat cv::ml::TrainData::getTestSamples()
  448. //
  449. /**
  450. * Returns matrix of test samples
  451. * return automatically generated
  452. */
  453. public Mat getTestSamples()
  454. {
  455. ThrowIfDisposed();
  456. return new Mat(DisposableObject.ThrowIfNullIntPtr(ml_TrainData_getTestSamples_10(nativeObj)));
  457. }
  458. //
  459. // C++: void cv::ml::TrainData::getNames(vector_String names)
  460. //
  461. /**
  462. * Returns vector of symbolic names captured in loadFromCSV()
  463. * param names automatically generated
  464. */
  465. public void getNames(List<string> names)
  466. {
  467. ThrowIfDisposed();
  468. Mat names_mat = Converters.vector_String_to_Mat(names);
  469. ml_TrainData_getNames_10(nativeObj, names_mat.nativeObj);
  470. }
  471. //
  472. // C++: static Mat cv::ml::TrainData::getSubVector(Mat vec, Mat idx)
  473. //
  474. /**
  475. * Extract from 1D vector elements specified by passed indexes.
  476. * param vec input vector (supported types: CV_32S, CV_32F, CV_64F)
  477. * param idx 1D index vector
  478. * return automatically generated
  479. */
  480. public static Mat getSubVector(Mat vec, Mat idx)
  481. {
  482. if (vec != null) vec.ThrowIfDisposed();
  483. if (idx != null) idx.ThrowIfDisposed();
  484. return new Mat(DisposableObject.ThrowIfNullIntPtr(ml_TrainData_getSubVector_10(vec.nativeObj, idx.nativeObj)));
  485. }
  486. //
  487. // C++: static Mat cv::ml::TrainData::getSubMatrix(Mat matrix, Mat idx, int layout)
  488. //
  489. /**
  490. * Extract from matrix rows/cols specified by passed indexes.
  491. * param matrix input matrix (supported types: CV_32S, CV_32F, CV_64F)
  492. * param idx 1D index vector
  493. * param layout specifies to extract rows (cv::ml::ROW_SAMPLES) or to extract columns (cv::ml::COL_SAMPLES)
  494. * return automatically generated
  495. */
  496. public static Mat getSubMatrix(Mat matrix, Mat idx, int layout)
  497. {
  498. if (matrix != null) matrix.ThrowIfDisposed();
  499. if (idx != null) idx.ThrowIfDisposed();
  500. return new Mat(DisposableObject.ThrowIfNullIntPtr(ml_TrainData_getSubMatrix_10(matrix.nativeObj, idx.nativeObj, layout)));
  501. }
  502. //
  503. // C++: static Ptr_TrainData cv::ml::TrainData::create(Mat samples, int layout, Mat responses, Mat varIdx = Mat(), Mat sampleIdx = Mat(), Mat sampleWeights = Mat(), Mat varType = Mat())
  504. //
  505. /**
  506. * Creates training data from in-memory arrays.
  507. *
  508. * param samples matrix of samples. It should have CV_32F type.
  509. * param layout see ml::SampleTypes.
  510. * param responses matrix of responses. If the responses are scalar, they should be stored as a
  511. * single row or as a single column. The matrix should have type CV_32F or CV_32S (in the
  512. * former case the responses are considered as ordered by default; in the latter case - as
  513. * categorical)
  514. * param varIdx vector specifying which variables to use for training. It can be an integer vector
  515. * (CV_32S) containing 0-based variable indices or byte vector (CV_8U) containing a mask of
  516. * active variables.
  517. * param sampleIdx vector specifying which samples to use for training. It can be an integer
  518. * vector (CV_32S) containing 0-based sample indices or byte vector (CV_8U) containing a mask
  519. * of training samples.
  520. * param sampleWeights optional vector with weights for each sample. It should have CV_32F type.
  521. * param varType optional vector of type CV_8U and size `&lt;number_of_variables_in_samples&gt; +
  522. * &lt;number_of_variables_in_responses&gt;`, containing types of each input and output variable. See
  523. * ml::VariableTypes.
  524. * return automatically generated
  525. */
  526. public static TrainData create(Mat samples, int layout, Mat responses, Mat varIdx, Mat sampleIdx, Mat sampleWeights, Mat varType)
  527. {
  528. if (samples != null) samples.ThrowIfDisposed();
  529. if (responses != null) responses.ThrowIfDisposed();
  530. if (varIdx != null) varIdx.ThrowIfDisposed();
  531. if (sampleIdx != null) sampleIdx.ThrowIfDisposed();
  532. if (sampleWeights != null) sampleWeights.ThrowIfDisposed();
  533. if (varType != null) varType.ThrowIfDisposed();
  534. return TrainData.__fromPtr__(DisposableObject.ThrowIfNullIntPtr(ml_TrainData_create_10(samples.nativeObj, layout, responses.nativeObj, varIdx.nativeObj, sampleIdx.nativeObj, sampleWeights.nativeObj, varType.nativeObj)));
  535. }
  536. /**
  537. * Creates training data from in-memory arrays.
  538. *
  539. * param samples matrix of samples. It should have CV_32F type.
  540. * param layout see ml::SampleTypes.
  541. * param responses matrix of responses. If the responses are scalar, they should be stored as a
  542. * single row or as a single column. The matrix should have type CV_32F or CV_32S (in the
  543. * former case the responses are considered as ordered by default; in the latter case - as
  544. * categorical)
  545. * param varIdx vector specifying which variables to use for training. It can be an integer vector
  546. * (CV_32S) containing 0-based variable indices or byte vector (CV_8U) containing a mask of
  547. * active variables.
  548. * param sampleIdx vector specifying which samples to use for training. It can be an integer
  549. * vector (CV_32S) containing 0-based sample indices or byte vector (CV_8U) containing a mask
  550. * of training samples.
  551. * param sampleWeights optional vector with weights for each sample. It should have CV_32F type.
  552. * &lt;number_of_variables_in_responses&gt;`, containing types of each input and output variable. See
  553. * ml::VariableTypes.
  554. * return automatically generated
  555. */
  556. public static TrainData create(Mat samples, int layout, Mat responses, Mat varIdx, Mat sampleIdx, Mat sampleWeights)
  557. {
  558. if (samples != null) samples.ThrowIfDisposed();
  559. if (responses != null) responses.ThrowIfDisposed();
  560. if (varIdx != null) varIdx.ThrowIfDisposed();
  561. if (sampleIdx != null) sampleIdx.ThrowIfDisposed();
  562. if (sampleWeights != null) sampleWeights.ThrowIfDisposed();
  563. return TrainData.__fromPtr__(DisposableObject.ThrowIfNullIntPtr(ml_TrainData_create_11(samples.nativeObj, layout, responses.nativeObj, varIdx.nativeObj, sampleIdx.nativeObj, sampleWeights.nativeObj)));
  564. }
  565. /**
  566. * Creates training data from in-memory arrays.
  567. *
  568. * param samples matrix of samples. It should have CV_32F type.
  569. * param layout see ml::SampleTypes.
  570. * param responses matrix of responses. If the responses are scalar, they should be stored as a
  571. * single row or as a single column. The matrix should have type CV_32F or CV_32S (in the
  572. * former case the responses are considered as ordered by default; in the latter case - as
  573. * categorical)
  574. * param varIdx vector specifying which variables to use for training. It can be an integer vector
  575. * (CV_32S) containing 0-based variable indices or byte vector (CV_8U) containing a mask of
  576. * active variables.
  577. * param sampleIdx vector specifying which samples to use for training. It can be an integer
  578. * vector (CV_32S) containing 0-based sample indices or byte vector (CV_8U) containing a mask
  579. * of training samples.
  580. * &lt;number_of_variables_in_responses&gt;`, containing types of each input and output variable. See
  581. * ml::VariableTypes.
  582. * return automatically generated
  583. */
  584. public static TrainData create(Mat samples, int layout, Mat responses, Mat varIdx, Mat sampleIdx)
  585. {
  586. if (samples != null) samples.ThrowIfDisposed();
  587. if (responses != null) responses.ThrowIfDisposed();
  588. if (varIdx != null) varIdx.ThrowIfDisposed();
  589. if (sampleIdx != null) sampleIdx.ThrowIfDisposed();
  590. return TrainData.__fromPtr__(DisposableObject.ThrowIfNullIntPtr(ml_TrainData_create_12(samples.nativeObj, layout, responses.nativeObj, varIdx.nativeObj, sampleIdx.nativeObj)));
  591. }
  592. /**
  593. * Creates training data from in-memory arrays.
  594. *
  595. * param samples matrix of samples. It should have CV_32F type.
  596. * param layout see ml::SampleTypes.
  597. * param responses matrix of responses. If the responses are scalar, they should be stored as a
  598. * single row or as a single column. The matrix should have type CV_32F or CV_32S (in the
  599. * former case the responses are considered as ordered by default; in the latter case - as
  600. * categorical)
  601. * param varIdx vector specifying which variables to use for training. It can be an integer vector
  602. * (CV_32S) containing 0-based variable indices or byte vector (CV_8U) containing a mask of
  603. * active variables.
  604. * vector (CV_32S) containing 0-based sample indices or byte vector (CV_8U) containing a mask
  605. * of training samples.
  606. * &lt;number_of_variables_in_responses&gt;`, containing types of each input and output variable. See
  607. * ml::VariableTypes.
  608. * return automatically generated
  609. */
  610. public static TrainData create(Mat samples, int layout, Mat responses, Mat varIdx)
  611. {
  612. if (samples != null) samples.ThrowIfDisposed();
  613. if (responses != null) responses.ThrowIfDisposed();
  614. if (varIdx != null) varIdx.ThrowIfDisposed();
  615. return TrainData.__fromPtr__(DisposableObject.ThrowIfNullIntPtr(ml_TrainData_create_13(samples.nativeObj, layout, responses.nativeObj, varIdx.nativeObj)));
  616. }
  617. /**
  618. * Creates training data from in-memory arrays.
  619. *
  620. * param samples matrix of samples. It should have CV_32F type.
  621. * param layout see ml::SampleTypes.
  622. * param responses matrix of responses. If the responses are scalar, they should be stored as a
  623. * single row or as a single column. The matrix should have type CV_32F or CV_32S (in the
  624. * former case the responses are considered as ordered by default; in the latter case - as
  625. * categorical)
  626. * (CV_32S) containing 0-based variable indices or byte vector (CV_8U) containing a mask of
  627. * active variables.
  628. * vector (CV_32S) containing 0-based sample indices or byte vector (CV_8U) containing a mask
  629. * of training samples.
  630. * &lt;number_of_variables_in_responses&gt;`, containing types of each input and output variable. See
  631. * ml::VariableTypes.
  632. * return automatically generated
  633. */
  634. public static TrainData create(Mat samples, int layout, Mat responses)
  635. {
  636. if (samples != null) samples.ThrowIfDisposed();
  637. if (responses != null) responses.ThrowIfDisposed();
  638. return TrainData.__fromPtr__(DisposableObject.ThrowIfNullIntPtr(ml_TrainData_create_14(samples.nativeObj, layout, responses.nativeObj)));
  639. }
  640. #if (UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR
  641. const string LIBNAME = "__Internal";
  642. #else
  643. const string LIBNAME = "opencvforunity";
  644. #endif
  645. // C++: int cv::ml::TrainData::getLayout()
  646. [DllImport(LIBNAME)]
  647. private static extern int ml_TrainData_getLayout_10(IntPtr nativeObj);
  648. // C++: int cv::ml::TrainData::getNTrainSamples()
  649. [DllImport(LIBNAME)]
  650. private static extern int ml_TrainData_getNTrainSamples_10(IntPtr nativeObj);
  651. // C++: int cv::ml::TrainData::getNTestSamples()
  652. [DllImport(LIBNAME)]
  653. private static extern int ml_TrainData_getNTestSamples_10(IntPtr nativeObj);
  654. // C++: int cv::ml::TrainData::getNSamples()
  655. [DllImport(LIBNAME)]
  656. private static extern int ml_TrainData_getNSamples_10(IntPtr nativeObj);
  657. // C++: int cv::ml::TrainData::getNVars()
  658. [DllImport(LIBNAME)]
  659. private static extern int ml_TrainData_getNVars_10(IntPtr nativeObj);
  660. // C++: int cv::ml::TrainData::getNAllVars()
  661. [DllImport(LIBNAME)]
  662. private static extern int ml_TrainData_getNAllVars_10(IntPtr nativeObj);
  663. // C++: void cv::ml::TrainData::getSample(Mat varIdx, int sidx, float* buf)
  664. [DllImport(LIBNAME)]
  665. private static extern void ml_TrainData_getSample_10(IntPtr nativeObj, IntPtr varIdx_nativeObj, int sidx, float buf);
  666. // C++: Mat cv::ml::TrainData::getSamples()
  667. [DllImport(LIBNAME)]
  668. private static extern IntPtr ml_TrainData_getSamples_10(IntPtr nativeObj);
  669. // C++: Mat cv::ml::TrainData::getMissing()
  670. [DllImport(LIBNAME)]
  671. private static extern IntPtr ml_TrainData_getMissing_10(IntPtr nativeObj);
  672. // C++: Mat cv::ml::TrainData::getTrainSamples(int layout = ROW_SAMPLE, bool compressSamples = true, bool compressVars = true)
  673. [DllImport(LIBNAME)]
  674. private static extern IntPtr ml_TrainData_getTrainSamples_10(IntPtr nativeObj, int layout, [MarshalAs(UnmanagedType.U1)] bool compressSamples, [MarshalAs(UnmanagedType.U1)] bool compressVars);
  675. [DllImport(LIBNAME)]
  676. private static extern IntPtr ml_TrainData_getTrainSamples_11(IntPtr nativeObj, int layout, [MarshalAs(UnmanagedType.U1)] bool compressSamples);
  677. [DllImport(LIBNAME)]
  678. private static extern IntPtr ml_TrainData_getTrainSamples_12(IntPtr nativeObj, int layout);
  679. [DllImport(LIBNAME)]
  680. private static extern IntPtr ml_TrainData_getTrainSamples_13(IntPtr nativeObj);
  681. // C++: Mat cv::ml::TrainData::getTrainResponses()
  682. [DllImport(LIBNAME)]
  683. private static extern IntPtr ml_TrainData_getTrainResponses_10(IntPtr nativeObj);
  684. // C++: Mat cv::ml::TrainData::getTrainNormCatResponses()
  685. [DllImport(LIBNAME)]
  686. private static extern IntPtr ml_TrainData_getTrainNormCatResponses_10(IntPtr nativeObj);
  687. // C++: Mat cv::ml::TrainData::getTestResponses()
  688. [DllImport(LIBNAME)]
  689. private static extern IntPtr ml_TrainData_getTestResponses_10(IntPtr nativeObj);
  690. // C++: Mat cv::ml::TrainData::getTestNormCatResponses()
  691. [DllImport(LIBNAME)]
  692. private static extern IntPtr ml_TrainData_getTestNormCatResponses_10(IntPtr nativeObj);
  693. // C++: Mat cv::ml::TrainData::getResponses()
  694. [DllImport(LIBNAME)]
  695. private static extern IntPtr ml_TrainData_getResponses_10(IntPtr nativeObj);
  696. // C++: Mat cv::ml::TrainData::getNormCatResponses()
  697. [DllImport(LIBNAME)]
  698. private static extern IntPtr ml_TrainData_getNormCatResponses_10(IntPtr nativeObj);
  699. // C++: Mat cv::ml::TrainData::getSampleWeights()
  700. [DllImport(LIBNAME)]
  701. private static extern IntPtr ml_TrainData_getSampleWeights_10(IntPtr nativeObj);
  702. // C++: Mat cv::ml::TrainData::getTrainSampleWeights()
  703. [DllImport(LIBNAME)]
  704. private static extern IntPtr ml_TrainData_getTrainSampleWeights_10(IntPtr nativeObj);
  705. // C++: Mat cv::ml::TrainData::getTestSampleWeights()
  706. [DllImport(LIBNAME)]
  707. private static extern IntPtr ml_TrainData_getTestSampleWeights_10(IntPtr nativeObj);
  708. // C++: Mat cv::ml::TrainData::getVarIdx()
  709. [DllImport(LIBNAME)]
  710. private static extern IntPtr ml_TrainData_getVarIdx_10(IntPtr nativeObj);
  711. // C++: Mat cv::ml::TrainData::getVarType()
  712. [DllImport(LIBNAME)]
  713. private static extern IntPtr ml_TrainData_getVarType_10(IntPtr nativeObj);
  714. // C++: Mat cv::ml::TrainData::getVarSymbolFlags()
  715. [DllImport(LIBNAME)]
  716. private static extern IntPtr ml_TrainData_getVarSymbolFlags_10(IntPtr nativeObj);
  717. // C++: int cv::ml::TrainData::getResponseType()
  718. [DllImport(LIBNAME)]
  719. private static extern int ml_TrainData_getResponseType_10(IntPtr nativeObj);
  720. // C++: Mat cv::ml::TrainData::getTrainSampleIdx()
  721. [DllImport(LIBNAME)]
  722. private static extern IntPtr ml_TrainData_getTrainSampleIdx_10(IntPtr nativeObj);
  723. // C++: Mat cv::ml::TrainData::getTestSampleIdx()
  724. [DllImport(LIBNAME)]
  725. private static extern IntPtr ml_TrainData_getTestSampleIdx_10(IntPtr nativeObj);
  726. // C++: void cv::ml::TrainData::getValues(int vi, Mat sidx, float* values)
  727. [DllImport(LIBNAME)]
  728. private static extern void ml_TrainData_getValues_10(IntPtr nativeObj, int vi, IntPtr sidx_nativeObj, float values);
  729. // C++: Mat cv::ml::TrainData::getDefaultSubstValues()
  730. [DllImport(LIBNAME)]
  731. private static extern IntPtr ml_TrainData_getDefaultSubstValues_10(IntPtr nativeObj);
  732. // C++: int cv::ml::TrainData::getCatCount(int vi)
  733. [DllImport(LIBNAME)]
  734. private static extern int ml_TrainData_getCatCount_10(IntPtr nativeObj, int vi);
  735. // C++: Mat cv::ml::TrainData::getClassLabels()
  736. [DllImport(LIBNAME)]
  737. private static extern IntPtr ml_TrainData_getClassLabels_10(IntPtr nativeObj);
  738. // C++: Mat cv::ml::TrainData::getCatOfs()
  739. [DllImport(LIBNAME)]
  740. private static extern IntPtr ml_TrainData_getCatOfs_10(IntPtr nativeObj);
  741. // C++: Mat cv::ml::TrainData::getCatMap()
  742. [DllImport(LIBNAME)]
  743. private static extern IntPtr ml_TrainData_getCatMap_10(IntPtr nativeObj);
  744. // C++: void cv::ml::TrainData::setTrainTestSplit(int count, bool shuffle = true)
  745. [DllImport(LIBNAME)]
  746. private static extern void ml_TrainData_setTrainTestSplit_10(IntPtr nativeObj, int count, [MarshalAs(UnmanagedType.U1)] bool shuffle);
  747. [DllImport(LIBNAME)]
  748. private static extern void ml_TrainData_setTrainTestSplit_11(IntPtr nativeObj, int count);
  749. // C++: void cv::ml::TrainData::setTrainTestSplitRatio(double ratio, bool shuffle = true)
  750. [DllImport(LIBNAME)]
  751. private static extern void ml_TrainData_setTrainTestSplitRatio_10(IntPtr nativeObj, double ratio, [MarshalAs(UnmanagedType.U1)] bool shuffle);
  752. [DllImport(LIBNAME)]
  753. private static extern void ml_TrainData_setTrainTestSplitRatio_11(IntPtr nativeObj, double ratio);
  754. // C++: void cv::ml::TrainData::shuffleTrainTest()
  755. [DllImport(LIBNAME)]
  756. private static extern void ml_TrainData_shuffleTrainTest_10(IntPtr nativeObj);
  757. // C++: Mat cv::ml::TrainData::getTestSamples()
  758. [DllImport(LIBNAME)]
  759. private static extern IntPtr ml_TrainData_getTestSamples_10(IntPtr nativeObj);
  760. // C++: void cv::ml::TrainData::getNames(vector_String names)
  761. [DllImport(LIBNAME)]
  762. private static extern void ml_TrainData_getNames_10(IntPtr nativeObj, IntPtr names_mat_nativeObj);
  763. // C++: static Mat cv::ml::TrainData::getSubVector(Mat vec, Mat idx)
  764. [DllImport(LIBNAME)]
  765. private static extern IntPtr ml_TrainData_getSubVector_10(IntPtr vec_nativeObj, IntPtr idx_nativeObj);
  766. // C++: static Mat cv::ml::TrainData::getSubMatrix(Mat matrix, Mat idx, int layout)
  767. [DllImport(LIBNAME)]
  768. private static extern IntPtr ml_TrainData_getSubMatrix_10(IntPtr matrix_nativeObj, IntPtr idx_nativeObj, int layout);
  769. // C++: static Ptr_TrainData cv::ml::TrainData::create(Mat samples, int layout, Mat responses, Mat varIdx = Mat(), Mat sampleIdx = Mat(), Mat sampleWeights = Mat(), Mat varType = Mat())
  770. [DllImport(LIBNAME)]
  771. private static extern IntPtr ml_TrainData_create_10(IntPtr samples_nativeObj, int layout, IntPtr responses_nativeObj, IntPtr varIdx_nativeObj, IntPtr sampleIdx_nativeObj, IntPtr sampleWeights_nativeObj, IntPtr varType_nativeObj);
  772. [DllImport(LIBNAME)]
  773. private static extern IntPtr ml_TrainData_create_11(IntPtr samples_nativeObj, int layout, IntPtr responses_nativeObj, IntPtr varIdx_nativeObj, IntPtr sampleIdx_nativeObj, IntPtr sampleWeights_nativeObj);
  774. [DllImport(LIBNAME)]
  775. private static extern IntPtr ml_TrainData_create_12(IntPtr samples_nativeObj, int layout, IntPtr responses_nativeObj, IntPtr varIdx_nativeObj, IntPtr sampleIdx_nativeObj);
  776. [DllImport(LIBNAME)]
  777. private static extern IntPtr ml_TrainData_create_13(IntPtr samples_nativeObj, int layout, IntPtr responses_nativeObj, IntPtr varIdx_nativeObj);
  778. [DllImport(LIBNAME)]
  779. private static extern IntPtr ml_TrainData_create_14(IntPtr samples_nativeObj, int layout, IntPtr responses_nativeObj);
  780. // native support for java finalize()
  781. [DllImport(LIBNAME)]
  782. private static extern void ml_TrainData_delete(IntPtr nativeObj);
  783. }
  784. }