DTrees.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547
  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 DTrees
  9. /**
  10. * The class represents a single decision tree or a collection of decision trees.
  11. *
  12. * The current public interface of the class allows user to train only a single decision tree, however
  13. * the class is capable of storing multiple decision trees and using them for prediction (by summing
  14. * responses or using a voting schemes), and the derived from DTrees classes (such as RTrees and Boost)
  15. * use this capability to implement decision tree ensembles.
  16. *
  17. * SEE: REF: ml_intro_trees
  18. */
  19. public class DTrees : StatModel
  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_DTrees_delete(nativeObj);
  32. nativeObj = IntPtr.Zero;
  33. }
  34. }
  35. finally
  36. {
  37. base.Dispose(disposing);
  38. }
  39. }
  40. protected internal DTrees(IntPtr addr) : base(addr) { }
  41. // internal usage only
  42. public static new DTrees __fromPtr__(IntPtr addr) { return new DTrees(addr); }
  43. // C++: enum cv.ml.DTrees.Flags
  44. public const int PREDICT_AUTO = 0;
  45. public const int PREDICT_SUM = (1 << 8);
  46. public const int PREDICT_MAX_VOTE = (2 << 8);
  47. public const int PREDICT_MASK = (3 << 8);
  48. //
  49. // C++: int cv::ml::DTrees::getMaxCategories()
  50. //
  51. /**
  52. * SEE: setMaxCategories
  53. * return automatically generated
  54. */
  55. public int getMaxCategories()
  56. {
  57. ThrowIfDisposed();
  58. return ml_DTrees_getMaxCategories_10(nativeObj);
  59. }
  60. //
  61. // C++: void cv::ml::DTrees::setMaxCategories(int val)
  62. //
  63. /**
  64. * getMaxCategories SEE: getMaxCategories
  65. * param val automatically generated
  66. */
  67. public void setMaxCategories(int val)
  68. {
  69. ThrowIfDisposed();
  70. ml_DTrees_setMaxCategories_10(nativeObj, val);
  71. }
  72. //
  73. // C++: int cv::ml::DTrees::getMaxDepth()
  74. //
  75. /**
  76. * SEE: setMaxDepth
  77. * return automatically generated
  78. */
  79. public int getMaxDepth()
  80. {
  81. ThrowIfDisposed();
  82. return ml_DTrees_getMaxDepth_10(nativeObj);
  83. }
  84. //
  85. // C++: void cv::ml::DTrees::setMaxDepth(int val)
  86. //
  87. /**
  88. * getMaxDepth SEE: getMaxDepth
  89. * param val automatically generated
  90. */
  91. public void setMaxDepth(int val)
  92. {
  93. ThrowIfDisposed();
  94. ml_DTrees_setMaxDepth_10(nativeObj, val);
  95. }
  96. //
  97. // C++: int cv::ml::DTrees::getMinSampleCount()
  98. //
  99. /**
  100. * SEE: setMinSampleCount
  101. * return automatically generated
  102. */
  103. public int getMinSampleCount()
  104. {
  105. ThrowIfDisposed();
  106. return ml_DTrees_getMinSampleCount_10(nativeObj);
  107. }
  108. //
  109. // C++: void cv::ml::DTrees::setMinSampleCount(int val)
  110. //
  111. /**
  112. * getMinSampleCount SEE: getMinSampleCount
  113. * param val automatically generated
  114. */
  115. public void setMinSampleCount(int val)
  116. {
  117. ThrowIfDisposed();
  118. ml_DTrees_setMinSampleCount_10(nativeObj, val);
  119. }
  120. //
  121. // C++: int cv::ml::DTrees::getCVFolds()
  122. //
  123. /**
  124. * SEE: setCVFolds
  125. * return automatically generated
  126. */
  127. public int getCVFolds()
  128. {
  129. ThrowIfDisposed();
  130. return ml_DTrees_getCVFolds_10(nativeObj);
  131. }
  132. //
  133. // C++: void cv::ml::DTrees::setCVFolds(int val)
  134. //
  135. /**
  136. * getCVFolds SEE: getCVFolds
  137. * param val automatically generated
  138. */
  139. public void setCVFolds(int val)
  140. {
  141. ThrowIfDisposed();
  142. ml_DTrees_setCVFolds_10(nativeObj, val);
  143. }
  144. //
  145. // C++: bool cv::ml::DTrees::getUseSurrogates()
  146. //
  147. /**
  148. * SEE: setUseSurrogates
  149. * return automatically generated
  150. */
  151. public bool getUseSurrogates()
  152. {
  153. ThrowIfDisposed();
  154. return ml_DTrees_getUseSurrogates_10(nativeObj);
  155. }
  156. //
  157. // C++: void cv::ml::DTrees::setUseSurrogates(bool val)
  158. //
  159. /**
  160. * getUseSurrogates SEE: getUseSurrogates
  161. * param val automatically generated
  162. */
  163. public void setUseSurrogates(bool val)
  164. {
  165. ThrowIfDisposed();
  166. ml_DTrees_setUseSurrogates_10(nativeObj, val);
  167. }
  168. //
  169. // C++: bool cv::ml::DTrees::getUse1SERule()
  170. //
  171. /**
  172. * SEE: setUse1SERule
  173. * return automatically generated
  174. */
  175. public bool getUse1SERule()
  176. {
  177. ThrowIfDisposed();
  178. return ml_DTrees_getUse1SERule_10(nativeObj);
  179. }
  180. //
  181. // C++: void cv::ml::DTrees::setUse1SERule(bool val)
  182. //
  183. /**
  184. * getUse1SERule SEE: getUse1SERule
  185. * param val automatically generated
  186. */
  187. public void setUse1SERule(bool val)
  188. {
  189. ThrowIfDisposed();
  190. ml_DTrees_setUse1SERule_10(nativeObj, val);
  191. }
  192. //
  193. // C++: bool cv::ml::DTrees::getTruncatePrunedTree()
  194. //
  195. /**
  196. * SEE: setTruncatePrunedTree
  197. * return automatically generated
  198. */
  199. public bool getTruncatePrunedTree()
  200. {
  201. ThrowIfDisposed();
  202. return ml_DTrees_getTruncatePrunedTree_10(nativeObj);
  203. }
  204. //
  205. // C++: void cv::ml::DTrees::setTruncatePrunedTree(bool val)
  206. //
  207. /**
  208. * getTruncatePrunedTree SEE: getTruncatePrunedTree
  209. * param val automatically generated
  210. */
  211. public void setTruncatePrunedTree(bool val)
  212. {
  213. ThrowIfDisposed();
  214. ml_DTrees_setTruncatePrunedTree_10(nativeObj, val);
  215. }
  216. //
  217. // C++: float cv::ml::DTrees::getRegressionAccuracy()
  218. //
  219. /**
  220. * SEE: setRegressionAccuracy
  221. * return automatically generated
  222. */
  223. public float getRegressionAccuracy()
  224. {
  225. ThrowIfDisposed();
  226. return ml_DTrees_getRegressionAccuracy_10(nativeObj);
  227. }
  228. //
  229. // C++: void cv::ml::DTrees::setRegressionAccuracy(float val)
  230. //
  231. /**
  232. * getRegressionAccuracy SEE: getRegressionAccuracy
  233. * param val automatically generated
  234. */
  235. public void setRegressionAccuracy(float val)
  236. {
  237. ThrowIfDisposed();
  238. ml_DTrees_setRegressionAccuracy_10(nativeObj, val);
  239. }
  240. //
  241. // C++: Mat cv::ml::DTrees::getPriors()
  242. //
  243. /**
  244. * SEE: setPriors
  245. * return automatically generated
  246. */
  247. public Mat getPriors()
  248. {
  249. ThrowIfDisposed();
  250. return new Mat(DisposableObject.ThrowIfNullIntPtr(ml_DTrees_getPriors_10(nativeObj)));
  251. }
  252. //
  253. // C++: void cv::ml::DTrees::setPriors(Mat val)
  254. //
  255. /**
  256. * getPriors SEE: getPriors
  257. * param val automatically generated
  258. */
  259. public void setPriors(Mat val)
  260. {
  261. ThrowIfDisposed();
  262. if (val != null) val.ThrowIfDisposed();
  263. ml_DTrees_setPriors_10(nativeObj, val.nativeObj);
  264. }
  265. //
  266. // C++: static Ptr_DTrees cv::ml::DTrees::create()
  267. //
  268. /**
  269. * Creates the empty model
  270. *
  271. * The static method creates empty decision tree with the specified parameters. It should be then
  272. * trained using train method (see StatModel::train). Alternatively, you can load the model from
  273. * file using Algorithm::load&lt;DTrees&gt;(filename).
  274. * return automatically generated
  275. */
  276. public static DTrees create()
  277. {
  278. return DTrees.__fromPtr__(DisposableObject.ThrowIfNullIntPtr(ml_DTrees_create_10()));
  279. }
  280. //
  281. // C++: static Ptr_DTrees cv::ml::DTrees::load(String filepath, String nodeName = String())
  282. //
  283. /**
  284. * Loads and creates a serialized DTrees from a file
  285. *
  286. * Use DTree::save to serialize and store an DTree to disk.
  287. * Load the DTree from this file again, by calling this function with the path to the file.
  288. * Optionally specify the node for the file containing the classifier
  289. *
  290. * param filepath path to serialized DTree
  291. * param nodeName name of node containing the classifier
  292. * return automatically generated
  293. */
  294. public static DTrees load(string filepath, string nodeName)
  295. {
  296. return DTrees.__fromPtr__(DisposableObject.ThrowIfNullIntPtr(ml_DTrees_load_10(filepath, nodeName)));
  297. }
  298. /**
  299. * Loads and creates a serialized DTrees from a file
  300. *
  301. * Use DTree::save to serialize and store an DTree to disk.
  302. * Load the DTree from this file again, by calling this function with the path to the file.
  303. * Optionally specify the node for the file containing the classifier
  304. *
  305. * param filepath path to serialized DTree
  306. * return automatically generated
  307. */
  308. public static DTrees load(string filepath)
  309. {
  310. return DTrees.__fromPtr__(DisposableObject.ThrowIfNullIntPtr(ml_DTrees_load_11(filepath)));
  311. }
  312. #if (UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR
  313. const string LIBNAME = "__Internal";
  314. #else
  315. const string LIBNAME = "opencvforunity";
  316. #endif
  317. // C++: int cv::ml::DTrees::getMaxCategories()
  318. [DllImport(LIBNAME)]
  319. private static extern int ml_DTrees_getMaxCategories_10(IntPtr nativeObj);
  320. // C++: void cv::ml::DTrees::setMaxCategories(int val)
  321. [DllImport(LIBNAME)]
  322. private static extern void ml_DTrees_setMaxCategories_10(IntPtr nativeObj, int val);
  323. // C++: int cv::ml::DTrees::getMaxDepth()
  324. [DllImport(LIBNAME)]
  325. private static extern int ml_DTrees_getMaxDepth_10(IntPtr nativeObj);
  326. // C++: void cv::ml::DTrees::setMaxDepth(int val)
  327. [DllImport(LIBNAME)]
  328. private static extern void ml_DTrees_setMaxDepth_10(IntPtr nativeObj, int val);
  329. // C++: int cv::ml::DTrees::getMinSampleCount()
  330. [DllImport(LIBNAME)]
  331. private static extern int ml_DTrees_getMinSampleCount_10(IntPtr nativeObj);
  332. // C++: void cv::ml::DTrees::setMinSampleCount(int val)
  333. [DllImport(LIBNAME)]
  334. private static extern void ml_DTrees_setMinSampleCount_10(IntPtr nativeObj, int val);
  335. // C++: int cv::ml::DTrees::getCVFolds()
  336. [DllImport(LIBNAME)]
  337. private static extern int ml_DTrees_getCVFolds_10(IntPtr nativeObj);
  338. // C++: void cv::ml::DTrees::setCVFolds(int val)
  339. [DllImport(LIBNAME)]
  340. private static extern void ml_DTrees_setCVFolds_10(IntPtr nativeObj, int val);
  341. // C++: bool cv::ml::DTrees::getUseSurrogates()
  342. [DllImport(LIBNAME)]
  343. [return: MarshalAs(UnmanagedType.U1)]
  344. private static extern bool ml_DTrees_getUseSurrogates_10(IntPtr nativeObj);
  345. // C++: void cv::ml::DTrees::setUseSurrogates(bool val)
  346. [DllImport(LIBNAME)]
  347. private static extern void ml_DTrees_setUseSurrogates_10(IntPtr nativeObj, [MarshalAs(UnmanagedType.U1)] bool val);
  348. // C++: bool cv::ml::DTrees::getUse1SERule()
  349. [DllImport(LIBNAME)]
  350. [return: MarshalAs(UnmanagedType.U1)]
  351. private static extern bool ml_DTrees_getUse1SERule_10(IntPtr nativeObj);
  352. // C++: void cv::ml::DTrees::setUse1SERule(bool val)
  353. [DllImport(LIBNAME)]
  354. private static extern void ml_DTrees_setUse1SERule_10(IntPtr nativeObj, [MarshalAs(UnmanagedType.U1)] bool val);
  355. // C++: bool cv::ml::DTrees::getTruncatePrunedTree()
  356. [DllImport(LIBNAME)]
  357. [return: MarshalAs(UnmanagedType.U1)]
  358. private static extern bool ml_DTrees_getTruncatePrunedTree_10(IntPtr nativeObj);
  359. // C++: void cv::ml::DTrees::setTruncatePrunedTree(bool val)
  360. [DllImport(LIBNAME)]
  361. private static extern void ml_DTrees_setTruncatePrunedTree_10(IntPtr nativeObj, [MarshalAs(UnmanagedType.U1)] bool val);
  362. // C++: float cv::ml::DTrees::getRegressionAccuracy()
  363. [DllImport(LIBNAME)]
  364. private static extern float ml_DTrees_getRegressionAccuracy_10(IntPtr nativeObj);
  365. // C++: void cv::ml::DTrees::setRegressionAccuracy(float val)
  366. [DllImport(LIBNAME)]
  367. private static extern void ml_DTrees_setRegressionAccuracy_10(IntPtr nativeObj, float val);
  368. // C++: Mat cv::ml::DTrees::getPriors()
  369. [DllImport(LIBNAME)]
  370. private static extern IntPtr ml_DTrees_getPriors_10(IntPtr nativeObj);
  371. // C++: void cv::ml::DTrees::setPriors(Mat val)
  372. [DllImport(LIBNAME)]
  373. private static extern void ml_DTrees_setPriors_10(IntPtr nativeObj, IntPtr val_nativeObj);
  374. // C++: static Ptr_DTrees cv::ml::DTrees::create()
  375. [DllImport(LIBNAME)]
  376. private static extern IntPtr ml_DTrees_create_10();
  377. // C++: static Ptr_DTrees cv::ml::DTrees::load(String filepath, String nodeName = String())
  378. [DllImport(LIBNAME)]
  379. private static extern IntPtr ml_DTrees_load_10(string filepath, string nodeName);
  380. [DllImport(LIBNAME)]
  381. private static extern IntPtr ml_DTrees_load_11(string filepath);
  382. // native support for java finalize()
  383. [DllImport(LIBNAME)]
  384. private static extern void ml_DTrees_delete(IntPtr nativeObj);
  385. }
  386. }