SelectiveSearchSegmentation.cs 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428
  1. using OpenCVForUnity.CoreModule;
  2. using OpenCVForUnity.UtilsModule;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Runtime.InteropServices;
  6. namespace OpenCVForUnity.XimgprocModule
  7. {
  8. // C++: class SelectiveSearchSegmentation
  9. /**
  10. * Selective search segmentation algorithm
  11. * The class implements the algorithm described in CITE: uijlings2013selective.
  12. */
  13. public class SelectiveSearchSegmentation : Algorithm
  14. {
  15. protected override void Dispose(bool disposing)
  16. {
  17. try
  18. {
  19. if (disposing)
  20. {
  21. }
  22. if (IsEnabledDispose)
  23. {
  24. if (nativeObj != IntPtr.Zero)
  25. ximgproc_SelectiveSearchSegmentation_delete(nativeObj);
  26. nativeObj = IntPtr.Zero;
  27. }
  28. }
  29. finally
  30. {
  31. base.Dispose(disposing);
  32. }
  33. }
  34. protected internal SelectiveSearchSegmentation(IntPtr addr) : base(addr) { }
  35. // internal usage only
  36. public static new SelectiveSearchSegmentation __fromPtr__(IntPtr addr) { return new SelectiveSearchSegmentation(addr); }
  37. //
  38. // C++: void cv::ximgproc::segmentation::SelectiveSearchSegmentation::setBaseImage(Mat img)
  39. //
  40. /**
  41. * Set a image used by switch* functions to initialize the class
  42. * param img The image
  43. */
  44. public void setBaseImage(Mat img)
  45. {
  46. ThrowIfDisposed();
  47. if (img != null) img.ThrowIfDisposed();
  48. ximgproc_SelectiveSearchSegmentation_setBaseImage_10(nativeObj, img.nativeObj);
  49. }
  50. //
  51. // C++: void cv::ximgproc::segmentation::SelectiveSearchSegmentation::switchToSingleStrategy(int k = 200, float sigma = 0.8f)
  52. //
  53. /**
  54. * Initialize the class with the 'Single stragegy' parameters describled in CITE: uijlings2013selective.
  55. * param k The k parameter for the graph segmentation
  56. * param sigma The sigma parameter for the graph segmentation
  57. */
  58. public void switchToSingleStrategy(int k, float sigma)
  59. {
  60. ThrowIfDisposed();
  61. ximgproc_SelectiveSearchSegmentation_switchToSingleStrategy_10(nativeObj, k, sigma);
  62. }
  63. /**
  64. * Initialize the class with the 'Single stragegy' parameters describled in CITE: uijlings2013selective.
  65. * param k The k parameter for the graph segmentation
  66. */
  67. public void switchToSingleStrategy(int k)
  68. {
  69. ThrowIfDisposed();
  70. ximgproc_SelectiveSearchSegmentation_switchToSingleStrategy_11(nativeObj, k);
  71. }
  72. /**
  73. * Initialize the class with the 'Single stragegy' parameters describled in CITE: uijlings2013selective.
  74. */
  75. public void switchToSingleStrategy()
  76. {
  77. ThrowIfDisposed();
  78. ximgproc_SelectiveSearchSegmentation_switchToSingleStrategy_12(nativeObj);
  79. }
  80. //
  81. // C++: void cv::ximgproc::segmentation::SelectiveSearchSegmentation::switchToSelectiveSearchFast(int base_k = 150, int inc_k = 150, float sigma = 0.8f)
  82. //
  83. /**
  84. * Initialize the class with the 'Selective search fast' parameters describled in CITE: uijlings2013selective.
  85. * param base_k The k parameter for the first graph segmentation
  86. * param inc_k The increment of the k parameter for all graph segmentations
  87. * param sigma The sigma parameter for the graph segmentation
  88. */
  89. public void switchToSelectiveSearchFast(int base_k, int inc_k, float sigma)
  90. {
  91. ThrowIfDisposed();
  92. ximgproc_SelectiveSearchSegmentation_switchToSelectiveSearchFast_10(nativeObj, base_k, inc_k, sigma);
  93. }
  94. /**
  95. * Initialize the class with the 'Selective search fast' parameters describled in CITE: uijlings2013selective.
  96. * param base_k The k parameter for the first graph segmentation
  97. * param inc_k The increment of the k parameter for all graph segmentations
  98. */
  99. public void switchToSelectiveSearchFast(int base_k, int inc_k)
  100. {
  101. ThrowIfDisposed();
  102. ximgproc_SelectiveSearchSegmentation_switchToSelectiveSearchFast_11(nativeObj, base_k, inc_k);
  103. }
  104. /**
  105. * Initialize the class with the 'Selective search fast' parameters describled in CITE: uijlings2013selective.
  106. * param base_k The k parameter for the first graph segmentation
  107. */
  108. public void switchToSelectiveSearchFast(int base_k)
  109. {
  110. ThrowIfDisposed();
  111. ximgproc_SelectiveSearchSegmentation_switchToSelectiveSearchFast_12(nativeObj, base_k);
  112. }
  113. /**
  114. * Initialize the class with the 'Selective search fast' parameters describled in CITE: uijlings2013selective.
  115. */
  116. public void switchToSelectiveSearchFast()
  117. {
  118. ThrowIfDisposed();
  119. ximgproc_SelectiveSearchSegmentation_switchToSelectiveSearchFast_13(nativeObj);
  120. }
  121. //
  122. // C++: void cv::ximgproc::segmentation::SelectiveSearchSegmentation::switchToSelectiveSearchQuality(int base_k = 150, int inc_k = 150, float sigma = 0.8f)
  123. //
  124. /**
  125. * Initialize the class with the 'Selective search fast' parameters describled in CITE: uijlings2013selective.
  126. * param base_k The k parameter for the first graph segmentation
  127. * param inc_k The increment of the k parameter for all graph segmentations
  128. * param sigma The sigma parameter for the graph segmentation
  129. */
  130. public void switchToSelectiveSearchQuality(int base_k, int inc_k, float sigma)
  131. {
  132. ThrowIfDisposed();
  133. ximgproc_SelectiveSearchSegmentation_switchToSelectiveSearchQuality_10(nativeObj, base_k, inc_k, sigma);
  134. }
  135. /**
  136. * Initialize the class with the 'Selective search fast' parameters describled in CITE: uijlings2013selective.
  137. * param base_k The k parameter for the first graph segmentation
  138. * param inc_k The increment of the k parameter for all graph segmentations
  139. */
  140. public void switchToSelectiveSearchQuality(int base_k, int inc_k)
  141. {
  142. ThrowIfDisposed();
  143. ximgproc_SelectiveSearchSegmentation_switchToSelectiveSearchQuality_11(nativeObj, base_k, inc_k);
  144. }
  145. /**
  146. * Initialize the class with the 'Selective search fast' parameters describled in CITE: uijlings2013selective.
  147. * param base_k The k parameter for the first graph segmentation
  148. */
  149. public void switchToSelectiveSearchQuality(int base_k)
  150. {
  151. ThrowIfDisposed();
  152. ximgproc_SelectiveSearchSegmentation_switchToSelectiveSearchQuality_12(nativeObj, base_k);
  153. }
  154. /**
  155. * Initialize the class with the 'Selective search fast' parameters describled in CITE: uijlings2013selective.
  156. */
  157. public void switchToSelectiveSearchQuality()
  158. {
  159. ThrowIfDisposed();
  160. ximgproc_SelectiveSearchSegmentation_switchToSelectiveSearchQuality_13(nativeObj);
  161. }
  162. //
  163. // C++: void cv::ximgproc::segmentation::SelectiveSearchSegmentation::addImage(Mat img)
  164. //
  165. /**
  166. * Add a new image in the list of images to process.
  167. * param img The image
  168. */
  169. public void addImage(Mat img)
  170. {
  171. ThrowIfDisposed();
  172. if (img != null) img.ThrowIfDisposed();
  173. ximgproc_SelectiveSearchSegmentation_addImage_10(nativeObj, img.nativeObj);
  174. }
  175. //
  176. // C++: void cv::ximgproc::segmentation::SelectiveSearchSegmentation::clearImages()
  177. //
  178. /**
  179. * Clear the list of images to process
  180. */
  181. public void clearImages()
  182. {
  183. ThrowIfDisposed();
  184. ximgproc_SelectiveSearchSegmentation_clearImages_10(nativeObj);
  185. }
  186. //
  187. // C++: void cv::ximgproc::segmentation::SelectiveSearchSegmentation::addGraphSegmentation(Ptr_GraphSegmentation g)
  188. //
  189. /**
  190. * Add a new graph segmentation in the list of graph segementations to process.
  191. * param g The graph segmentation
  192. */
  193. public void addGraphSegmentation(GraphSegmentation g)
  194. {
  195. ThrowIfDisposed();
  196. if (g != null) g.ThrowIfDisposed();
  197. ximgproc_SelectiveSearchSegmentation_addGraphSegmentation_10(nativeObj, g.getNativeObjAddr());
  198. }
  199. //
  200. // C++: void cv::ximgproc::segmentation::SelectiveSearchSegmentation::clearGraphSegmentations()
  201. //
  202. /**
  203. * Clear the list of graph segmentations to process;
  204. */
  205. public void clearGraphSegmentations()
  206. {
  207. ThrowIfDisposed();
  208. ximgproc_SelectiveSearchSegmentation_clearGraphSegmentations_10(nativeObj);
  209. }
  210. //
  211. // C++: void cv::ximgproc::segmentation::SelectiveSearchSegmentation::addStrategy(Ptr_SelectiveSearchSegmentationStrategy s)
  212. //
  213. /**
  214. * Add a new strategy in the list of strategy to process.
  215. * param s The strategy
  216. */
  217. public void addStrategy(SelectiveSearchSegmentationStrategy s)
  218. {
  219. ThrowIfDisposed();
  220. if (s != null) s.ThrowIfDisposed();
  221. ximgproc_SelectiveSearchSegmentation_addStrategy_10(nativeObj, s.getNativeObjAddr());
  222. }
  223. //
  224. // C++: void cv::ximgproc::segmentation::SelectiveSearchSegmentation::clearStrategies()
  225. //
  226. /**
  227. * Clear the list of strategy to process;
  228. */
  229. public void clearStrategies()
  230. {
  231. ThrowIfDisposed();
  232. ximgproc_SelectiveSearchSegmentation_clearStrategies_10(nativeObj);
  233. }
  234. //
  235. // C++: void cv::ximgproc::segmentation::SelectiveSearchSegmentation::process(vector_Rect& rects)
  236. //
  237. /**
  238. * Based on all images, graph segmentations and stragies, computes all possible rects and return them
  239. * param rects The list of rects. The first ones are more relevents than the lasts ones.
  240. */
  241. public void process(MatOfRect rects)
  242. {
  243. ThrowIfDisposed();
  244. if (rects != null) rects.ThrowIfDisposed();
  245. Mat rects_mat = rects;
  246. ximgproc_SelectiveSearchSegmentation_process_10(nativeObj, rects_mat.nativeObj);
  247. }
  248. #if (UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR
  249. const string LIBNAME = "__Internal";
  250. #else
  251. const string LIBNAME = "opencvforunity";
  252. #endif
  253. // C++: void cv::ximgproc::segmentation::SelectiveSearchSegmentation::setBaseImage(Mat img)
  254. [DllImport(LIBNAME)]
  255. private static extern void ximgproc_SelectiveSearchSegmentation_setBaseImage_10(IntPtr nativeObj, IntPtr img_nativeObj);
  256. // C++: void cv::ximgproc::segmentation::SelectiveSearchSegmentation::switchToSingleStrategy(int k = 200, float sigma = 0.8f)
  257. [DllImport(LIBNAME)]
  258. private static extern void ximgproc_SelectiveSearchSegmentation_switchToSingleStrategy_10(IntPtr nativeObj, int k, float sigma);
  259. [DllImport(LIBNAME)]
  260. private static extern void ximgproc_SelectiveSearchSegmentation_switchToSingleStrategy_11(IntPtr nativeObj, int k);
  261. [DllImport(LIBNAME)]
  262. private static extern void ximgproc_SelectiveSearchSegmentation_switchToSingleStrategy_12(IntPtr nativeObj);
  263. // C++: void cv::ximgproc::segmentation::SelectiveSearchSegmentation::switchToSelectiveSearchFast(int base_k = 150, int inc_k = 150, float sigma = 0.8f)
  264. [DllImport(LIBNAME)]
  265. private static extern void ximgproc_SelectiveSearchSegmentation_switchToSelectiveSearchFast_10(IntPtr nativeObj, int base_k, int inc_k, float sigma);
  266. [DllImport(LIBNAME)]
  267. private static extern void ximgproc_SelectiveSearchSegmentation_switchToSelectiveSearchFast_11(IntPtr nativeObj, int base_k, int inc_k);
  268. [DllImport(LIBNAME)]
  269. private static extern void ximgproc_SelectiveSearchSegmentation_switchToSelectiveSearchFast_12(IntPtr nativeObj, int base_k);
  270. [DllImport(LIBNAME)]
  271. private static extern void ximgproc_SelectiveSearchSegmentation_switchToSelectiveSearchFast_13(IntPtr nativeObj);
  272. // C++: void cv::ximgproc::segmentation::SelectiveSearchSegmentation::switchToSelectiveSearchQuality(int base_k = 150, int inc_k = 150, float sigma = 0.8f)
  273. [DllImport(LIBNAME)]
  274. private static extern void ximgproc_SelectiveSearchSegmentation_switchToSelectiveSearchQuality_10(IntPtr nativeObj, int base_k, int inc_k, float sigma);
  275. [DllImport(LIBNAME)]
  276. private static extern void ximgproc_SelectiveSearchSegmentation_switchToSelectiveSearchQuality_11(IntPtr nativeObj, int base_k, int inc_k);
  277. [DllImport(LIBNAME)]
  278. private static extern void ximgproc_SelectiveSearchSegmentation_switchToSelectiveSearchQuality_12(IntPtr nativeObj, int base_k);
  279. [DllImport(LIBNAME)]
  280. private static extern void ximgproc_SelectiveSearchSegmentation_switchToSelectiveSearchQuality_13(IntPtr nativeObj);
  281. // C++: void cv::ximgproc::segmentation::SelectiveSearchSegmentation::addImage(Mat img)
  282. [DllImport(LIBNAME)]
  283. private static extern void ximgproc_SelectiveSearchSegmentation_addImage_10(IntPtr nativeObj, IntPtr img_nativeObj);
  284. // C++: void cv::ximgproc::segmentation::SelectiveSearchSegmentation::clearImages()
  285. [DllImport(LIBNAME)]
  286. private static extern void ximgproc_SelectiveSearchSegmentation_clearImages_10(IntPtr nativeObj);
  287. // C++: void cv::ximgproc::segmentation::SelectiveSearchSegmentation::addGraphSegmentation(Ptr_GraphSegmentation g)
  288. [DllImport(LIBNAME)]
  289. private static extern void ximgproc_SelectiveSearchSegmentation_addGraphSegmentation_10(IntPtr nativeObj, IntPtr g_nativeObj);
  290. // C++: void cv::ximgproc::segmentation::SelectiveSearchSegmentation::clearGraphSegmentations()
  291. [DllImport(LIBNAME)]
  292. private static extern void ximgproc_SelectiveSearchSegmentation_clearGraphSegmentations_10(IntPtr nativeObj);
  293. // C++: void cv::ximgproc::segmentation::SelectiveSearchSegmentation::addStrategy(Ptr_SelectiveSearchSegmentationStrategy s)
  294. [DllImport(LIBNAME)]
  295. private static extern void ximgproc_SelectiveSearchSegmentation_addStrategy_10(IntPtr nativeObj, IntPtr s_nativeObj);
  296. // C++: void cv::ximgproc::segmentation::SelectiveSearchSegmentation::clearStrategies()
  297. [DllImport(LIBNAME)]
  298. private static extern void ximgproc_SelectiveSearchSegmentation_clearStrategies_10(IntPtr nativeObj);
  299. // C++: void cv::ximgproc::segmentation::SelectiveSearchSegmentation::process(vector_Rect& rects)
  300. [DllImport(LIBNAME)]
  301. private static extern void ximgproc_SelectiveSearchSegmentation_process_10(IntPtr nativeObj, IntPtr rects_mat_nativeObj);
  302. // native support for java finalize()
  303. [DllImport(LIBNAME)]
  304. private static extern void ximgproc_SelectiveSearchSegmentation_delete(IntPtr nativeObj);
  305. }
  306. }