gapi_stereo_tests_inl.hpp 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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 distribution and at http://opencv.org/license.html.
  4. //
  5. // Copyright (C) 2021 Intel Corporation
  6. #ifndef OPENCV_GAPI_STEREO_TESTS_INL_HPP
  7. #define OPENCV_GAPI_STEREO_TESTS_INL_HPP
  8. #include <opencv2/gapi/stereo.hpp>
  9. #include <opencv2/gapi/cpu/stereo.hpp>
  10. #include "gapi_stereo_tests.hpp"
  11. #ifdef HAVE_OPENCV_CALIB3D
  12. #include <opencv2/calib3d.hpp>
  13. namespace opencv_test {
  14. TEST_P(TestGAPIStereo, DisparityDepthTest)
  15. {
  16. using format = cv::gapi::StereoOutputFormat;
  17. switch(oF) {
  18. case format::DEPTH_FLOAT16: dtype = CV_16FC1; break;
  19. case format::DEPTH_FLOAT32: dtype = CV_32FC1; break;
  20. case format::DISPARITY_FIXED16_12_4: dtype = CV_16SC1; break;
  21. default: GAPI_Assert(false && "Unsupported format in test");
  22. }
  23. initOutMats(sz, dtype);
  24. // G-API
  25. cv::GMat inL, inR;
  26. cv::GMat out = cv::gapi::stereo(inL, inR, oF);
  27. cv::GComputation(cv::GIn(inL, inR), cv::GOut(out))
  28. .apply(cv::gin(in_mat1, in_mat2), cv::gout(out_mat_gapi),
  29. cv::compile_args(cv::gapi::calib3d::cpu::kernels(),
  30. cv::gapi::calib3d::cpu::StereoInitParam {
  31. numDisparities,
  32. blockSize,
  33. baseline,
  34. focus}));
  35. // OpenCV
  36. cv::StereoBM::create(numDisparities, blockSize)->compute(in_mat1,
  37. in_mat2,
  38. out_mat_ocv);
  39. static const int DISPARITY_SHIFT_16S = 4;
  40. switch(oF) {
  41. case format::DEPTH_FLOAT16:
  42. out_mat_ocv.convertTo(out_mat_ocv, CV_32FC1, 1./(1 << DISPARITY_SHIFT_16S), 0);
  43. out_mat_ocv = (focus * baseline) / out_mat_ocv;
  44. out_mat_ocv.convertTo(out_mat_ocv, CV_16FC1);
  45. break;
  46. case format::DEPTH_FLOAT32:
  47. out_mat_ocv.convertTo(out_mat_ocv, CV_32FC1, 1./(1 << DISPARITY_SHIFT_16S), 0);
  48. out_mat_ocv = (focus * baseline) / out_mat_ocv;
  49. break;
  50. case format::DISPARITY_FIXED16_12_4:
  51. break;
  52. default:
  53. GAPI_Assert(false && "Unsupported format in test");
  54. }
  55. EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
  56. }
  57. } // namespace opencv_test
  58. #endif // HAVE_OPENCV_CALIB3D
  59. #endif // OPENCV_GAPI_STEREO_TESTS_INL_HPP