StereoSGBM.cs 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815
  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 StereoSGBM
  9. /**
  10. * The class implements the modified H. Hirschmuller algorithm CITE: HH08 that differs from the original
  11. * one as follows:
  12. *
  13. * <ul>
  14. * <li>
  15. * By default, the algorithm is single-pass, which means that you consider only 5 directions
  16. * instead of 8. Set mode=StereoSGBM::MODE_HH in createStereoSGBM to run the full variant of the
  17. * algorithm but beware that it may consume a lot of memory.
  18. * </li>
  19. * <li>
  20. * The algorithm matches blocks, not individual pixels. Though, setting blockSize=1 reduces the
  21. * blocks to single pixels.
  22. * </li>
  23. * <li>
  24. * Mutual information cost function is not implemented. Instead, a simpler Birchfield-Tomasi
  25. * sub-pixel metric from CITE: BT98 is used. Though, the color images are supported as well.
  26. * </li>
  27. * <li>
  28. * Some pre- and post- processing steps from K. Konolige algorithm StereoBM are included, for
  29. * example: pre-filtering (StereoBM::PREFILTER_XSOBEL type) and post-filtering (uniqueness
  30. * check, quadratic interpolation and speckle filtering).
  31. * </li>
  32. * </ul>
  33. *
  34. * <b>Note:</b>
  35. * <ul>
  36. * <li>
  37. * (Python) An example illustrating the use of the StereoSGBM matching algorithm can be found
  38. * at opencv_source_code/samples/python/stereo_match.py
  39. * </li>
  40. * </ul>
  41. */
  42. public class StereoSGBM : StereoMatcher
  43. {
  44. protected override void Dispose(bool disposing)
  45. {
  46. try
  47. {
  48. if (disposing)
  49. {
  50. }
  51. if (IsEnabledDispose)
  52. {
  53. if (nativeObj != IntPtr.Zero)
  54. calib3d_StereoSGBM_delete(nativeObj);
  55. nativeObj = IntPtr.Zero;
  56. }
  57. }
  58. finally
  59. {
  60. base.Dispose(disposing);
  61. }
  62. }
  63. protected internal StereoSGBM(IntPtr addr) : base(addr) { }
  64. // internal usage only
  65. public static new StereoSGBM __fromPtr__(IntPtr addr) { return new StereoSGBM(addr); }
  66. // C++: enum <unnamed>
  67. public const int MODE_SGBM = 0;
  68. public const int MODE_HH = 1;
  69. public const int MODE_SGBM_3WAY = 2;
  70. public const int MODE_HH4 = 3;
  71. //
  72. // C++: int cv::StereoSGBM::getPreFilterCap()
  73. //
  74. public int getPreFilterCap()
  75. {
  76. ThrowIfDisposed();
  77. return calib3d_StereoSGBM_getPreFilterCap_10(nativeObj);
  78. }
  79. //
  80. // C++: void cv::StereoSGBM::setPreFilterCap(int preFilterCap)
  81. //
  82. public void setPreFilterCap(int preFilterCap)
  83. {
  84. ThrowIfDisposed();
  85. calib3d_StereoSGBM_setPreFilterCap_10(nativeObj, preFilterCap);
  86. }
  87. //
  88. // C++: int cv::StereoSGBM::getUniquenessRatio()
  89. //
  90. public int getUniquenessRatio()
  91. {
  92. ThrowIfDisposed();
  93. return calib3d_StereoSGBM_getUniquenessRatio_10(nativeObj);
  94. }
  95. //
  96. // C++: void cv::StereoSGBM::setUniquenessRatio(int uniquenessRatio)
  97. //
  98. public void setUniquenessRatio(int uniquenessRatio)
  99. {
  100. ThrowIfDisposed();
  101. calib3d_StereoSGBM_setUniquenessRatio_10(nativeObj, uniquenessRatio);
  102. }
  103. //
  104. // C++: int cv::StereoSGBM::getP1()
  105. //
  106. public int getP1()
  107. {
  108. ThrowIfDisposed();
  109. return calib3d_StereoSGBM_getP1_10(nativeObj);
  110. }
  111. //
  112. // C++: void cv::StereoSGBM::setP1(int P1)
  113. //
  114. public void setP1(int P1)
  115. {
  116. ThrowIfDisposed();
  117. calib3d_StereoSGBM_setP1_10(nativeObj, P1);
  118. }
  119. //
  120. // C++: int cv::StereoSGBM::getP2()
  121. //
  122. public int getP2()
  123. {
  124. ThrowIfDisposed();
  125. return calib3d_StereoSGBM_getP2_10(nativeObj);
  126. }
  127. //
  128. // C++: void cv::StereoSGBM::setP2(int P2)
  129. //
  130. public void setP2(int P2)
  131. {
  132. ThrowIfDisposed();
  133. calib3d_StereoSGBM_setP2_10(nativeObj, P2);
  134. }
  135. //
  136. // C++: int cv::StereoSGBM::getMode()
  137. //
  138. public int getMode()
  139. {
  140. ThrowIfDisposed();
  141. return calib3d_StereoSGBM_getMode_10(nativeObj);
  142. }
  143. //
  144. // C++: void cv::StereoSGBM::setMode(int mode)
  145. //
  146. public void setMode(int mode)
  147. {
  148. ThrowIfDisposed();
  149. calib3d_StereoSGBM_setMode_10(nativeObj, mode);
  150. }
  151. //
  152. // C++: static Ptr_StereoSGBM cv::StereoSGBM::create(int minDisparity = 0, int numDisparities = 16, int blockSize = 3, int P1 = 0, int P2 = 0, int disp12MaxDiff = 0, int preFilterCap = 0, int uniquenessRatio = 0, int speckleWindowSize = 0, int speckleRange = 0, int mode = StereoSGBM::MODE_SGBM)
  153. //
  154. /**
  155. * Creates StereoSGBM object
  156. *
  157. * param minDisparity Minimum possible disparity value. Normally, it is zero but sometimes
  158. * rectification algorithms can shift images, so this parameter needs to be adjusted accordingly.
  159. * param numDisparities Maximum disparity minus minimum disparity. The value is always greater than
  160. * zero. In the current implementation, this parameter must be divisible by 16.
  161. * param blockSize Matched block size. It must be an odd number &gt;=1 . Normally, it should be
  162. * somewhere in the 3..11 range.
  163. * param P1 The first parameter controlling the disparity smoothness. See below.
  164. * param P2 The second parameter controlling the disparity smoothness. The larger the values are,
  165. * the smoother the disparity is. P1 is the penalty on the disparity change by plus or minus 1
  166. * between neighbor pixels. P2 is the penalty on the disparity change by more than 1 between neighbor
  167. * pixels. The algorithm requires P2 &gt; P1 . See stereo_match.cpp sample where some reasonably good
  168. * P1 and P2 values are shown (like 8\*number_of_image_channels\*blockSize\*blockSize and
  169. * 32\*number_of_image_channels\*blockSize\*blockSize , respectively).
  170. * param disp12MaxDiff Maximum allowed difference (in integer pixel units) in the left-right
  171. * disparity check. Set it to a non-positive value to disable the check.
  172. * param preFilterCap Truncation value for the prefiltered image pixels. The algorithm first
  173. * computes x-derivative at each pixel and clips its value by [-preFilterCap, preFilterCap] interval.
  174. * The result values are passed to the Birchfield-Tomasi pixel cost function.
  175. * param uniquenessRatio Margin in percentage by which the best (minimum) computed cost function
  176. * value should "win" the second best value to consider the found match correct. Normally, a value
  177. * within the 5-15 range is good enough.
  178. * param speckleWindowSize Maximum size of smooth disparity regions to consider their noise speckles
  179. * and invalidate. Set it to 0 to disable speckle filtering. Otherwise, set it somewhere in the
  180. * 50-200 range.
  181. * param speckleRange Maximum disparity variation within each connected component. If you do speckle
  182. * filtering, set the parameter to a positive value, it will be implicitly multiplied by 16.
  183. * Normally, 1 or 2 is good enough.
  184. * param mode Set it to StereoSGBM::MODE_HH to run the full-scale two-pass dynamic programming
  185. * algorithm. It will consume O(W\*H\*numDisparities) bytes, which is large for 640x480 stereo and
  186. * huge for HD-size pictures. By default, it is set to false .
  187. *
  188. * The first constructor initializes StereoSGBM with all the default parameters. So, you only have to
  189. * set StereoSGBM::numDisparities at minimum. The second constructor enables you to set each parameter
  190. * to a custom value.
  191. * return automatically generated
  192. */
  193. public static StereoSGBM create(int minDisparity, int numDisparities, int blockSize, int P1, int P2, int disp12MaxDiff, int preFilterCap, int uniquenessRatio, int speckleWindowSize, int speckleRange, int mode)
  194. {
  195. return StereoSGBM.__fromPtr__(DisposableObject.ThrowIfNullIntPtr(calib3d_StereoSGBM_create_10(minDisparity, numDisparities, blockSize, P1, P2, disp12MaxDiff, preFilterCap, uniquenessRatio, speckleWindowSize, speckleRange, mode)));
  196. }
  197. /**
  198. * Creates StereoSGBM object
  199. *
  200. * param minDisparity Minimum possible disparity value. Normally, it is zero but sometimes
  201. * rectification algorithms can shift images, so this parameter needs to be adjusted accordingly.
  202. * param numDisparities Maximum disparity minus minimum disparity. The value is always greater than
  203. * zero. In the current implementation, this parameter must be divisible by 16.
  204. * param blockSize Matched block size. It must be an odd number &gt;=1 . Normally, it should be
  205. * somewhere in the 3..11 range.
  206. * param P1 The first parameter controlling the disparity smoothness. See below.
  207. * param P2 The second parameter controlling the disparity smoothness. The larger the values are,
  208. * the smoother the disparity is. P1 is the penalty on the disparity change by plus or minus 1
  209. * between neighbor pixels. P2 is the penalty on the disparity change by more than 1 between neighbor
  210. * pixels. The algorithm requires P2 &gt; P1 . See stereo_match.cpp sample where some reasonably good
  211. * P1 and P2 values are shown (like 8\*number_of_image_channels\*blockSize\*blockSize and
  212. * 32\*number_of_image_channels\*blockSize\*blockSize , respectively).
  213. * param disp12MaxDiff Maximum allowed difference (in integer pixel units) in the left-right
  214. * disparity check. Set it to a non-positive value to disable the check.
  215. * param preFilterCap Truncation value for the prefiltered image pixels. The algorithm first
  216. * computes x-derivative at each pixel and clips its value by [-preFilterCap, preFilterCap] interval.
  217. * The result values are passed to the Birchfield-Tomasi pixel cost function.
  218. * param uniquenessRatio Margin in percentage by which the best (minimum) computed cost function
  219. * value should "win" the second best value to consider the found match correct. Normally, a value
  220. * within the 5-15 range is good enough.
  221. * param speckleWindowSize Maximum size of smooth disparity regions to consider their noise speckles
  222. * and invalidate. Set it to 0 to disable speckle filtering. Otherwise, set it somewhere in the
  223. * 50-200 range.
  224. * param speckleRange Maximum disparity variation within each connected component. If you do speckle
  225. * filtering, set the parameter to a positive value, it will be implicitly multiplied by 16.
  226. * Normally, 1 or 2 is good enough.
  227. * algorithm. It will consume O(W\*H\*numDisparities) bytes, which is large for 640x480 stereo and
  228. * huge for HD-size pictures. By default, it is set to false .
  229. *
  230. * The first constructor initializes StereoSGBM with all the default parameters. So, you only have to
  231. * set StereoSGBM::numDisparities at minimum. The second constructor enables you to set each parameter
  232. * to a custom value.
  233. * return automatically generated
  234. */
  235. public static StereoSGBM create(int minDisparity, int numDisparities, int blockSize, int P1, int P2, int disp12MaxDiff, int preFilterCap, int uniquenessRatio, int speckleWindowSize, int speckleRange)
  236. {
  237. return StereoSGBM.__fromPtr__(DisposableObject.ThrowIfNullIntPtr(calib3d_StereoSGBM_create_11(minDisparity, numDisparities, blockSize, P1, P2, disp12MaxDiff, preFilterCap, uniquenessRatio, speckleWindowSize, speckleRange)));
  238. }
  239. /**
  240. * Creates StereoSGBM object
  241. *
  242. * param minDisparity Minimum possible disparity value. Normally, it is zero but sometimes
  243. * rectification algorithms can shift images, so this parameter needs to be adjusted accordingly.
  244. * param numDisparities Maximum disparity minus minimum disparity. The value is always greater than
  245. * zero. In the current implementation, this parameter must be divisible by 16.
  246. * param blockSize Matched block size. It must be an odd number &gt;=1 . Normally, it should be
  247. * somewhere in the 3..11 range.
  248. * param P1 The first parameter controlling the disparity smoothness. See below.
  249. * param P2 The second parameter controlling the disparity smoothness. The larger the values are,
  250. * the smoother the disparity is. P1 is the penalty on the disparity change by plus or minus 1
  251. * between neighbor pixels. P2 is the penalty on the disparity change by more than 1 between neighbor
  252. * pixels. The algorithm requires P2 &gt; P1 . See stereo_match.cpp sample where some reasonably good
  253. * P1 and P2 values are shown (like 8\*number_of_image_channels\*blockSize\*blockSize and
  254. * 32\*number_of_image_channels\*blockSize\*blockSize , respectively).
  255. * param disp12MaxDiff Maximum allowed difference (in integer pixel units) in the left-right
  256. * disparity check. Set it to a non-positive value to disable the check.
  257. * param preFilterCap Truncation value for the prefiltered image pixels. The algorithm first
  258. * computes x-derivative at each pixel and clips its value by [-preFilterCap, preFilterCap] interval.
  259. * The result values are passed to the Birchfield-Tomasi pixel cost function.
  260. * param uniquenessRatio Margin in percentage by which the best (minimum) computed cost function
  261. * value should "win" the second best value to consider the found match correct. Normally, a value
  262. * within the 5-15 range is good enough.
  263. * param speckleWindowSize Maximum size of smooth disparity regions to consider their noise speckles
  264. * and invalidate. Set it to 0 to disable speckle filtering. Otherwise, set it somewhere in the
  265. * 50-200 range.
  266. * filtering, set the parameter to a positive value, it will be implicitly multiplied by 16.
  267. * Normally, 1 or 2 is good enough.
  268. * algorithm. It will consume O(W\*H\*numDisparities) bytes, which is large for 640x480 stereo and
  269. * huge for HD-size pictures. By default, it is set to false .
  270. *
  271. * The first constructor initializes StereoSGBM with all the default parameters. So, you only have to
  272. * set StereoSGBM::numDisparities at minimum. The second constructor enables you to set each parameter
  273. * to a custom value.
  274. * return automatically generated
  275. */
  276. public static StereoSGBM create(int minDisparity, int numDisparities, int blockSize, int P1, int P2, int disp12MaxDiff, int preFilterCap, int uniquenessRatio, int speckleWindowSize)
  277. {
  278. return StereoSGBM.__fromPtr__(DisposableObject.ThrowIfNullIntPtr(calib3d_StereoSGBM_create_12(minDisparity, numDisparities, blockSize, P1, P2, disp12MaxDiff, preFilterCap, uniquenessRatio, speckleWindowSize)));
  279. }
  280. /**
  281. * Creates StereoSGBM object
  282. *
  283. * param minDisparity Minimum possible disparity value. Normally, it is zero but sometimes
  284. * rectification algorithms can shift images, so this parameter needs to be adjusted accordingly.
  285. * param numDisparities Maximum disparity minus minimum disparity. The value is always greater than
  286. * zero. In the current implementation, this parameter must be divisible by 16.
  287. * param blockSize Matched block size. It must be an odd number &gt;=1 . Normally, it should be
  288. * somewhere in the 3..11 range.
  289. * param P1 The first parameter controlling the disparity smoothness. See below.
  290. * param P2 The second parameter controlling the disparity smoothness. The larger the values are,
  291. * the smoother the disparity is. P1 is the penalty on the disparity change by plus or minus 1
  292. * between neighbor pixels. P2 is the penalty on the disparity change by more than 1 between neighbor
  293. * pixels. The algorithm requires P2 &gt; P1 . See stereo_match.cpp sample where some reasonably good
  294. * P1 and P2 values are shown (like 8\*number_of_image_channels\*blockSize\*blockSize and
  295. * 32\*number_of_image_channels\*blockSize\*blockSize , respectively).
  296. * param disp12MaxDiff Maximum allowed difference (in integer pixel units) in the left-right
  297. * disparity check. Set it to a non-positive value to disable the check.
  298. * param preFilterCap Truncation value for the prefiltered image pixels. The algorithm first
  299. * computes x-derivative at each pixel and clips its value by [-preFilterCap, preFilterCap] interval.
  300. * The result values are passed to the Birchfield-Tomasi pixel cost function.
  301. * param uniquenessRatio Margin in percentage by which the best (minimum) computed cost function
  302. * value should "win" the second best value to consider the found match correct. Normally, a value
  303. * within the 5-15 range is good enough.
  304. * and invalidate. Set it to 0 to disable speckle filtering. Otherwise, set it somewhere in the
  305. * 50-200 range.
  306. * filtering, set the parameter to a positive value, it will be implicitly multiplied by 16.
  307. * Normally, 1 or 2 is good enough.
  308. * algorithm. It will consume O(W\*H\*numDisparities) bytes, which is large for 640x480 stereo and
  309. * huge for HD-size pictures. By default, it is set to false .
  310. *
  311. * The first constructor initializes StereoSGBM with all the default parameters. So, you only have to
  312. * set StereoSGBM::numDisparities at minimum. The second constructor enables you to set each parameter
  313. * to a custom value.
  314. * return automatically generated
  315. */
  316. public static StereoSGBM create(int minDisparity, int numDisparities, int blockSize, int P1, int P2, int disp12MaxDiff, int preFilterCap, int uniquenessRatio)
  317. {
  318. return StereoSGBM.__fromPtr__(DisposableObject.ThrowIfNullIntPtr(calib3d_StereoSGBM_create_13(minDisparity, numDisparities, blockSize, P1, P2, disp12MaxDiff, preFilterCap, uniquenessRatio)));
  319. }
  320. /**
  321. * Creates StereoSGBM object
  322. *
  323. * param minDisparity Minimum possible disparity value. Normally, it is zero but sometimes
  324. * rectification algorithms can shift images, so this parameter needs to be adjusted accordingly.
  325. * param numDisparities Maximum disparity minus minimum disparity. The value is always greater than
  326. * zero. In the current implementation, this parameter must be divisible by 16.
  327. * param blockSize Matched block size. It must be an odd number &gt;=1 . Normally, it should be
  328. * somewhere in the 3..11 range.
  329. * param P1 The first parameter controlling the disparity smoothness. See below.
  330. * param P2 The second parameter controlling the disparity smoothness. The larger the values are,
  331. * the smoother the disparity is. P1 is the penalty on the disparity change by plus or minus 1
  332. * between neighbor pixels. P2 is the penalty on the disparity change by more than 1 between neighbor
  333. * pixels. The algorithm requires P2 &gt; P1 . See stereo_match.cpp sample where some reasonably good
  334. * P1 and P2 values are shown (like 8\*number_of_image_channels\*blockSize\*blockSize and
  335. * 32\*number_of_image_channels\*blockSize\*blockSize , respectively).
  336. * param disp12MaxDiff Maximum allowed difference (in integer pixel units) in the left-right
  337. * disparity check. Set it to a non-positive value to disable the check.
  338. * param preFilterCap Truncation value for the prefiltered image pixels. The algorithm first
  339. * computes x-derivative at each pixel and clips its value by [-preFilterCap, preFilterCap] interval.
  340. * The result values are passed to the Birchfield-Tomasi pixel cost function.
  341. * value should "win" the second best value to consider the found match correct. Normally, a value
  342. * within the 5-15 range is good enough.
  343. * and invalidate. Set it to 0 to disable speckle filtering. Otherwise, set it somewhere in the
  344. * 50-200 range.
  345. * filtering, set the parameter to a positive value, it will be implicitly multiplied by 16.
  346. * Normally, 1 or 2 is good enough.
  347. * algorithm. It will consume O(W\*H\*numDisparities) bytes, which is large for 640x480 stereo and
  348. * huge for HD-size pictures. By default, it is set to false .
  349. *
  350. * The first constructor initializes StereoSGBM with all the default parameters. So, you only have to
  351. * set StereoSGBM::numDisparities at minimum. The second constructor enables you to set each parameter
  352. * to a custom value.
  353. * return automatically generated
  354. */
  355. public static StereoSGBM create(int minDisparity, int numDisparities, int blockSize, int P1, int P2, int disp12MaxDiff, int preFilterCap)
  356. {
  357. return StereoSGBM.__fromPtr__(DisposableObject.ThrowIfNullIntPtr(calib3d_StereoSGBM_create_14(minDisparity, numDisparities, blockSize, P1, P2, disp12MaxDiff, preFilterCap)));
  358. }
  359. /**
  360. * Creates StereoSGBM object
  361. *
  362. * param minDisparity Minimum possible disparity value. Normally, it is zero but sometimes
  363. * rectification algorithms can shift images, so this parameter needs to be adjusted accordingly.
  364. * param numDisparities Maximum disparity minus minimum disparity. The value is always greater than
  365. * zero. In the current implementation, this parameter must be divisible by 16.
  366. * param blockSize Matched block size. It must be an odd number &gt;=1 . Normally, it should be
  367. * somewhere in the 3..11 range.
  368. * param P1 The first parameter controlling the disparity smoothness. See below.
  369. * param P2 The second parameter controlling the disparity smoothness. The larger the values are,
  370. * the smoother the disparity is. P1 is the penalty on the disparity change by plus or minus 1
  371. * between neighbor pixels. P2 is the penalty on the disparity change by more than 1 between neighbor
  372. * pixels. The algorithm requires P2 &gt; P1 . See stereo_match.cpp sample where some reasonably good
  373. * P1 and P2 values are shown (like 8\*number_of_image_channels\*blockSize\*blockSize and
  374. * 32\*number_of_image_channels\*blockSize\*blockSize , respectively).
  375. * param disp12MaxDiff Maximum allowed difference (in integer pixel units) in the left-right
  376. * disparity check. Set it to a non-positive value to disable the check.
  377. * computes x-derivative at each pixel and clips its value by [-preFilterCap, preFilterCap] interval.
  378. * The result values are passed to the Birchfield-Tomasi pixel cost function.
  379. * value should "win" the second best value to consider the found match correct. Normally, a value
  380. * within the 5-15 range is good enough.
  381. * and invalidate. Set it to 0 to disable speckle filtering. Otherwise, set it somewhere in the
  382. * 50-200 range.
  383. * filtering, set the parameter to a positive value, it will be implicitly multiplied by 16.
  384. * Normally, 1 or 2 is good enough.
  385. * algorithm. It will consume O(W\*H\*numDisparities) bytes, which is large for 640x480 stereo and
  386. * huge for HD-size pictures. By default, it is set to false .
  387. *
  388. * The first constructor initializes StereoSGBM with all the default parameters. So, you only have to
  389. * set StereoSGBM::numDisparities at minimum. The second constructor enables you to set each parameter
  390. * to a custom value.
  391. * return automatically generated
  392. */
  393. public static StereoSGBM create(int minDisparity, int numDisparities, int blockSize, int P1, int P2, int disp12MaxDiff)
  394. {
  395. return StereoSGBM.__fromPtr__(DisposableObject.ThrowIfNullIntPtr(calib3d_StereoSGBM_create_15(minDisparity, numDisparities, blockSize, P1, P2, disp12MaxDiff)));
  396. }
  397. /**
  398. * Creates StereoSGBM object
  399. *
  400. * param minDisparity Minimum possible disparity value. Normally, it is zero but sometimes
  401. * rectification algorithms can shift images, so this parameter needs to be adjusted accordingly.
  402. * param numDisparities Maximum disparity minus minimum disparity. The value is always greater than
  403. * zero. In the current implementation, this parameter must be divisible by 16.
  404. * param blockSize Matched block size. It must be an odd number &gt;=1 . Normally, it should be
  405. * somewhere in the 3..11 range.
  406. * param P1 The first parameter controlling the disparity smoothness. See below.
  407. * param P2 The second parameter controlling the disparity smoothness. The larger the values are,
  408. * the smoother the disparity is. P1 is the penalty on the disparity change by plus or minus 1
  409. * between neighbor pixels. P2 is the penalty on the disparity change by more than 1 between neighbor
  410. * pixels. The algorithm requires P2 &gt; P1 . See stereo_match.cpp sample where some reasonably good
  411. * P1 and P2 values are shown (like 8\*number_of_image_channels\*blockSize\*blockSize and
  412. * 32\*number_of_image_channels\*blockSize\*blockSize , respectively).
  413. * disparity check. Set it to a non-positive value to disable the check.
  414. * computes x-derivative at each pixel and clips its value by [-preFilterCap, preFilterCap] interval.
  415. * The result values are passed to the Birchfield-Tomasi pixel cost function.
  416. * value should "win" the second best value to consider the found match correct. Normally, a value
  417. * within the 5-15 range is good enough.
  418. * and invalidate. Set it to 0 to disable speckle filtering. Otherwise, set it somewhere in the
  419. * 50-200 range.
  420. * filtering, set the parameter to a positive value, it will be implicitly multiplied by 16.
  421. * Normally, 1 or 2 is good enough.
  422. * algorithm. It will consume O(W\*H\*numDisparities) bytes, which is large for 640x480 stereo and
  423. * huge for HD-size pictures. By default, it is set to false .
  424. *
  425. * The first constructor initializes StereoSGBM with all the default parameters. So, you only have to
  426. * set StereoSGBM::numDisparities at minimum. The second constructor enables you to set each parameter
  427. * to a custom value.
  428. * return automatically generated
  429. */
  430. public static StereoSGBM create(int minDisparity, int numDisparities, int blockSize, int P1, int P2)
  431. {
  432. return StereoSGBM.__fromPtr__(DisposableObject.ThrowIfNullIntPtr(calib3d_StereoSGBM_create_16(minDisparity, numDisparities, blockSize, P1, P2)));
  433. }
  434. /**
  435. * Creates StereoSGBM object
  436. *
  437. * param minDisparity Minimum possible disparity value. Normally, it is zero but sometimes
  438. * rectification algorithms can shift images, so this parameter needs to be adjusted accordingly.
  439. * param numDisparities Maximum disparity minus minimum disparity. The value is always greater than
  440. * zero. In the current implementation, this parameter must be divisible by 16.
  441. * param blockSize Matched block size. It must be an odd number &gt;=1 . Normally, it should be
  442. * somewhere in the 3..11 range.
  443. * param P1 The first parameter controlling the disparity smoothness. See below.
  444. * the smoother the disparity is. P1 is the penalty on the disparity change by plus or minus 1
  445. * between neighbor pixels. P2 is the penalty on the disparity change by more than 1 between neighbor
  446. * pixels. The algorithm requires P2 &gt; P1 . See stereo_match.cpp sample where some reasonably good
  447. * P1 and P2 values are shown (like 8\*number_of_image_channels\*blockSize\*blockSize and
  448. * 32\*number_of_image_channels\*blockSize\*blockSize , respectively).
  449. * disparity check. Set it to a non-positive value to disable the check.
  450. * computes x-derivative at each pixel and clips its value by [-preFilterCap, preFilterCap] interval.
  451. * The result values are passed to the Birchfield-Tomasi pixel cost function.
  452. * value should "win" the second best value to consider the found match correct. Normally, a value
  453. * within the 5-15 range is good enough.
  454. * and invalidate. Set it to 0 to disable speckle filtering. Otherwise, set it somewhere in the
  455. * 50-200 range.
  456. * filtering, set the parameter to a positive value, it will be implicitly multiplied by 16.
  457. * Normally, 1 or 2 is good enough.
  458. * algorithm. It will consume O(W\*H\*numDisparities) bytes, which is large for 640x480 stereo and
  459. * huge for HD-size pictures. By default, it is set to false .
  460. *
  461. * The first constructor initializes StereoSGBM with all the default parameters. So, you only have to
  462. * set StereoSGBM::numDisparities at minimum. The second constructor enables you to set each parameter
  463. * to a custom value.
  464. * return automatically generated
  465. */
  466. public static StereoSGBM create(int minDisparity, int numDisparities, int blockSize, int P1)
  467. {
  468. return StereoSGBM.__fromPtr__(DisposableObject.ThrowIfNullIntPtr(calib3d_StereoSGBM_create_17(minDisparity, numDisparities, blockSize, P1)));
  469. }
  470. /**
  471. * Creates StereoSGBM object
  472. *
  473. * param minDisparity Minimum possible disparity value. Normally, it is zero but sometimes
  474. * rectification algorithms can shift images, so this parameter needs to be adjusted accordingly.
  475. * param numDisparities Maximum disparity minus minimum disparity. The value is always greater than
  476. * zero. In the current implementation, this parameter must be divisible by 16.
  477. * param blockSize Matched block size. It must be an odd number &gt;=1 . Normally, it should be
  478. * somewhere in the 3..11 range.
  479. * the smoother the disparity is. P1 is the penalty on the disparity change by plus or minus 1
  480. * between neighbor pixels. P2 is the penalty on the disparity change by more than 1 between neighbor
  481. * pixels. The algorithm requires P2 &gt; P1 . See stereo_match.cpp sample where some reasonably good
  482. * P1 and P2 values are shown (like 8\*number_of_image_channels\*blockSize\*blockSize and
  483. * 32\*number_of_image_channels\*blockSize\*blockSize , respectively).
  484. * disparity check. Set it to a non-positive value to disable the check.
  485. * computes x-derivative at each pixel and clips its value by [-preFilterCap, preFilterCap] interval.
  486. * The result values are passed to the Birchfield-Tomasi pixel cost function.
  487. * value should "win" the second best value to consider the found match correct. Normally, a value
  488. * within the 5-15 range is good enough.
  489. * and invalidate. Set it to 0 to disable speckle filtering. Otherwise, set it somewhere in the
  490. * 50-200 range.
  491. * filtering, set the parameter to a positive value, it will be implicitly multiplied by 16.
  492. * Normally, 1 or 2 is good enough.
  493. * algorithm. It will consume O(W\*H\*numDisparities) bytes, which is large for 640x480 stereo and
  494. * huge for HD-size pictures. By default, it is set to false .
  495. *
  496. * The first constructor initializes StereoSGBM with all the default parameters. So, you only have to
  497. * set StereoSGBM::numDisparities at minimum. The second constructor enables you to set each parameter
  498. * to a custom value.
  499. * return automatically generated
  500. */
  501. public static StereoSGBM create(int minDisparity, int numDisparities, int blockSize)
  502. {
  503. return StereoSGBM.__fromPtr__(DisposableObject.ThrowIfNullIntPtr(calib3d_StereoSGBM_create_18(minDisparity, numDisparities, blockSize)));
  504. }
  505. /**
  506. * Creates StereoSGBM object
  507. *
  508. * param minDisparity Minimum possible disparity value. Normally, it is zero but sometimes
  509. * rectification algorithms can shift images, so this parameter needs to be adjusted accordingly.
  510. * param numDisparities Maximum disparity minus minimum disparity. The value is always greater than
  511. * zero. In the current implementation, this parameter must be divisible by 16.
  512. * somewhere in the 3..11 range.
  513. * the smoother the disparity is. P1 is the penalty on the disparity change by plus or minus 1
  514. * between neighbor pixels. P2 is the penalty on the disparity change by more than 1 between neighbor
  515. * pixels. The algorithm requires P2 &gt; P1 . See stereo_match.cpp sample where some reasonably good
  516. * P1 and P2 values are shown (like 8\*number_of_image_channels\*blockSize\*blockSize and
  517. * 32\*number_of_image_channels\*blockSize\*blockSize , respectively).
  518. * disparity check. Set it to a non-positive value to disable the check.
  519. * computes x-derivative at each pixel and clips its value by [-preFilterCap, preFilterCap] interval.
  520. * The result values are passed to the Birchfield-Tomasi pixel cost function.
  521. * value should "win" the second best value to consider the found match correct. Normally, a value
  522. * within the 5-15 range is good enough.
  523. * and invalidate. Set it to 0 to disable speckle filtering. Otherwise, set it somewhere in the
  524. * 50-200 range.
  525. * filtering, set the parameter to a positive value, it will be implicitly multiplied by 16.
  526. * Normally, 1 or 2 is good enough.
  527. * algorithm. It will consume O(W\*H\*numDisparities) bytes, which is large for 640x480 stereo and
  528. * huge for HD-size pictures. By default, it is set to false .
  529. *
  530. * The first constructor initializes StereoSGBM with all the default parameters. So, you only have to
  531. * set StereoSGBM::numDisparities at minimum. The second constructor enables you to set each parameter
  532. * to a custom value.
  533. * return automatically generated
  534. */
  535. public static StereoSGBM create(int minDisparity, int numDisparities)
  536. {
  537. return StereoSGBM.__fromPtr__(DisposableObject.ThrowIfNullIntPtr(calib3d_StereoSGBM_create_19(minDisparity, numDisparities)));
  538. }
  539. /**
  540. * Creates StereoSGBM object
  541. *
  542. * param minDisparity Minimum possible disparity value. Normally, it is zero but sometimes
  543. * rectification algorithms can shift images, so this parameter needs to be adjusted accordingly.
  544. * zero. In the current implementation, this parameter must be divisible by 16.
  545. * somewhere in the 3..11 range.
  546. * the smoother the disparity is. P1 is the penalty on the disparity change by plus or minus 1
  547. * between neighbor pixels. P2 is the penalty on the disparity change by more than 1 between neighbor
  548. * pixels. The algorithm requires P2 &gt; P1 . See stereo_match.cpp sample where some reasonably good
  549. * P1 and P2 values are shown (like 8\*number_of_image_channels\*blockSize\*blockSize and
  550. * 32\*number_of_image_channels\*blockSize\*blockSize , respectively).
  551. * disparity check. Set it to a non-positive value to disable the check.
  552. * computes x-derivative at each pixel and clips its value by [-preFilterCap, preFilterCap] interval.
  553. * The result values are passed to the Birchfield-Tomasi pixel cost function.
  554. * value should "win" the second best value to consider the found match correct. Normally, a value
  555. * within the 5-15 range is good enough.
  556. * and invalidate. Set it to 0 to disable speckle filtering. Otherwise, set it somewhere in the
  557. * 50-200 range.
  558. * filtering, set the parameter to a positive value, it will be implicitly multiplied by 16.
  559. * Normally, 1 or 2 is good enough.
  560. * algorithm. It will consume O(W\*H\*numDisparities) bytes, which is large for 640x480 stereo and
  561. * huge for HD-size pictures. By default, it is set to false .
  562. *
  563. * The first constructor initializes StereoSGBM with all the default parameters. So, you only have to
  564. * set StereoSGBM::numDisparities at minimum. The second constructor enables you to set each parameter
  565. * to a custom value.
  566. * return automatically generated
  567. */
  568. public static StereoSGBM create(int minDisparity)
  569. {
  570. return StereoSGBM.__fromPtr__(DisposableObject.ThrowIfNullIntPtr(calib3d_StereoSGBM_create_110(minDisparity)));
  571. }
  572. /**
  573. * Creates StereoSGBM object
  574. *
  575. * rectification algorithms can shift images, so this parameter needs to be adjusted accordingly.
  576. * zero. In the current implementation, this parameter must be divisible by 16.
  577. * somewhere in the 3..11 range.
  578. * the smoother the disparity is. P1 is the penalty on the disparity change by plus or minus 1
  579. * between neighbor pixels. P2 is the penalty on the disparity change by more than 1 between neighbor
  580. * pixels. The algorithm requires P2 &gt; P1 . See stereo_match.cpp sample where some reasonably good
  581. * P1 and P2 values are shown (like 8\*number_of_image_channels\*blockSize\*blockSize and
  582. * 32\*number_of_image_channels\*blockSize\*blockSize , respectively).
  583. * disparity check. Set it to a non-positive value to disable the check.
  584. * computes x-derivative at each pixel and clips its value by [-preFilterCap, preFilterCap] interval.
  585. * The result values are passed to the Birchfield-Tomasi pixel cost function.
  586. * value should "win" the second best value to consider the found match correct. Normally, a value
  587. * within the 5-15 range is good enough.
  588. * and invalidate. Set it to 0 to disable speckle filtering. Otherwise, set it somewhere in the
  589. * 50-200 range.
  590. * filtering, set the parameter to a positive value, it will be implicitly multiplied by 16.
  591. * Normally, 1 or 2 is good enough.
  592. * algorithm. It will consume O(W\*H\*numDisparities) bytes, which is large for 640x480 stereo and
  593. * huge for HD-size pictures. By default, it is set to false .
  594. *
  595. * The first constructor initializes StereoSGBM with all the default parameters. So, you only have to
  596. * set StereoSGBM::numDisparities at minimum. The second constructor enables you to set each parameter
  597. * to a custom value.
  598. * return automatically generated
  599. */
  600. public static StereoSGBM create()
  601. {
  602. return StereoSGBM.__fromPtr__(DisposableObject.ThrowIfNullIntPtr(calib3d_StereoSGBM_create_111()));
  603. }
  604. #if (UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR
  605. const string LIBNAME = "__Internal";
  606. #else
  607. const string LIBNAME = "opencvforunity";
  608. #endif
  609. // C++: int cv::StereoSGBM::getPreFilterCap()
  610. [DllImport(LIBNAME)]
  611. private static extern int calib3d_StereoSGBM_getPreFilterCap_10(IntPtr nativeObj);
  612. // C++: void cv::StereoSGBM::setPreFilterCap(int preFilterCap)
  613. [DllImport(LIBNAME)]
  614. private static extern void calib3d_StereoSGBM_setPreFilterCap_10(IntPtr nativeObj, int preFilterCap);
  615. // C++: int cv::StereoSGBM::getUniquenessRatio()
  616. [DllImport(LIBNAME)]
  617. private static extern int calib3d_StereoSGBM_getUniquenessRatio_10(IntPtr nativeObj);
  618. // C++: void cv::StereoSGBM::setUniquenessRatio(int uniquenessRatio)
  619. [DllImport(LIBNAME)]
  620. private static extern void calib3d_StereoSGBM_setUniquenessRatio_10(IntPtr nativeObj, int uniquenessRatio);
  621. // C++: int cv::StereoSGBM::getP1()
  622. [DllImport(LIBNAME)]
  623. private static extern int calib3d_StereoSGBM_getP1_10(IntPtr nativeObj);
  624. // C++: void cv::StereoSGBM::setP1(int P1)
  625. [DllImport(LIBNAME)]
  626. private static extern void calib3d_StereoSGBM_setP1_10(IntPtr nativeObj, int P1);
  627. // C++: int cv::StereoSGBM::getP2()
  628. [DllImport(LIBNAME)]
  629. private static extern int calib3d_StereoSGBM_getP2_10(IntPtr nativeObj);
  630. // C++: void cv::StereoSGBM::setP2(int P2)
  631. [DllImport(LIBNAME)]
  632. private static extern void calib3d_StereoSGBM_setP2_10(IntPtr nativeObj, int P2);
  633. // C++: int cv::StereoSGBM::getMode()
  634. [DllImport(LIBNAME)]
  635. private static extern int calib3d_StereoSGBM_getMode_10(IntPtr nativeObj);
  636. // C++: void cv::StereoSGBM::setMode(int mode)
  637. [DllImport(LIBNAME)]
  638. private static extern void calib3d_StereoSGBM_setMode_10(IntPtr nativeObj, int mode);
  639. // C++: static Ptr_StereoSGBM cv::StereoSGBM::create(int minDisparity = 0, int numDisparities = 16, int blockSize = 3, int P1 = 0, int P2 = 0, int disp12MaxDiff = 0, int preFilterCap = 0, int uniquenessRatio = 0, int speckleWindowSize = 0, int speckleRange = 0, int mode = StereoSGBM::MODE_SGBM)
  640. [DllImport(LIBNAME)]
  641. private static extern IntPtr calib3d_StereoSGBM_create_10(int minDisparity, int numDisparities, int blockSize, int P1, int P2, int disp12MaxDiff, int preFilterCap, int uniquenessRatio, int speckleWindowSize, int speckleRange, int mode);
  642. [DllImport(LIBNAME)]
  643. private static extern IntPtr calib3d_StereoSGBM_create_11(int minDisparity, int numDisparities, int blockSize, int P1, int P2, int disp12MaxDiff, int preFilterCap, int uniquenessRatio, int speckleWindowSize, int speckleRange);
  644. [DllImport(LIBNAME)]
  645. private static extern IntPtr calib3d_StereoSGBM_create_12(int minDisparity, int numDisparities, int blockSize, int P1, int P2, int disp12MaxDiff, int preFilterCap, int uniquenessRatio, int speckleWindowSize);
  646. [DllImport(LIBNAME)]
  647. private static extern IntPtr calib3d_StereoSGBM_create_13(int minDisparity, int numDisparities, int blockSize, int P1, int P2, int disp12MaxDiff, int preFilterCap, int uniquenessRatio);
  648. [DllImport(LIBNAME)]
  649. private static extern IntPtr calib3d_StereoSGBM_create_14(int minDisparity, int numDisparities, int blockSize, int P1, int P2, int disp12MaxDiff, int preFilterCap);
  650. [DllImport(LIBNAME)]
  651. private static extern IntPtr calib3d_StereoSGBM_create_15(int minDisparity, int numDisparities, int blockSize, int P1, int P2, int disp12MaxDiff);
  652. [DllImport(LIBNAME)]
  653. private static extern IntPtr calib3d_StereoSGBM_create_16(int minDisparity, int numDisparities, int blockSize, int P1, int P2);
  654. [DllImport(LIBNAME)]
  655. private static extern IntPtr calib3d_StereoSGBM_create_17(int minDisparity, int numDisparities, int blockSize, int P1);
  656. [DllImport(LIBNAME)]
  657. private static extern IntPtr calib3d_StereoSGBM_create_18(int minDisparity, int numDisparities, int blockSize);
  658. [DllImport(LIBNAME)]
  659. private static extern IntPtr calib3d_StereoSGBM_create_19(int minDisparity, int numDisparities);
  660. [DllImport(LIBNAME)]
  661. private static extern IntPtr calib3d_StereoSGBM_create_110(int minDisparity);
  662. [DllImport(LIBNAME)]
  663. private static extern IntPtr calib3d_StereoSGBM_create_111();
  664. // native support for java finalize()
  665. [DllImport(LIBNAME)]
  666. private static extern void calib3d_StereoSGBM_delete(IntPtr nativeObj);
  667. }
  668. }