StereoMatcher.cs 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  1. using OpenCVForUnity.CoreModule;
  2. using OpenCVForUnity.UtilsModule;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Runtime.InteropServices;
  6. namespace OpenCVForUnity.Calib3dModule
  7. {
  8. // C++: class StereoMatcher
  9. /**
  10. * The base class for stereo correspondence algorithms.
  11. */
  12. public class StereoMatcher : Algorithm
  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. calib3d_StereoMatcher_delete(nativeObj);
  25. nativeObj = IntPtr.Zero;
  26. }
  27. }
  28. finally
  29. {
  30. base.Dispose(disposing);
  31. }
  32. }
  33. protected internal StereoMatcher(IntPtr addr) : base(addr) { }
  34. // internal usage only
  35. public static new StereoMatcher __fromPtr__(IntPtr addr) { return new StereoMatcher(addr); }
  36. // C++: enum <unnamed>
  37. public const int DISP_SHIFT = 4;
  38. public const int DISP_SCALE = (1 << DISP_SHIFT);
  39. //
  40. // C++: void cv::StereoMatcher::compute(Mat left, Mat right, Mat& disparity)
  41. //
  42. /**
  43. * Computes disparity map for the specified stereo pair
  44. *
  45. * param left Left 8-bit single-channel image.
  46. * param right Right image of the same size and the same type as the left one.
  47. * param disparity Output disparity map. It has the same size as the input images. Some algorithms,
  48. * like StereoBM or StereoSGBM compute 16-bit fixed-point disparity map (where each disparity value
  49. * has 4 fractional bits), whereas other algorithms output 32-bit floating-point disparity map.
  50. */
  51. public void compute(Mat left, Mat right, Mat disparity)
  52. {
  53. ThrowIfDisposed();
  54. if (left != null) left.ThrowIfDisposed();
  55. if (right != null) right.ThrowIfDisposed();
  56. if (disparity != null) disparity.ThrowIfDisposed();
  57. calib3d_StereoMatcher_compute_10(nativeObj, left.nativeObj, right.nativeObj, disparity.nativeObj);
  58. }
  59. //
  60. // C++: int cv::StereoMatcher::getMinDisparity()
  61. //
  62. public int getMinDisparity()
  63. {
  64. ThrowIfDisposed();
  65. return calib3d_StereoMatcher_getMinDisparity_10(nativeObj);
  66. }
  67. //
  68. // C++: void cv::StereoMatcher::setMinDisparity(int minDisparity)
  69. //
  70. public void setMinDisparity(int minDisparity)
  71. {
  72. ThrowIfDisposed();
  73. calib3d_StereoMatcher_setMinDisparity_10(nativeObj, minDisparity);
  74. }
  75. //
  76. // C++: int cv::StereoMatcher::getNumDisparities()
  77. //
  78. public int getNumDisparities()
  79. {
  80. ThrowIfDisposed();
  81. return calib3d_StereoMatcher_getNumDisparities_10(nativeObj);
  82. }
  83. //
  84. // C++: void cv::StereoMatcher::setNumDisparities(int numDisparities)
  85. //
  86. public void setNumDisparities(int numDisparities)
  87. {
  88. ThrowIfDisposed();
  89. calib3d_StereoMatcher_setNumDisparities_10(nativeObj, numDisparities);
  90. }
  91. //
  92. // C++: int cv::StereoMatcher::getBlockSize()
  93. //
  94. public int getBlockSize()
  95. {
  96. ThrowIfDisposed();
  97. return calib3d_StereoMatcher_getBlockSize_10(nativeObj);
  98. }
  99. //
  100. // C++: void cv::StereoMatcher::setBlockSize(int blockSize)
  101. //
  102. public void setBlockSize(int blockSize)
  103. {
  104. ThrowIfDisposed();
  105. calib3d_StereoMatcher_setBlockSize_10(nativeObj, blockSize);
  106. }
  107. //
  108. // C++: int cv::StereoMatcher::getSpeckleWindowSize()
  109. //
  110. public int getSpeckleWindowSize()
  111. {
  112. ThrowIfDisposed();
  113. return calib3d_StereoMatcher_getSpeckleWindowSize_10(nativeObj);
  114. }
  115. //
  116. // C++: void cv::StereoMatcher::setSpeckleWindowSize(int speckleWindowSize)
  117. //
  118. public void setSpeckleWindowSize(int speckleWindowSize)
  119. {
  120. ThrowIfDisposed();
  121. calib3d_StereoMatcher_setSpeckleWindowSize_10(nativeObj, speckleWindowSize);
  122. }
  123. //
  124. // C++: int cv::StereoMatcher::getSpeckleRange()
  125. //
  126. public int getSpeckleRange()
  127. {
  128. ThrowIfDisposed();
  129. return calib3d_StereoMatcher_getSpeckleRange_10(nativeObj);
  130. }
  131. //
  132. // C++: void cv::StereoMatcher::setSpeckleRange(int speckleRange)
  133. //
  134. public void setSpeckleRange(int speckleRange)
  135. {
  136. ThrowIfDisposed();
  137. calib3d_StereoMatcher_setSpeckleRange_10(nativeObj, speckleRange);
  138. }
  139. //
  140. // C++: int cv::StereoMatcher::getDisp12MaxDiff()
  141. //
  142. public int getDisp12MaxDiff()
  143. {
  144. ThrowIfDisposed();
  145. return calib3d_StereoMatcher_getDisp12MaxDiff_10(nativeObj);
  146. }
  147. //
  148. // C++: void cv::StereoMatcher::setDisp12MaxDiff(int disp12MaxDiff)
  149. //
  150. public void setDisp12MaxDiff(int disp12MaxDiff)
  151. {
  152. ThrowIfDisposed();
  153. calib3d_StereoMatcher_setDisp12MaxDiff_10(nativeObj, disp12MaxDiff);
  154. }
  155. #if (UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR
  156. const string LIBNAME = "__Internal";
  157. #else
  158. const string LIBNAME = "opencvforunity";
  159. #endif
  160. // C++: void cv::StereoMatcher::compute(Mat left, Mat right, Mat& disparity)
  161. [DllImport(LIBNAME)]
  162. private static extern void calib3d_StereoMatcher_compute_10(IntPtr nativeObj, IntPtr left_nativeObj, IntPtr right_nativeObj, IntPtr disparity_nativeObj);
  163. // C++: int cv::StereoMatcher::getMinDisparity()
  164. [DllImport(LIBNAME)]
  165. private static extern int calib3d_StereoMatcher_getMinDisparity_10(IntPtr nativeObj);
  166. // C++: void cv::StereoMatcher::setMinDisparity(int minDisparity)
  167. [DllImport(LIBNAME)]
  168. private static extern void calib3d_StereoMatcher_setMinDisparity_10(IntPtr nativeObj, int minDisparity);
  169. // C++: int cv::StereoMatcher::getNumDisparities()
  170. [DllImport(LIBNAME)]
  171. private static extern int calib3d_StereoMatcher_getNumDisparities_10(IntPtr nativeObj);
  172. // C++: void cv::StereoMatcher::setNumDisparities(int numDisparities)
  173. [DllImport(LIBNAME)]
  174. private static extern void calib3d_StereoMatcher_setNumDisparities_10(IntPtr nativeObj, int numDisparities);
  175. // C++: int cv::StereoMatcher::getBlockSize()
  176. [DllImport(LIBNAME)]
  177. private static extern int calib3d_StereoMatcher_getBlockSize_10(IntPtr nativeObj);
  178. // C++: void cv::StereoMatcher::setBlockSize(int blockSize)
  179. [DllImport(LIBNAME)]
  180. private static extern void calib3d_StereoMatcher_setBlockSize_10(IntPtr nativeObj, int blockSize);
  181. // C++: int cv::StereoMatcher::getSpeckleWindowSize()
  182. [DllImport(LIBNAME)]
  183. private static extern int calib3d_StereoMatcher_getSpeckleWindowSize_10(IntPtr nativeObj);
  184. // C++: void cv::StereoMatcher::setSpeckleWindowSize(int speckleWindowSize)
  185. [DllImport(LIBNAME)]
  186. private static extern void calib3d_StereoMatcher_setSpeckleWindowSize_10(IntPtr nativeObj, int speckleWindowSize);
  187. // C++: int cv::StereoMatcher::getSpeckleRange()
  188. [DllImport(LIBNAME)]
  189. private static extern int calib3d_StereoMatcher_getSpeckleRange_10(IntPtr nativeObj);
  190. // C++: void cv::StereoMatcher::setSpeckleRange(int speckleRange)
  191. [DllImport(LIBNAME)]
  192. private static extern void calib3d_StereoMatcher_setSpeckleRange_10(IntPtr nativeObj, int speckleRange);
  193. // C++: int cv::StereoMatcher::getDisp12MaxDiff()
  194. [DllImport(LIBNAME)]
  195. private static extern int calib3d_StereoMatcher_getDisp12MaxDiff_10(IntPtr nativeObj);
  196. // C++: void cv::StereoMatcher::setDisp12MaxDiff(int disp12MaxDiff)
  197. [DllImport(LIBNAME)]
  198. private static extern void calib3d_StereoMatcher_setDisp12MaxDiff_10(IntPtr nativeObj, int disp12MaxDiff);
  199. // native support for java finalize()
  200. [DllImport(LIBNAME)]
  201. private static extern void calib3d_StereoMatcher_delete(IntPtr nativeObj);
  202. }
  203. }