CascadeClassifier.cs 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875
  1. using OpenCVForUnity.CoreModule;
  2. using OpenCVForUnity.UtilsModule;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Runtime.InteropServices;
  6. namespace OpenCVForUnity.ObjdetectModule
  7. {
  8. // C++: class CascadeClassifier
  9. /**
  10. * Cascade classifier class for object detection.
  11. */
  12. public class CascadeClassifier : DisposableOpenCVObject
  13. {
  14. protected override void Dispose(bool disposing)
  15. {
  16. try
  17. {
  18. if (disposing)
  19. {
  20. }
  21. if (IsEnabledDispose)
  22. {
  23. if (nativeObj != IntPtr.Zero)
  24. objdetect_CascadeClassifier_delete(nativeObj);
  25. nativeObj = IntPtr.Zero;
  26. }
  27. }
  28. finally
  29. {
  30. base.Dispose(disposing);
  31. }
  32. }
  33. protected internal CascadeClassifier(IntPtr addr) : base(addr) { }
  34. public IntPtr getNativeObjAddr() { return nativeObj; }
  35. // internal usage only
  36. public static CascadeClassifier __fromPtr__(IntPtr addr) { return new CascadeClassifier(addr); }
  37. //
  38. // C++: cv::CascadeClassifier::CascadeClassifier()
  39. //
  40. public CascadeClassifier()
  41. {
  42. nativeObj = DisposableObject.ThrowIfNullIntPtr(objdetect_CascadeClassifier_CascadeClassifier_10());
  43. }
  44. //
  45. // C++: cv::CascadeClassifier::CascadeClassifier(String filename)
  46. //
  47. /**
  48. * Loads a classifier from a file.
  49. *
  50. * param filename Name of the file from which the classifier is loaded.
  51. */
  52. public CascadeClassifier(string filename)
  53. {
  54. nativeObj = DisposableObject.ThrowIfNullIntPtr(objdetect_CascadeClassifier_CascadeClassifier_11(filename));
  55. }
  56. //
  57. // C++: bool cv::CascadeClassifier::empty()
  58. //
  59. /**
  60. * Checks whether the classifier has been loaded.
  61. * return automatically generated
  62. */
  63. public bool empty()
  64. {
  65. ThrowIfDisposed();
  66. return objdetect_CascadeClassifier_empty_10(nativeObj);
  67. }
  68. //
  69. // C++: bool cv::CascadeClassifier::load(String filename)
  70. //
  71. /**
  72. * Loads a classifier from a file.
  73. *
  74. * param filename Name of the file from which the classifier is loaded. The file may contain an old
  75. * HAAR classifier trained by the haartraining application or a new cascade classifier trained by the
  76. * traincascade application.
  77. * return automatically generated
  78. */
  79. public bool load(string filename)
  80. {
  81. ThrowIfDisposed();
  82. return objdetect_CascadeClassifier_load_10(nativeObj, filename);
  83. }
  84. //
  85. // C++: bool cv::CascadeClassifier::read(FileNode node)
  86. //
  87. // Unknown type 'FileNode' (I), skipping the function
  88. //
  89. // C++: void cv::CascadeClassifier::detectMultiScale(Mat image, vector_Rect& objects, double scaleFactor = 1.1, int minNeighbors = 3, int flags = 0, Size minSize = Size(), Size maxSize = Size())
  90. //
  91. /**
  92. * Detects objects of different sizes in the input image. The detected objects are returned as a list
  93. * of rectangles.
  94. *
  95. * param image Matrix of the type CV_8U containing an image where objects are detected.
  96. * param objects Vector of rectangles where each rectangle contains the detected object, the
  97. * rectangles may be partially outside the original image.
  98. * param scaleFactor Parameter specifying how much the image size is reduced at each image scale.
  99. * param minNeighbors Parameter specifying how many neighbors each candidate rectangle should have
  100. * to retain it.
  101. * param flags Parameter with the same meaning for an old cascade as in the function
  102. * cvHaarDetectObjects. It is not used for a new cascade.
  103. * param minSize Minimum possible object size. Objects smaller than that are ignored.
  104. * param maxSize Maximum possible object size. Objects larger than that are ignored. If {code maxSize == minSize} model is evaluated on single scale.
  105. */
  106. public void detectMultiScale(Mat image, MatOfRect objects, double scaleFactor, int minNeighbors, int flags, Size minSize, Size maxSize)
  107. {
  108. ThrowIfDisposed();
  109. if (image != null) image.ThrowIfDisposed();
  110. if (objects != null) objects.ThrowIfDisposed();
  111. Mat objects_mat = objects;
  112. objdetect_CascadeClassifier_detectMultiScale_10(nativeObj, image.nativeObj, objects_mat.nativeObj, scaleFactor, minNeighbors, flags, minSize.width, minSize.height, maxSize.width, maxSize.height);
  113. }
  114. /**
  115. * Detects objects of different sizes in the input image. The detected objects are returned as a list
  116. * of rectangles.
  117. *
  118. * param image Matrix of the type CV_8U containing an image where objects are detected.
  119. * param objects Vector of rectangles where each rectangle contains the detected object, the
  120. * rectangles may be partially outside the original image.
  121. * param scaleFactor Parameter specifying how much the image size is reduced at each image scale.
  122. * param minNeighbors Parameter specifying how many neighbors each candidate rectangle should have
  123. * to retain it.
  124. * param flags Parameter with the same meaning for an old cascade as in the function
  125. * cvHaarDetectObjects. It is not used for a new cascade.
  126. * param minSize Minimum possible object size. Objects smaller than that are ignored.
  127. */
  128. public void detectMultiScale(Mat image, MatOfRect objects, double scaleFactor, int minNeighbors, int flags, Size minSize)
  129. {
  130. ThrowIfDisposed();
  131. if (image != null) image.ThrowIfDisposed();
  132. if (objects != null) objects.ThrowIfDisposed();
  133. Mat objects_mat = objects;
  134. objdetect_CascadeClassifier_detectMultiScale_11(nativeObj, image.nativeObj, objects_mat.nativeObj, scaleFactor, minNeighbors, flags, minSize.width, minSize.height);
  135. }
  136. /**
  137. * Detects objects of different sizes in the input image. The detected objects are returned as a list
  138. * of rectangles.
  139. *
  140. * param image Matrix of the type CV_8U containing an image where objects are detected.
  141. * param objects Vector of rectangles where each rectangle contains the detected object, the
  142. * rectangles may be partially outside the original image.
  143. * param scaleFactor Parameter specifying how much the image size is reduced at each image scale.
  144. * param minNeighbors Parameter specifying how many neighbors each candidate rectangle should have
  145. * to retain it.
  146. * param flags Parameter with the same meaning for an old cascade as in the function
  147. * cvHaarDetectObjects. It is not used for a new cascade.
  148. */
  149. public void detectMultiScale(Mat image, MatOfRect objects, double scaleFactor, int minNeighbors, int flags)
  150. {
  151. ThrowIfDisposed();
  152. if (image != null) image.ThrowIfDisposed();
  153. if (objects != null) objects.ThrowIfDisposed();
  154. Mat objects_mat = objects;
  155. objdetect_CascadeClassifier_detectMultiScale_12(nativeObj, image.nativeObj, objects_mat.nativeObj, scaleFactor, minNeighbors, flags);
  156. }
  157. /**
  158. * Detects objects of different sizes in the input image. The detected objects are returned as a list
  159. * of rectangles.
  160. *
  161. * param image Matrix of the type CV_8U containing an image where objects are detected.
  162. * param objects Vector of rectangles where each rectangle contains the detected object, the
  163. * rectangles may be partially outside the original image.
  164. * param scaleFactor Parameter specifying how much the image size is reduced at each image scale.
  165. * param minNeighbors Parameter specifying how many neighbors each candidate rectangle should have
  166. * to retain it.
  167. * cvHaarDetectObjects. It is not used for a new cascade.
  168. */
  169. public void detectMultiScale(Mat image, MatOfRect objects, double scaleFactor, int minNeighbors)
  170. {
  171. ThrowIfDisposed();
  172. if (image != null) image.ThrowIfDisposed();
  173. if (objects != null) objects.ThrowIfDisposed();
  174. Mat objects_mat = objects;
  175. objdetect_CascadeClassifier_detectMultiScale_13(nativeObj, image.nativeObj, objects_mat.nativeObj, scaleFactor, minNeighbors);
  176. }
  177. /**
  178. * Detects objects of different sizes in the input image. The detected objects are returned as a list
  179. * of rectangles.
  180. *
  181. * param image Matrix of the type CV_8U containing an image where objects are detected.
  182. * param objects Vector of rectangles where each rectangle contains the detected object, the
  183. * rectangles may be partially outside the original image.
  184. * param scaleFactor Parameter specifying how much the image size is reduced at each image scale.
  185. * to retain it.
  186. * cvHaarDetectObjects. It is not used for a new cascade.
  187. */
  188. public void detectMultiScale(Mat image, MatOfRect objects, double scaleFactor)
  189. {
  190. ThrowIfDisposed();
  191. if (image != null) image.ThrowIfDisposed();
  192. if (objects != null) objects.ThrowIfDisposed();
  193. Mat objects_mat = objects;
  194. objdetect_CascadeClassifier_detectMultiScale_14(nativeObj, image.nativeObj, objects_mat.nativeObj, scaleFactor);
  195. }
  196. /**
  197. * Detects objects of different sizes in the input image. The detected objects are returned as a list
  198. * of rectangles.
  199. *
  200. * param image Matrix of the type CV_8U containing an image where objects are detected.
  201. * param objects Vector of rectangles where each rectangle contains the detected object, the
  202. * rectangles may be partially outside the original image.
  203. * to retain it.
  204. * cvHaarDetectObjects. It is not used for a new cascade.
  205. */
  206. public void detectMultiScale(Mat image, MatOfRect objects)
  207. {
  208. ThrowIfDisposed();
  209. if (image != null) image.ThrowIfDisposed();
  210. if (objects != null) objects.ThrowIfDisposed();
  211. Mat objects_mat = objects;
  212. objdetect_CascadeClassifier_detectMultiScale_15(nativeObj, image.nativeObj, objects_mat.nativeObj);
  213. }
  214. //
  215. // C++: void cv::CascadeClassifier::detectMultiScale(Mat image, vector_Rect& objects, vector_int& numDetections, double scaleFactor = 1.1, int minNeighbors = 3, int flags = 0, Size minSize = Size(), Size maxSize = Size())
  216. //
  217. /**
  218. *
  219. * param image Matrix of the type CV_8U containing an image where objects are detected.
  220. * param objects Vector of rectangles where each rectangle contains the detected object, the
  221. * rectangles may be partially outside the original image.
  222. * param numDetections Vector of detection numbers for the corresponding objects. An object's number
  223. * of detections is the number of neighboring positively classified rectangles that were joined
  224. * together to form the object.
  225. * param scaleFactor Parameter specifying how much the image size is reduced at each image scale.
  226. * param minNeighbors Parameter specifying how many neighbors each candidate rectangle should have
  227. * to retain it.
  228. * param flags Parameter with the same meaning for an old cascade as in the function
  229. * cvHaarDetectObjects. It is not used for a new cascade.
  230. * param minSize Minimum possible object size. Objects smaller than that are ignored.
  231. * param maxSize Maximum possible object size. Objects larger than that are ignored. If {code maxSize == minSize} model is evaluated on single scale.
  232. */
  233. public void detectMultiScale2(Mat image, MatOfRect objects, MatOfInt numDetections, double scaleFactor, int minNeighbors, int flags, Size minSize, Size maxSize)
  234. {
  235. ThrowIfDisposed();
  236. if (image != null) image.ThrowIfDisposed();
  237. if (objects != null) objects.ThrowIfDisposed();
  238. if (numDetections != null) numDetections.ThrowIfDisposed();
  239. Mat objects_mat = objects;
  240. Mat numDetections_mat = numDetections;
  241. objdetect_CascadeClassifier_detectMultiScale2_10(nativeObj, image.nativeObj, objects_mat.nativeObj, numDetections_mat.nativeObj, scaleFactor, minNeighbors, flags, minSize.width, minSize.height, maxSize.width, maxSize.height);
  242. }
  243. /**
  244. *
  245. * param image Matrix of the type CV_8U containing an image where objects are detected.
  246. * param objects Vector of rectangles where each rectangle contains the detected object, the
  247. * rectangles may be partially outside the original image.
  248. * param numDetections Vector of detection numbers for the corresponding objects. An object's number
  249. * of detections is the number of neighboring positively classified rectangles that were joined
  250. * together to form the object.
  251. * param scaleFactor Parameter specifying how much the image size is reduced at each image scale.
  252. * param minNeighbors Parameter specifying how many neighbors each candidate rectangle should have
  253. * to retain it.
  254. * param flags Parameter with the same meaning for an old cascade as in the function
  255. * cvHaarDetectObjects. It is not used for a new cascade.
  256. * param minSize Minimum possible object size. Objects smaller than that are ignored.
  257. */
  258. public void detectMultiScale2(Mat image, MatOfRect objects, MatOfInt numDetections, double scaleFactor, int minNeighbors, int flags, Size minSize)
  259. {
  260. ThrowIfDisposed();
  261. if (image != null) image.ThrowIfDisposed();
  262. if (objects != null) objects.ThrowIfDisposed();
  263. if (numDetections != null) numDetections.ThrowIfDisposed();
  264. Mat objects_mat = objects;
  265. Mat numDetections_mat = numDetections;
  266. objdetect_CascadeClassifier_detectMultiScale2_11(nativeObj, image.nativeObj, objects_mat.nativeObj, numDetections_mat.nativeObj, scaleFactor, minNeighbors, flags, minSize.width, minSize.height);
  267. }
  268. /**
  269. *
  270. * param image Matrix of the type CV_8U containing an image where objects are detected.
  271. * param objects Vector of rectangles where each rectangle contains the detected object, the
  272. * rectangles may be partially outside the original image.
  273. * param numDetections Vector of detection numbers for the corresponding objects. An object's number
  274. * of detections is the number of neighboring positively classified rectangles that were joined
  275. * together to form the object.
  276. * param scaleFactor Parameter specifying how much the image size is reduced at each image scale.
  277. * param minNeighbors Parameter specifying how many neighbors each candidate rectangle should have
  278. * to retain it.
  279. * param flags Parameter with the same meaning for an old cascade as in the function
  280. * cvHaarDetectObjects. It is not used for a new cascade.
  281. */
  282. public void detectMultiScale2(Mat image, MatOfRect objects, MatOfInt numDetections, double scaleFactor, int minNeighbors, int flags)
  283. {
  284. ThrowIfDisposed();
  285. if (image != null) image.ThrowIfDisposed();
  286. if (objects != null) objects.ThrowIfDisposed();
  287. if (numDetections != null) numDetections.ThrowIfDisposed();
  288. Mat objects_mat = objects;
  289. Mat numDetections_mat = numDetections;
  290. objdetect_CascadeClassifier_detectMultiScale2_12(nativeObj, image.nativeObj, objects_mat.nativeObj, numDetections_mat.nativeObj, scaleFactor, minNeighbors, flags);
  291. }
  292. /**
  293. *
  294. * param image Matrix of the type CV_8U containing an image where objects are detected.
  295. * param objects Vector of rectangles where each rectangle contains the detected object, the
  296. * rectangles may be partially outside the original image.
  297. * param numDetections Vector of detection numbers for the corresponding objects. An object's number
  298. * of detections is the number of neighboring positively classified rectangles that were joined
  299. * together to form the object.
  300. * param scaleFactor Parameter specifying how much the image size is reduced at each image scale.
  301. * param minNeighbors Parameter specifying how many neighbors each candidate rectangle should have
  302. * to retain it.
  303. * cvHaarDetectObjects. It is not used for a new cascade.
  304. */
  305. public void detectMultiScale2(Mat image, MatOfRect objects, MatOfInt numDetections, double scaleFactor, int minNeighbors)
  306. {
  307. ThrowIfDisposed();
  308. if (image != null) image.ThrowIfDisposed();
  309. if (objects != null) objects.ThrowIfDisposed();
  310. if (numDetections != null) numDetections.ThrowIfDisposed();
  311. Mat objects_mat = objects;
  312. Mat numDetections_mat = numDetections;
  313. objdetect_CascadeClassifier_detectMultiScale2_13(nativeObj, image.nativeObj, objects_mat.nativeObj, numDetections_mat.nativeObj, scaleFactor, minNeighbors);
  314. }
  315. /**
  316. *
  317. * param image Matrix of the type CV_8U containing an image where objects are detected.
  318. * param objects Vector of rectangles where each rectangle contains the detected object, the
  319. * rectangles may be partially outside the original image.
  320. * param numDetections Vector of detection numbers for the corresponding objects. An object's number
  321. * of detections is the number of neighboring positively classified rectangles that were joined
  322. * together to form the object.
  323. * param scaleFactor Parameter specifying how much the image size is reduced at each image scale.
  324. * to retain it.
  325. * cvHaarDetectObjects. It is not used for a new cascade.
  326. */
  327. public void detectMultiScale2(Mat image, MatOfRect objects, MatOfInt numDetections, double scaleFactor)
  328. {
  329. ThrowIfDisposed();
  330. if (image != null) image.ThrowIfDisposed();
  331. if (objects != null) objects.ThrowIfDisposed();
  332. if (numDetections != null) numDetections.ThrowIfDisposed();
  333. Mat objects_mat = objects;
  334. Mat numDetections_mat = numDetections;
  335. objdetect_CascadeClassifier_detectMultiScale2_14(nativeObj, image.nativeObj, objects_mat.nativeObj, numDetections_mat.nativeObj, scaleFactor);
  336. }
  337. /**
  338. *
  339. * param image Matrix of the type CV_8U containing an image where objects are detected.
  340. * param objects Vector of rectangles where each rectangle contains the detected object, the
  341. * rectangles may be partially outside the original image.
  342. * param numDetections Vector of detection numbers for the corresponding objects. An object's number
  343. * of detections is the number of neighboring positively classified rectangles that were joined
  344. * together to form the object.
  345. * to retain it.
  346. * cvHaarDetectObjects. It is not used for a new cascade.
  347. */
  348. public void detectMultiScale2(Mat image, MatOfRect objects, MatOfInt numDetections)
  349. {
  350. ThrowIfDisposed();
  351. if (image != null) image.ThrowIfDisposed();
  352. if (objects != null) objects.ThrowIfDisposed();
  353. if (numDetections != null) numDetections.ThrowIfDisposed();
  354. Mat objects_mat = objects;
  355. Mat numDetections_mat = numDetections;
  356. objdetect_CascadeClassifier_detectMultiScale2_15(nativeObj, image.nativeObj, objects_mat.nativeObj, numDetections_mat.nativeObj);
  357. }
  358. //
  359. // C++: void cv::CascadeClassifier::detectMultiScale(Mat image, vector_Rect& objects, vector_int& rejectLevels, vector_double& levelWeights, double scaleFactor = 1.1, int minNeighbors = 3, int flags = 0, Size minSize = Size(), Size maxSize = Size(), bool outputRejectLevels = false)
  360. //
  361. /**
  362. *
  363. * This function allows you to retrieve the final stage decision certainty of classification.
  364. * For this, one needs to set {code outputRejectLevels} on true and provide the {code rejectLevels} and {code levelWeights} parameter.
  365. * For each resulting detection, {code levelWeights} will then contain the certainty of classification at the final stage.
  366. * This value can then be used to separate strong from weaker classifications.
  367. *
  368. * A code sample on how to use it efficiently can be found below:
  369. * <code>
  370. * Mat img;
  371. * vector&lt;double&gt; weights;
  372. * vector&lt;int&gt; levels;
  373. * vector&lt;Rect&gt; detections;
  374. * CascadeClassifier model("/path/to/your/model.xml");
  375. * model.detectMultiScale(img, detections, levels, weights, 1.1, 3, 0, Size(), Size(), true);
  376. * cerr &lt;&lt; "Detection " &lt;&lt; detections[0] &lt;&lt; " with weight " &lt;&lt; weights[0] &lt;&lt; endl;
  377. * </code>
  378. * param image automatically generated
  379. * param objects automatically generated
  380. * param rejectLevels automatically generated
  381. * param levelWeights automatically generated
  382. * param scaleFactor automatically generated
  383. * param minNeighbors automatically generated
  384. * param flags automatically generated
  385. * param minSize automatically generated
  386. * param maxSize automatically generated
  387. * param outputRejectLevels automatically generated
  388. */
  389. public void detectMultiScale3(Mat image, MatOfRect objects, MatOfInt rejectLevels, MatOfDouble levelWeights, double scaleFactor, int minNeighbors, int flags, Size minSize, Size maxSize, bool outputRejectLevels)
  390. {
  391. ThrowIfDisposed();
  392. if (image != null) image.ThrowIfDisposed();
  393. if (objects != null) objects.ThrowIfDisposed();
  394. if (rejectLevels != null) rejectLevels.ThrowIfDisposed();
  395. if (levelWeights != null) levelWeights.ThrowIfDisposed();
  396. Mat objects_mat = objects;
  397. Mat rejectLevels_mat = rejectLevels;
  398. Mat levelWeights_mat = levelWeights;
  399. objdetect_CascadeClassifier_detectMultiScale3_10(nativeObj, image.nativeObj, objects_mat.nativeObj, rejectLevels_mat.nativeObj, levelWeights_mat.nativeObj, scaleFactor, minNeighbors, flags, minSize.width, minSize.height, maxSize.width, maxSize.height, outputRejectLevels);
  400. }
  401. /**
  402. *
  403. * This function allows you to retrieve the final stage decision certainty of classification.
  404. * For this, one needs to set {code outputRejectLevels} on true and provide the {code rejectLevels} and {code levelWeights} parameter.
  405. * For each resulting detection, {code levelWeights} will then contain the certainty of classification at the final stage.
  406. * This value can then be used to separate strong from weaker classifications.
  407. *
  408. * A code sample on how to use it efficiently can be found below:
  409. * <code>
  410. * Mat img;
  411. * vector&lt;double&gt; weights;
  412. * vector&lt;int&gt; levels;
  413. * vector&lt;Rect&gt; detections;
  414. * CascadeClassifier model("/path/to/your/model.xml");
  415. * model.detectMultiScale(img, detections, levels, weights, 1.1, 3, 0, Size(), Size(), true);
  416. * cerr &lt;&lt; "Detection " &lt;&lt; detections[0] &lt;&lt; " with weight " &lt;&lt; weights[0] &lt;&lt; endl;
  417. * </code>
  418. * param image automatically generated
  419. * param objects automatically generated
  420. * param rejectLevels automatically generated
  421. * param levelWeights automatically generated
  422. * param scaleFactor automatically generated
  423. * param minNeighbors automatically generated
  424. * param flags automatically generated
  425. * param minSize automatically generated
  426. * param maxSize automatically generated
  427. */
  428. public void detectMultiScale3(Mat image, MatOfRect objects, MatOfInt rejectLevels, MatOfDouble levelWeights, double scaleFactor, int minNeighbors, int flags, Size minSize, Size maxSize)
  429. {
  430. ThrowIfDisposed();
  431. if (image != null) image.ThrowIfDisposed();
  432. if (objects != null) objects.ThrowIfDisposed();
  433. if (rejectLevels != null) rejectLevels.ThrowIfDisposed();
  434. if (levelWeights != null) levelWeights.ThrowIfDisposed();
  435. Mat objects_mat = objects;
  436. Mat rejectLevels_mat = rejectLevels;
  437. Mat levelWeights_mat = levelWeights;
  438. objdetect_CascadeClassifier_detectMultiScale3_11(nativeObj, image.nativeObj, objects_mat.nativeObj, rejectLevels_mat.nativeObj, levelWeights_mat.nativeObj, scaleFactor, minNeighbors, flags, minSize.width, minSize.height, maxSize.width, maxSize.height);
  439. }
  440. /**
  441. *
  442. * This function allows you to retrieve the final stage decision certainty of classification.
  443. * For this, one needs to set {code outputRejectLevels} on true and provide the {code rejectLevels} and {code levelWeights} parameter.
  444. * For each resulting detection, {code levelWeights} will then contain the certainty of classification at the final stage.
  445. * This value can then be used to separate strong from weaker classifications.
  446. *
  447. * A code sample on how to use it efficiently can be found below:
  448. * <code>
  449. * Mat img;
  450. * vector&lt;double&gt; weights;
  451. * vector&lt;int&gt; levels;
  452. * vector&lt;Rect&gt; detections;
  453. * CascadeClassifier model("/path/to/your/model.xml");
  454. * model.detectMultiScale(img, detections, levels, weights, 1.1, 3, 0, Size(), Size(), true);
  455. * cerr &lt;&lt; "Detection " &lt;&lt; detections[0] &lt;&lt; " with weight " &lt;&lt; weights[0] &lt;&lt; endl;
  456. * </code>
  457. * param image automatically generated
  458. * param objects automatically generated
  459. * param rejectLevels automatically generated
  460. * param levelWeights automatically generated
  461. * param scaleFactor automatically generated
  462. * param minNeighbors automatically generated
  463. * param flags automatically generated
  464. * param minSize automatically generated
  465. */
  466. public void detectMultiScale3(Mat image, MatOfRect objects, MatOfInt rejectLevels, MatOfDouble levelWeights, double scaleFactor, int minNeighbors, int flags, Size minSize)
  467. {
  468. ThrowIfDisposed();
  469. if (image != null) image.ThrowIfDisposed();
  470. if (objects != null) objects.ThrowIfDisposed();
  471. if (rejectLevels != null) rejectLevels.ThrowIfDisposed();
  472. if (levelWeights != null) levelWeights.ThrowIfDisposed();
  473. Mat objects_mat = objects;
  474. Mat rejectLevels_mat = rejectLevels;
  475. Mat levelWeights_mat = levelWeights;
  476. objdetect_CascadeClassifier_detectMultiScale3_12(nativeObj, image.nativeObj, objects_mat.nativeObj, rejectLevels_mat.nativeObj, levelWeights_mat.nativeObj, scaleFactor, minNeighbors, flags, minSize.width, minSize.height);
  477. }
  478. /**
  479. *
  480. * This function allows you to retrieve the final stage decision certainty of classification.
  481. * For this, one needs to set {code outputRejectLevels} on true and provide the {code rejectLevels} and {code levelWeights} parameter.
  482. * For each resulting detection, {code levelWeights} will then contain the certainty of classification at the final stage.
  483. * This value can then be used to separate strong from weaker classifications.
  484. *
  485. * A code sample on how to use it efficiently can be found below:
  486. * <code>
  487. * Mat img;
  488. * vector&lt;double&gt; weights;
  489. * vector&lt;int&gt; levels;
  490. * vector&lt;Rect&gt; detections;
  491. * CascadeClassifier model("/path/to/your/model.xml");
  492. * model.detectMultiScale(img, detections, levels, weights, 1.1, 3, 0, Size(), Size(), true);
  493. * cerr &lt;&lt; "Detection " &lt;&lt; detections[0] &lt;&lt; " with weight " &lt;&lt; weights[0] &lt;&lt; endl;
  494. * </code>
  495. * param image automatically generated
  496. * param objects automatically generated
  497. * param rejectLevels automatically generated
  498. * param levelWeights automatically generated
  499. * param scaleFactor automatically generated
  500. * param minNeighbors automatically generated
  501. * param flags automatically generated
  502. */
  503. public void detectMultiScale3(Mat image, MatOfRect objects, MatOfInt rejectLevels, MatOfDouble levelWeights, double scaleFactor, int minNeighbors, int flags)
  504. {
  505. ThrowIfDisposed();
  506. if (image != null) image.ThrowIfDisposed();
  507. if (objects != null) objects.ThrowIfDisposed();
  508. if (rejectLevels != null) rejectLevels.ThrowIfDisposed();
  509. if (levelWeights != null) levelWeights.ThrowIfDisposed();
  510. Mat objects_mat = objects;
  511. Mat rejectLevels_mat = rejectLevels;
  512. Mat levelWeights_mat = levelWeights;
  513. objdetect_CascadeClassifier_detectMultiScale3_13(nativeObj, image.nativeObj, objects_mat.nativeObj, rejectLevels_mat.nativeObj, levelWeights_mat.nativeObj, scaleFactor, minNeighbors, flags);
  514. }
  515. /**
  516. *
  517. * This function allows you to retrieve the final stage decision certainty of classification.
  518. * For this, one needs to set {code outputRejectLevels} on true and provide the {code rejectLevels} and {code levelWeights} parameter.
  519. * For each resulting detection, {code levelWeights} will then contain the certainty of classification at the final stage.
  520. * This value can then be used to separate strong from weaker classifications.
  521. *
  522. * A code sample on how to use it efficiently can be found below:
  523. * <code>
  524. * Mat img;
  525. * vector&lt;double&gt; weights;
  526. * vector&lt;int&gt; levels;
  527. * vector&lt;Rect&gt; detections;
  528. * CascadeClassifier model("/path/to/your/model.xml");
  529. * model.detectMultiScale(img, detections, levels, weights, 1.1, 3, 0, Size(), Size(), true);
  530. * cerr &lt;&lt; "Detection " &lt;&lt; detections[0] &lt;&lt; " with weight " &lt;&lt; weights[0] &lt;&lt; endl;
  531. * </code>
  532. * param image automatically generated
  533. * param objects automatically generated
  534. * param rejectLevels automatically generated
  535. * param levelWeights automatically generated
  536. * param scaleFactor automatically generated
  537. * param minNeighbors automatically generated
  538. */
  539. public void detectMultiScale3(Mat image, MatOfRect objects, MatOfInt rejectLevels, MatOfDouble levelWeights, double scaleFactor, int minNeighbors)
  540. {
  541. ThrowIfDisposed();
  542. if (image != null) image.ThrowIfDisposed();
  543. if (objects != null) objects.ThrowIfDisposed();
  544. if (rejectLevels != null) rejectLevels.ThrowIfDisposed();
  545. if (levelWeights != null) levelWeights.ThrowIfDisposed();
  546. Mat objects_mat = objects;
  547. Mat rejectLevels_mat = rejectLevels;
  548. Mat levelWeights_mat = levelWeights;
  549. objdetect_CascadeClassifier_detectMultiScale3_14(nativeObj, image.nativeObj, objects_mat.nativeObj, rejectLevels_mat.nativeObj, levelWeights_mat.nativeObj, scaleFactor, minNeighbors);
  550. }
  551. /**
  552. *
  553. * This function allows you to retrieve the final stage decision certainty of classification.
  554. * For this, one needs to set {code outputRejectLevels} on true and provide the {code rejectLevels} and {code levelWeights} parameter.
  555. * For each resulting detection, {code levelWeights} will then contain the certainty of classification at the final stage.
  556. * This value can then be used to separate strong from weaker classifications.
  557. *
  558. * A code sample on how to use it efficiently can be found below:
  559. * <code>
  560. * Mat img;
  561. * vector&lt;double&gt; weights;
  562. * vector&lt;int&gt; levels;
  563. * vector&lt;Rect&gt; detections;
  564. * CascadeClassifier model("/path/to/your/model.xml");
  565. * model.detectMultiScale(img, detections, levels, weights, 1.1, 3, 0, Size(), Size(), true);
  566. * cerr &lt;&lt; "Detection " &lt;&lt; detections[0] &lt;&lt; " with weight " &lt;&lt; weights[0] &lt;&lt; endl;
  567. * </code>
  568. * param image automatically generated
  569. * param objects automatically generated
  570. * param rejectLevels automatically generated
  571. * param levelWeights automatically generated
  572. * param scaleFactor automatically generated
  573. */
  574. public void detectMultiScale3(Mat image, MatOfRect objects, MatOfInt rejectLevels, MatOfDouble levelWeights, double scaleFactor)
  575. {
  576. ThrowIfDisposed();
  577. if (image != null) image.ThrowIfDisposed();
  578. if (objects != null) objects.ThrowIfDisposed();
  579. if (rejectLevels != null) rejectLevels.ThrowIfDisposed();
  580. if (levelWeights != null) levelWeights.ThrowIfDisposed();
  581. Mat objects_mat = objects;
  582. Mat rejectLevels_mat = rejectLevels;
  583. Mat levelWeights_mat = levelWeights;
  584. objdetect_CascadeClassifier_detectMultiScale3_15(nativeObj, image.nativeObj, objects_mat.nativeObj, rejectLevels_mat.nativeObj, levelWeights_mat.nativeObj, scaleFactor);
  585. }
  586. /**
  587. *
  588. * This function allows you to retrieve the final stage decision certainty of classification.
  589. * For this, one needs to set {code outputRejectLevels} on true and provide the {code rejectLevels} and {code levelWeights} parameter.
  590. * For each resulting detection, {code levelWeights} will then contain the certainty of classification at the final stage.
  591. * This value can then be used to separate strong from weaker classifications.
  592. *
  593. * A code sample on how to use it efficiently can be found below:
  594. * <code>
  595. * Mat img;
  596. * vector&lt;double&gt; weights;
  597. * vector&lt;int&gt; levels;
  598. * vector&lt;Rect&gt; detections;
  599. * CascadeClassifier model("/path/to/your/model.xml");
  600. * model.detectMultiScale(img, detections, levels, weights, 1.1, 3, 0, Size(), Size(), true);
  601. * cerr &lt;&lt; "Detection " &lt;&lt; detections[0] &lt;&lt; " with weight " &lt;&lt; weights[0] &lt;&lt; endl;
  602. * </code>
  603. * param image automatically generated
  604. * param objects automatically generated
  605. * param rejectLevels automatically generated
  606. * param levelWeights automatically generated
  607. */
  608. public void detectMultiScale3(Mat image, MatOfRect objects, MatOfInt rejectLevels, MatOfDouble levelWeights)
  609. {
  610. ThrowIfDisposed();
  611. if (image != null) image.ThrowIfDisposed();
  612. if (objects != null) objects.ThrowIfDisposed();
  613. if (rejectLevels != null) rejectLevels.ThrowIfDisposed();
  614. if (levelWeights != null) levelWeights.ThrowIfDisposed();
  615. Mat objects_mat = objects;
  616. Mat rejectLevels_mat = rejectLevels;
  617. Mat levelWeights_mat = levelWeights;
  618. objdetect_CascadeClassifier_detectMultiScale3_16(nativeObj, image.nativeObj, objects_mat.nativeObj, rejectLevels_mat.nativeObj, levelWeights_mat.nativeObj);
  619. }
  620. //
  621. // C++: bool cv::CascadeClassifier::isOldFormatCascade()
  622. //
  623. public bool isOldFormatCascade()
  624. {
  625. ThrowIfDisposed();
  626. return objdetect_CascadeClassifier_isOldFormatCascade_10(nativeObj);
  627. }
  628. //
  629. // C++: Size cv::CascadeClassifier::getOriginalWindowSize()
  630. //
  631. public Size getOriginalWindowSize()
  632. {
  633. ThrowIfDisposed();
  634. double[] tmpArray = new double[2];
  635. objdetect_CascadeClassifier_getOriginalWindowSize_10(nativeObj, tmpArray);
  636. Size retVal = new Size(tmpArray);
  637. return retVal;
  638. }
  639. //
  640. // C++: int cv::CascadeClassifier::getFeatureType()
  641. //
  642. public int getFeatureType()
  643. {
  644. ThrowIfDisposed();
  645. return objdetect_CascadeClassifier_getFeatureType_10(nativeObj);
  646. }
  647. //
  648. // C++: static bool cv::CascadeClassifier::convert(String oldcascade, String newcascade)
  649. //
  650. public static bool convert(string oldcascade, string newcascade)
  651. {
  652. return objdetect_CascadeClassifier_convert_10(oldcascade, newcascade);
  653. }
  654. #if (UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR
  655. const string LIBNAME = "__Internal";
  656. #else
  657. const string LIBNAME = "opencvforunity";
  658. #endif
  659. // C++: cv::CascadeClassifier::CascadeClassifier()
  660. [DllImport(LIBNAME)]
  661. private static extern IntPtr objdetect_CascadeClassifier_CascadeClassifier_10();
  662. // C++: cv::CascadeClassifier::CascadeClassifier(String filename)
  663. [DllImport(LIBNAME)]
  664. private static extern IntPtr objdetect_CascadeClassifier_CascadeClassifier_11(string filename);
  665. // C++: bool cv::CascadeClassifier::empty()
  666. [DllImport(LIBNAME)]
  667. [return: MarshalAs(UnmanagedType.U1)]
  668. private static extern bool objdetect_CascadeClassifier_empty_10(IntPtr nativeObj);
  669. // C++: bool cv::CascadeClassifier::load(String filename)
  670. [DllImport(LIBNAME)]
  671. [return: MarshalAs(UnmanagedType.U1)]
  672. private static extern bool objdetect_CascadeClassifier_load_10(IntPtr nativeObj, string filename);
  673. // C++: void cv::CascadeClassifier::detectMultiScale(Mat image, vector_Rect& objects, double scaleFactor = 1.1, int minNeighbors = 3, int flags = 0, Size minSize = Size(), Size maxSize = Size())
  674. [DllImport(LIBNAME)]
  675. private static extern void objdetect_CascadeClassifier_detectMultiScale_10(IntPtr nativeObj, IntPtr image_nativeObj, IntPtr objects_mat_nativeObj, double scaleFactor, int minNeighbors, int flags, double minSize_width, double minSize_height, double maxSize_width, double maxSize_height);
  676. [DllImport(LIBNAME)]
  677. private static extern void objdetect_CascadeClassifier_detectMultiScale_11(IntPtr nativeObj, IntPtr image_nativeObj, IntPtr objects_mat_nativeObj, double scaleFactor, int minNeighbors, int flags, double minSize_width, double minSize_height);
  678. [DllImport(LIBNAME)]
  679. private static extern void objdetect_CascadeClassifier_detectMultiScale_12(IntPtr nativeObj, IntPtr image_nativeObj, IntPtr objects_mat_nativeObj, double scaleFactor, int minNeighbors, int flags);
  680. [DllImport(LIBNAME)]
  681. private static extern void objdetect_CascadeClassifier_detectMultiScale_13(IntPtr nativeObj, IntPtr image_nativeObj, IntPtr objects_mat_nativeObj, double scaleFactor, int minNeighbors);
  682. [DllImport(LIBNAME)]
  683. private static extern void objdetect_CascadeClassifier_detectMultiScale_14(IntPtr nativeObj, IntPtr image_nativeObj, IntPtr objects_mat_nativeObj, double scaleFactor);
  684. [DllImport(LIBNAME)]
  685. private static extern void objdetect_CascadeClassifier_detectMultiScale_15(IntPtr nativeObj, IntPtr image_nativeObj, IntPtr objects_mat_nativeObj);
  686. // C++: void cv::CascadeClassifier::detectMultiScale(Mat image, vector_Rect& objects, vector_int& numDetections, double scaleFactor = 1.1, int minNeighbors = 3, int flags = 0, Size minSize = Size(), Size maxSize = Size())
  687. [DllImport(LIBNAME)]
  688. private static extern void objdetect_CascadeClassifier_detectMultiScale2_10(IntPtr nativeObj, IntPtr image_nativeObj, IntPtr objects_mat_nativeObj, IntPtr numDetections_mat_nativeObj, double scaleFactor, int minNeighbors, int flags, double minSize_width, double minSize_height, double maxSize_width, double maxSize_height);
  689. [DllImport(LIBNAME)]
  690. private static extern void objdetect_CascadeClassifier_detectMultiScale2_11(IntPtr nativeObj, IntPtr image_nativeObj, IntPtr objects_mat_nativeObj, IntPtr numDetections_mat_nativeObj, double scaleFactor, int minNeighbors, int flags, double minSize_width, double minSize_height);
  691. [DllImport(LIBNAME)]
  692. private static extern void objdetect_CascadeClassifier_detectMultiScale2_12(IntPtr nativeObj, IntPtr image_nativeObj, IntPtr objects_mat_nativeObj, IntPtr numDetections_mat_nativeObj, double scaleFactor, int minNeighbors, int flags);
  693. [DllImport(LIBNAME)]
  694. private static extern void objdetect_CascadeClassifier_detectMultiScale2_13(IntPtr nativeObj, IntPtr image_nativeObj, IntPtr objects_mat_nativeObj, IntPtr numDetections_mat_nativeObj, double scaleFactor, int minNeighbors);
  695. [DllImport(LIBNAME)]
  696. private static extern void objdetect_CascadeClassifier_detectMultiScale2_14(IntPtr nativeObj, IntPtr image_nativeObj, IntPtr objects_mat_nativeObj, IntPtr numDetections_mat_nativeObj, double scaleFactor);
  697. [DllImport(LIBNAME)]
  698. private static extern void objdetect_CascadeClassifier_detectMultiScale2_15(IntPtr nativeObj, IntPtr image_nativeObj, IntPtr objects_mat_nativeObj, IntPtr numDetections_mat_nativeObj);
  699. // C++: void cv::CascadeClassifier::detectMultiScale(Mat image, vector_Rect& objects, vector_int& rejectLevels, vector_double& levelWeights, double scaleFactor = 1.1, int minNeighbors = 3, int flags = 0, Size minSize = Size(), Size maxSize = Size(), bool outputRejectLevels = false)
  700. [DllImport(LIBNAME)]
  701. private static extern void objdetect_CascadeClassifier_detectMultiScale3_10(IntPtr nativeObj, IntPtr image_nativeObj, IntPtr objects_mat_nativeObj, IntPtr rejectLevels_mat_nativeObj, IntPtr levelWeights_mat_nativeObj, double scaleFactor, int minNeighbors, int flags, double minSize_width, double minSize_height, double maxSize_width, double maxSize_height, [MarshalAs(UnmanagedType.U1)] bool outputRejectLevels);
  702. [DllImport(LIBNAME)]
  703. private static extern void objdetect_CascadeClassifier_detectMultiScale3_11(IntPtr nativeObj, IntPtr image_nativeObj, IntPtr objects_mat_nativeObj, IntPtr rejectLevels_mat_nativeObj, IntPtr levelWeights_mat_nativeObj, double scaleFactor, int minNeighbors, int flags, double minSize_width, double minSize_height, double maxSize_width, double maxSize_height);
  704. [DllImport(LIBNAME)]
  705. private static extern void objdetect_CascadeClassifier_detectMultiScale3_12(IntPtr nativeObj, IntPtr image_nativeObj, IntPtr objects_mat_nativeObj, IntPtr rejectLevels_mat_nativeObj, IntPtr levelWeights_mat_nativeObj, double scaleFactor, int minNeighbors, int flags, double minSize_width, double minSize_height);
  706. [DllImport(LIBNAME)]
  707. private static extern void objdetect_CascadeClassifier_detectMultiScale3_13(IntPtr nativeObj, IntPtr image_nativeObj, IntPtr objects_mat_nativeObj, IntPtr rejectLevels_mat_nativeObj, IntPtr levelWeights_mat_nativeObj, double scaleFactor, int minNeighbors, int flags);
  708. [DllImport(LIBNAME)]
  709. private static extern void objdetect_CascadeClassifier_detectMultiScale3_14(IntPtr nativeObj, IntPtr image_nativeObj, IntPtr objects_mat_nativeObj, IntPtr rejectLevels_mat_nativeObj, IntPtr levelWeights_mat_nativeObj, double scaleFactor, int minNeighbors);
  710. [DllImport(LIBNAME)]
  711. private static extern void objdetect_CascadeClassifier_detectMultiScale3_15(IntPtr nativeObj, IntPtr image_nativeObj, IntPtr objects_mat_nativeObj, IntPtr rejectLevels_mat_nativeObj, IntPtr levelWeights_mat_nativeObj, double scaleFactor);
  712. [DllImport(LIBNAME)]
  713. private static extern void objdetect_CascadeClassifier_detectMultiScale3_16(IntPtr nativeObj, IntPtr image_nativeObj, IntPtr objects_mat_nativeObj, IntPtr rejectLevels_mat_nativeObj, IntPtr levelWeights_mat_nativeObj);
  714. // C++: bool cv::CascadeClassifier::isOldFormatCascade()
  715. [DllImport(LIBNAME)]
  716. [return: MarshalAs(UnmanagedType.U1)]
  717. private static extern bool objdetect_CascadeClassifier_isOldFormatCascade_10(IntPtr nativeObj);
  718. // C++: Size cv::CascadeClassifier::getOriginalWindowSize()
  719. [DllImport(LIBNAME)]
  720. private static extern void objdetect_CascadeClassifier_getOriginalWindowSize_10(IntPtr nativeObj, double[] retVal);
  721. // C++: int cv::CascadeClassifier::getFeatureType()
  722. [DllImport(LIBNAME)]
  723. private static extern int objdetect_CascadeClassifier_getFeatureType_10(IntPtr nativeObj);
  724. // C++: static bool cv::CascadeClassifier::convert(String oldcascade, String newcascade)
  725. [DllImport(LIBNAME)]
  726. [return: MarshalAs(UnmanagedType.U1)]
  727. private static extern bool objdetect_CascadeClassifier_convert_10(string oldcascade, string newcascade);
  728. // native support for java finalize()
  729. [DllImport(LIBNAME)]
  730. private static extern void objdetect_CascadeClassifier_delete(IntPtr nativeObj);
  731. }
  732. }