StereoBM.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437
  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 StereoBM
  9. /**
  10. * Class for computing stereo correspondence using the block matching algorithm, introduced and
  11. * contributed to OpenCV by K. Konolige.
  12. */
  13. public class StereoBM : StereoMatcher
  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. calib3d_StereoBM_delete(nativeObj);
  26. nativeObj = IntPtr.Zero;
  27. }
  28. }
  29. finally
  30. {
  31. base.Dispose(disposing);
  32. }
  33. }
  34. protected internal StereoBM(IntPtr addr) : base(addr) { }
  35. // internal usage only
  36. public static new StereoBM __fromPtr__(IntPtr addr) { return new StereoBM(addr); }
  37. // C++: enum <unnamed>
  38. public const int PREFILTER_NORMALIZED_RESPONSE = 0;
  39. public const int PREFILTER_XSOBEL = 1;
  40. //
  41. // C++: int cv::StereoBM::getPreFilterType()
  42. //
  43. public int getPreFilterType()
  44. {
  45. ThrowIfDisposed();
  46. return calib3d_StereoBM_getPreFilterType_10(nativeObj);
  47. }
  48. //
  49. // C++: void cv::StereoBM::setPreFilterType(int preFilterType)
  50. //
  51. public void setPreFilterType(int preFilterType)
  52. {
  53. ThrowIfDisposed();
  54. calib3d_StereoBM_setPreFilterType_10(nativeObj, preFilterType);
  55. }
  56. //
  57. // C++: int cv::StereoBM::getPreFilterSize()
  58. //
  59. public int getPreFilterSize()
  60. {
  61. ThrowIfDisposed();
  62. return calib3d_StereoBM_getPreFilterSize_10(nativeObj);
  63. }
  64. //
  65. // C++: void cv::StereoBM::setPreFilterSize(int preFilterSize)
  66. //
  67. public void setPreFilterSize(int preFilterSize)
  68. {
  69. ThrowIfDisposed();
  70. calib3d_StereoBM_setPreFilterSize_10(nativeObj, preFilterSize);
  71. }
  72. //
  73. // C++: int cv::StereoBM::getPreFilterCap()
  74. //
  75. public int getPreFilterCap()
  76. {
  77. ThrowIfDisposed();
  78. return calib3d_StereoBM_getPreFilterCap_10(nativeObj);
  79. }
  80. //
  81. // C++: void cv::StereoBM::setPreFilterCap(int preFilterCap)
  82. //
  83. public void setPreFilterCap(int preFilterCap)
  84. {
  85. ThrowIfDisposed();
  86. calib3d_StereoBM_setPreFilterCap_10(nativeObj, preFilterCap);
  87. }
  88. //
  89. // C++: int cv::StereoBM::getTextureThreshold()
  90. //
  91. public int getTextureThreshold()
  92. {
  93. ThrowIfDisposed();
  94. return calib3d_StereoBM_getTextureThreshold_10(nativeObj);
  95. }
  96. //
  97. // C++: void cv::StereoBM::setTextureThreshold(int textureThreshold)
  98. //
  99. public void setTextureThreshold(int textureThreshold)
  100. {
  101. ThrowIfDisposed();
  102. calib3d_StereoBM_setTextureThreshold_10(nativeObj, textureThreshold);
  103. }
  104. //
  105. // C++: int cv::StereoBM::getUniquenessRatio()
  106. //
  107. public int getUniquenessRatio()
  108. {
  109. ThrowIfDisposed();
  110. return calib3d_StereoBM_getUniquenessRatio_10(nativeObj);
  111. }
  112. //
  113. // C++: void cv::StereoBM::setUniquenessRatio(int uniquenessRatio)
  114. //
  115. public void setUniquenessRatio(int uniquenessRatio)
  116. {
  117. ThrowIfDisposed();
  118. calib3d_StereoBM_setUniquenessRatio_10(nativeObj, uniquenessRatio);
  119. }
  120. //
  121. // C++: int cv::StereoBM::getSmallerBlockSize()
  122. //
  123. public int getSmallerBlockSize()
  124. {
  125. ThrowIfDisposed();
  126. return calib3d_StereoBM_getSmallerBlockSize_10(nativeObj);
  127. }
  128. //
  129. // C++: void cv::StereoBM::setSmallerBlockSize(int blockSize)
  130. //
  131. public void setSmallerBlockSize(int blockSize)
  132. {
  133. ThrowIfDisposed();
  134. calib3d_StereoBM_setSmallerBlockSize_10(nativeObj, blockSize);
  135. }
  136. //
  137. // C++: Rect cv::StereoBM::getROI1()
  138. //
  139. public Rect getROI1()
  140. {
  141. ThrowIfDisposed();
  142. double[] tmpArray = new double[4];
  143. calib3d_StereoBM_getROI1_10(nativeObj, tmpArray);
  144. Rect retVal = new Rect(tmpArray);
  145. return retVal;
  146. }
  147. //
  148. // C++: void cv::StereoBM::setROI1(Rect roi1)
  149. //
  150. public void setROI1(Rect roi1)
  151. {
  152. ThrowIfDisposed();
  153. calib3d_StereoBM_setROI1_10(nativeObj, roi1.x, roi1.y, roi1.width, roi1.height);
  154. }
  155. //
  156. // C++: Rect cv::StereoBM::getROI2()
  157. //
  158. public Rect getROI2()
  159. {
  160. ThrowIfDisposed();
  161. double[] tmpArray = new double[4];
  162. calib3d_StereoBM_getROI2_10(nativeObj, tmpArray);
  163. Rect retVal = new Rect(tmpArray);
  164. return retVal;
  165. }
  166. //
  167. // C++: void cv::StereoBM::setROI2(Rect roi2)
  168. //
  169. public void setROI2(Rect roi2)
  170. {
  171. ThrowIfDisposed();
  172. calib3d_StereoBM_setROI2_10(nativeObj, roi2.x, roi2.y, roi2.width, roi2.height);
  173. }
  174. //
  175. // C++: static Ptr_StereoBM cv::StereoBM::create(int numDisparities = 0, int blockSize = 21)
  176. //
  177. /**
  178. * Creates StereoBM object
  179. *
  180. * param numDisparities the disparity search range. For each pixel algorithm will find the best
  181. * disparity from 0 (default minimum disparity) to numDisparities. The search range can then be
  182. * shifted by changing the minimum disparity.
  183. * param blockSize the linear size of the blocks compared by the algorithm. The size should be odd
  184. * (as the block is centered at the current pixel). Larger block size implies smoother, though less
  185. * accurate disparity map. Smaller block size gives more detailed disparity map, but there is higher
  186. * chance for algorithm to find a wrong correspondence.
  187. *
  188. * The function create StereoBM object. You can then call StereoBM::compute() to compute disparity for
  189. * a specific stereo pair.
  190. * return automatically generated
  191. */
  192. public static StereoBM create(int numDisparities, int blockSize)
  193. {
  194. return StereoBM.__fromPtr__(DisposableObject.ThrowIfNullIntPtr(calib3d_StereoBM_create_10(numDisparities, blockSize)));
  195. }
  196. /**
  197. * Creates StereoBM object
  198. *
  199. * param numDisparities the disparity search range. For each pixel algorithm will find the best
  200. * disparity from 0 (default minimum disparity) to numDisparities. The search range can then be
  201. * shifted by changing the minimum disparity.
  202. * (as the block is centered at the current pixel). Larger block size implies smoother, though less
  203. * accurate disparity map. Smaller block size gives more detailed disparity map, but there is higher
  204. * chance for algorithm to find a wrong correspondence.
  205. *
  206. * The function create StereoBM object. You can then call StereoBM::compute() to compute disparity for
  207. * a specific stereo pair.
  208. * return automatically generated
  209. */
  210. public static StereoBM create(int numDisparities)
  211. {
  212. return StereoBM.__fromPtr__(DisposableObject.ThrowIfNullIntPtr(calib3d_StereoBM_create_11(numDisparities)));
  213. }
  214. /**
  215. * Creates StereoBM object
  216. *
  217. * disparity from 0 (default minimum disparity) to numDisparities. The search range can then be
  218. * shifted by changing the minimum disparity.
  219. * (as the block is centered at the current pixel). Larger block size implies smoother, though less
  220. * accurate disparity map. Smaller block size gives more detailed disparity map, but there is higher
  221. * chance for algorithm to find a wrong correspondence.
  222. *
  223. * The function create StereoBM object. You can then call StereoBM::compute() to compute disparity for
  224. * a specific stereo pair.
  225. * return automatically generated
  226. */
  227. public static StereoBM create()
  228. {
  229. return StereoBM.__fromPtr__(DisposableObject.ThrowIfNullIntPtr(calib3d_StereoBM_create_12()));
  230. }
  231. #if (UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR
  232. const string LIBNAME = "__Internal";
  233. #else
  234. const string LIBNAME = "opencvforunity";
  235. #endif
  236. // C++: int cv::StereoBM::getPreFilterType()
  237. [DllImport(LIBNAME)]
  238. private static extern int calib3d_StereoBM_getPreFilterType_10(IntPtr nativeObj);
  239. // C++: void cv::StereoBM::setPreFilterType(int preFilterType)
  240. [DllImport(LIBNAME)]
  241. private static extern void calib3d_StereoBM_setPreFilterType_10(IntPtr nativeObj, int preFilterType);
  242. // C++: int cv::StereoBM::getPreFilterSize()
  243. [DllImport(LIBNAME)]
  244. private static extern int calib3d_StereoBM_getPreFilterSize_10(IntPtr nativeObj);
  245. // C++: void cv::StereoBM::setPreFilterSize(int preFilterSize)
  246. [DllImport(LIBNAME)]
  247. private static extern void calib3d_StereoBM_setPreFilterSize_10(IntPtr nativeObj, int preFilterSize);
  248. // C++: int cv::StereoBM::getPreFilterCap()
  249. [DllImport(LIBNAME)]
  250. private static extern int calib3d_StereoBM_getPreFilterCap_10(IntPtr nativeObj);
  251. // C++: void cv::StereoBM::setPreFilterCap(int preFilterCap)
  252. [DllImport(LIBNAME)]
  253. private static extern void calib3d_StereoBM_setPreFilterCap_10(IntPtr nativeObj, int preFilterCap);
  254. // C++: int cv::StereoBM::getTextureThreshold()
  255. [DllImport(LIBNAME)]
  256. private static extern int calib3d_StereoBM_getTextureThreshold_10(IntPtr nativeObj);
  257. // C++: void cv::StereoBM::setTextureThreshold(int textureThreshold)
  258. [DllImport(LIBNAME)]
  259. private static extern void calib3d_StereoBM_setTextureThreshold_10(IntPtr nativeObj, int textureThreshold);
  260. // C++: int cv::StereoBM::getUniquenessRatio()
  261. [DllImport(LIBNAME)]
  262. private static extern int calib3d_StereoBM_getUniquenessRatio_10(IntPtr nativeObj);
  263. // C++: void cv::StereoBM::setUniquenessRatio(int uniquenessRatio)
  264. [DllImport(LIBNAME)]
  265. private static extern void calib3d_StereoBM_setUniquenessRatio_10(IntPtr nativeObj, int uniquenessRatio);
  266. // C++: int cv::StereoBM::getSmallerBlockSize()
  267. [DllImport(LIBNAME)]
  268. private static extern int calib3d_StereoBM_getSmallerBlockSize_10(IntPtr nativeObj);
  269. // C++: void cv::StereoBM::setSmallerBlockSize(int blockSize)
  270. [DllImport(LIBNAME)]
  271. private static extern void calib3d_StereoBM_setSmallerBlockSize_10(IntPtr nativeObj, int blockSize);
  272. // C++: Rect cv::StereoBM::getROI1()
  273. [DllImport(LIBNAME)]
  274. private static extern void calib3d_StereoBM_getROI1_10(IntPtr nativeObj, double[] retVal);
  275. // C++: void cv::StereoBM::setROI1(Rect roi1)
  276. [DllImport(LIBNAME)]
  277. private static extern void calib3d_StereoBM_setROI1_10(IntPtr nativeObj, int roi1_x, int roi1_y, int roi1_width, int roi1_height);
  278. // C++: Rect cv::StereoBM::getROI2()
  279. [DllImport(LIBNAME)]
  280. private static extern void calib3d_StereoBM_getROI2_10(IntPtr nativeObj, double[] retVal);
  281. // C++: void cv::StereoBM::setROI2(Rect roi2)
  282. [DllImport(LIBNAME)]
  283. private static extern void calib3d_StereoBM_setROI2_10(IntPtr nativeObj, int roi2_x, int roi2_y, int roi2_width, int roi2_height);
  284. // C++: static Ptr_StereoBM cv::StereoBM::create(int numDisparities = 0, int blockSize = 21)
  285. [DllImport(LIBNAME)]
  286. private static extern IntPtr calib3d_StereoBM_create_10(int numDisparities, int blockSize);
  287. [DllImport(LIBNAME)]
  288. private static extern IntPtr calib3d_StereoBM_create_11(int numDisparities);
  289. [DllImport(LIBNAME)]
  290. private static extern IntPtr calib3d_StereoBM_create_12();
  291. // native support for java finalize()
  292. [DllImport(LIBNAME)]
  293. private static extern void calib3d_StereoBM_delete(IntPtr nativeObj);
  294. }
  295. }