stereo.hpp 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. // This file is part of OpenCV project.
  2. // It is subject to the license terms in the LICENSE file found in the top-level directory
  3. // of this distereoibution and at http://opencv.org/license.html.
  4. //
  5. // Copyright (C) 2021 Intel Corporation
  6. #ifndef OPENCV_GAPI_STEREO_HPP
  7. #define OPENCV_GAPI_STEREO_HPP
  8. #include <opencv2/gapi/gmat.hpp>
  9. #include <opencv2/gapi/gscalar.hpp>
  10. #include <opencv2/gapi/gkernel.hpp>
  11. namespace cv {
  12. namespace gapi {
  13. /**
  14. * The enum specified format of result that you get from @ref cv::gapi::stereo.
  15. */
  16. enum class StereoOutputFormat {
  17. DEPTH_FLOAT16, ///< Floating point 16 bit value, CV_16FC1.
  18. ///< This identifier is deprecated, use DEPTH_16F instead.
  19. DEPTH_FLOAT32, ///< Floating point 32 bit value, CV_32FC1
  20. ///< This identifier is deprecated, use DEPTH_16F instead.
  21. DISPARITY_FIXED16_11_5, ///< 16 bit signed: first bit for sign,
  22. ///< 10 bits for integer part,
  23. ///< 5 bits for fractional part.
  24. ///< This identifier is deprecated,
  25. ///< use DISPARITY_16Q_10_5 instead.
  26. DISPARITY_FIXED16_12_4, ///< 16 bit signed: first bit for sign,
  27. ///< 11 bits for integer part,
  28. ///< 4 bits for fractional part.
  29. ///< This identifier is deprecated,
  30. ///< use DISPARITY_16Q_11_4 instead.
  31. DEPTH_16F = DEPTH_FLOAT16, ///< Same as DEPTH_FLOAT16
  32. DEPTH_32F = DEPTH_FLOAT32, ///< Same as DEPTH_FLOAT32
  33. DISPARITY_16Q_10_5 = DISPARITY_FIXED16_11_5, ///< Same as DISPARITY_FIXED16_11_5
  34. DISPARITY_16Q_11_4 = DISPARITY_FIXED16_12_4 ///< Same as DISPARITY_FIXED16_12_4
  35. };
  36. /**
  37. * @brief This namespace contains G-API Operation Types for Stereo and
  38. * related functionality.
  39. */
  40. namespace calib3d {
  41. G_TYPED_KERNEL(GStereo, <GMat(GMat, GMat, const StereoOutputFormat)>, "org.opencv.stereo") {
  42. static GMatDesc outMeta(const GMatDesc &left, const GMatDesc &right, const StereoOutputFormat of) {
  43. GAPI_Assert(left.chan == 1);
  44. GAPI_Assert(left.depth == CV_8U);
  45. GAPI_Assert(right.chan == 1);
  46. GAPI_Assert(right.depth == CV_8U);
  47. switch(of) {
  48. case StereoOutputFormat::DEPTH_FLOAT16:
  49. return left.withDepth(CV_16FC1);
  50. case StereoOutputFormat::DEPTH_FLOAT32:
  51. return left.withDepth(CV_32FC1);
  52. case StereoOutputFormat::DISPARITY_FIXED16_11_5:
  53. case StereoOutputFormat::DISPARITY_FIXED16_12_4:
  54. return left.withDepth(CV_16SC1);
  55. default:
  56. GAPI_Assert(false && "Unknown output format!");
  57. }
  58. }
  59. };
  60. } // namespace calib3d
  61. /** @brief Computes disparity/depth map for the specified stereo-pair.
  62. The function computes disparity or depth map depending on passed StereoOutputFormat argument.
  63. @param left 8-bit single-channel left image of @ref CV_8UC1 type.
  64. @param right 8-bit single-channel right image of @ref CV_8UC1 type.
  65. @param of enum to specified output kind: depth or disparity and corresponding type
  66. */
  67. GAPI_EXPORTS GMat stereo(const GMat& left,
  68. const GMat& right,
  69. const StereoOutputFormat of = StereoOutputFormat::DEPTH_FLOAT32);
  70. } // namespace gapi
  71. } // namespace cv
  72. #endif // OPENCV_GAPI_STEREO_HPP