test_orientation.cpp 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. #include "test_precomp.hpp"
  5. using namespace std;
  6. namespace opencv_test { namespace {
  7. struct VideoCaptureAPITests: TestWithParam<cv::VideoCaptureAPIs>
  8. {
  9. void SetUp()
  10. {
  11. cv::VideoCaptureAPIs api = GetParam();
  12. if (!videoio_registry::hasBackend(api))
  13. throw SkipTestException("backend " + std::to_string(int(api)) + " was not found");
  14. string video_file = string(cvtest::TS::ptr()->get_data_path()) + "video/rotated_metadata.mp4";
  15. EXPECT_NO_THROW(cap.open(video_file, api));
  16. ASSERT_TRUE(cap.isOpened()) << "Can't open the video: " << video_file << " with backend " << api << std::endl;
  17. }
  18. void tearDown()
  19. {
  20. cap.release();
  21. }
  22. void orientationCheck(double angle, int width, int height)
  23. {
  24. EXPECT_EQ(angle, cap.get(CAP_PROP_ORIENTATION_META));
  25. EXPECT_EQ(width, (int)cap.get(CAP_PROP_FRAME_WIDTH));
  26. EXPECT_EQ(height, (int)cap.get(CAP_PROP_FRAME_HEIGHT));
  27. Mat frame;
  28. cap >> frame;
  29. ASSERT_EQ(width, frame.cols);
  30. ASSERT_EQ(height, frame.rows);
  31. }
  32. VideoCapture cap;
  33. };
  34. // Related issues:
  35. // - https://github.com/opencv/opencv/issues/26795
  36. // - https://github.com/opencv/opencv/issues/15499
  37. TEST_P(VideoCaptureAPITests, mp4_orientation_default_auto)
  38. {
  39. EXPECT_TRUE(cap.get(CAP_PROP_ORIENTATION_AUTO));
  40. orientationCheck(90., 270, 480);
  41. }
  42. TEST_P(VideoCaptureAPITests, mp4_orientation_forced)
  43. {
  44. EXPECT_TRUE(cap.set(CAP_PROP_ORIENTATION_AUTO, false));
  45. orientationCheck(90., 480, 270);
  46. }
  47. TEST_P(VideoCaptureAPITests, mp4_orientation_switch)
  48. {
  49. SCOPED_TRACE("Initial orientation with autorotation");
  50. orientationCheck(90., 270, 480);
  51. SCOPED_TRACE("Disabled autorotation");
  52. EXPECT_TRUE(cap.set(CAP_PROP_ORIENTATION_AUTO, false));
  53. EXPECT_FALSE(cap.get(CAP_PROP_ORIENTATION_AUTO));
  54. orientationCheck(90., 480, 270);
  55. }
  56. static cv::VideoCaptureAPIs supported_backends[] = {
  57. #ifdef HAVE_AVFOUNDATION
  58. CAP_AVFOUNDATION,
  59. #endif
  60. CAP_FFMPEG
  61. };
  62. inline static std::string VideoCaptureAPITests_name_printer(const testing::TestParamInfo<VideoCaptureAPITests::ParamType>& info)
  63. {
  64. std::ostringstream out;
  65. out << getBackendNameSafe(info.param);
  66. return out.str();
  67. }
  68. INSTANTIATE_TEST_CASE_P(videoio, VideoCaptureAPITests, testing::ValuesIn(supported_backends), VideoCaptureAPITests_name_printer);
  69. }} // namespace