SelectiveSearchSegmentationStrategy.cs 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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 SelectiveSearchSegmentationStrategy
  9. /**
  10. * Strategie for the selective search segmentation algorithm
  11. * The class implements a generic stragery for the algorithm described in CITE: uijlings2013selective.
  12. */
  13. public class SelectiveSearchSegmentationStrategy : 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_SelectiveSearchSegmentationStrategy_delete(nativeObj);
  26. nativeObj = IntPtr.Zero;
  27. }
  28. }
  29. finally
  30. {
  31. base.Dispose(disposing);
  32. }
  33. }
  34. protected internal SelectiveSearchSegmentationStrategy(IntPtr addr) : base(addr) { }
  35. // internal usage only
  36. public static new SelectiveSearchSegmentationStrategy __fromPtr__(IntPtr addr) { return new SelectiveSearchSegmentationStrategy(addr); }
  37. //
  38. // C++: void cv::ximgproc::segmentation::SelectiveSearchSegmentationStrategy::setImage(Mat img, Mat regions, Mat sizes, int image_id = -1)
  39. //
  40. /**
  41. * Set a initial image, with a segmentation.
  42. * param img The input image. Any number of channel can be provided
  43. * param regions A segmentation of the image. The parameter must be the same size of img.
  44. * param sizes The sizes of different regions
  45. * param image_id If not set to -1, try to cache pre-computations. If the same set og (img, regions, size) is used, the image_id need to be the same.
  46. */
  47. public void setImage(Mat img, Mat regions, Mat sizes, int image_id)
  48. {
  49. ThrowIfDisposed();
  50. if (img != null) img.ThrowIfDisposed();
  51. if (regions != null) regions.ThrowIfDisposed();
  52. if (sizes != null) sizes.ThrowIfDisposed();
  53. ximgproc_SelectiveSearchSegmentationStrategy_setImage_10(nativeObj, img.nativeObj, regions.nativeObj, sizes.nativeObj, image_id);
  54. }
  55. /**
  56. * Set a initial image, with a segmentation.
  57. * param img The input image. Any number of channel can be provided
  58. * param regions A segmentation of the image. The parameter must be the same size of img.
  59. * param sizes The sizes of different regions
  60. */
  61. public void setImage(Mat img, Mat regions, Mat sizes)
  62. {
  63. ThrowIfDisposed();
  64. if (img != null) img.ThrowIfDisposed();
  65. if (regions != null) regions.ThrowIfDisposed();
  66. if (sizes != null) sizes.ThrowIfDisposed();
  67. ximgproc_SelectiveSearchSegmentationStrategy_setImage_11(nativeObj, img.nativeObj, regions.nativeObj, sizes.nativeObj);
  68. }
  69. //
  70. // C++: float cv::ximgproc::segmentation::SelectiveSearchSegmentationStrategy::get(int r1, int r2)
  71. //
  72. /**
  73. * Return the score between two regions (between 0 and 1)
  74. * param r1 The first region
  75. * param r2 The second region
  76. * return automatically generated
  77. */
  78. public float get(int r1, int r2)
  79. {
  80. ThrowIfDisposed();
  81. return ximgproc_SelectiveSearchSegmentationStrategy_get_10(nativeObj, r1, r2);
  82. }
  83. //
  84. // C++: void cv::ximgproc::segmentation::SelectiveSearchSegmentationStrategy::merge(int r1, int r2)
  85. //
  86. /**
  87. * Inform the strategy that two regions will be merged
  88. * param r1 The first region
  89. * param r2 The second region
  90. */
  91. public void merge(int r1, int r2)
  92. {
  93. ThrowIfDisposed();
  94. ximgproc_SelectiveSearchSegmentationStrategy_merge_10(nativeObj, r1, r2);
  95. }
  96. #if (UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR
  97. const string LIBNAME = "__Internal";
  98. #else
  99. const string LIBNAME = "opencvforunity";
  100. #endif
  101. // C++: void cv::ximgproc::segmentation::SelectiveSearchSegmentationStrategy::setImage(Mat img, Mat regions, Mat sizes, int image_id = -1)
  102. [DllImport(LIBNAME)]
  103. private static extern void ximgproc_SelectiveSearchSegmentationStrategy_setImage_10(IntPtr nativeObj, IntPtr img_nativeObj, IntPtr regions_nativeObj, IntPtr sizes_nativeObj, int image_id);
  104. [DllImport(LIBNAME)]
  105. private static extern void ximgproc_SelectiveSearchSegmentationStrategy_setImage_11(IntPtr nativeObj, IntPtr img_nativeObj, IntPtr regions_nativeObj, IntPtr sizes_nativeObj);
  106. // C++: float cv::ximgproc::segmentation::SelectiveSearchSegmentationStrategy::get(int r1, int r2)
  107. [DllImport(LIBNAME)]
  108. private static extern float ximgproc_SelectiveSearchSegmentationStrategy_get_10(IntPtr nativeObj, int r1, int r2);
  109. // C++: void cv::ximgproc::segmentation::SelectiveSearchSegmentationStrategy::merge(int r1, int r2)
  110. [DllImport(LIBNAME)]
  111. private static extern void ximgproc_SelectiveSearchSegmentationStrategy_merge_10(IntPtr nativeObj, int r1, int r2);
  112. // native support for java finalize()
  113. [DllImport(LIBNAME)]
  114. private static extern void ximgproc_SelectiveSearchSegmentationStrategy_delete(IntPtr nativeObj);
  115. }
  116. }