mirror of
https://github.com/opencv/opencv.git
synced 2025-06-23 12:11:35 +08:00

Fixed default cap_prop_orientation_auto behaviour #26800 Fixes : #26795 ### Pull Request Readiness Checklist See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request - [x] I agree to contribute to the project under Apache 2 License. - [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV - [x] The PR is proposed to the proper branch - [x] There is a reference to the original bug report and related work - [ ] There is accuracy test, performance test and test data in opencv_extra repository, if applicable Patch to opencv_extra has the same branch name. - [ ] The feature is well documented and sample code can be built with the project CMake
88 lines
2.4 KiB
C++
88 lines
2.4 KiB
C++
// This file is part of OpenCV project.
|
|
// It is subject to the license terms in the LICENSE file found in the top-level directory
|
|
// of this distribution and at http://opencv.org/license.html.
|
|
|
|
#include "test_precomp.hpp"
|
|
|
|
using namespace std;
|
|
|
|
namespace opencv_test { namespace {
|
|
|
|
// PR: https://github.com/opencv/opencv/pull/26800
|
|
// TODO: Enable the tests back on Windows after FFmpeg plugin rebuild
|
|
#ifndef _WIN32
|
|
|
|
struct VideoCaptureAPITests: TestWithParam<cv::VideoCaptureAPIs>
|
|
{
|
|
void SetUp()
|
|
{
|
|
cv::VideoCaptureAPIs api = GetParam();
|
|
if (!videoio_registry::hasBackend(api))
|
|
throw SkipTestException("backend " + std::to_string(int(api)) + " was not found");
|
|
|
|
string video_file = string(cvtest::TS::ptr()->get_data_path()) + "video/rotated_metadata.mp4";
|
|
|
|
EXPECT_NO_THROW(cap.open(video_file, api));
|
|
ASSERT_TRUE(cap.isOpened()) << "Can't open the video: " << video_file << " with backend " << api << std::endl;
|
|
}
|
|
|
|
void tearDown()
|
|
{
|
|
cap.release();
|
|
}
|
|
|
|
void orientationCheck(double angle, int width, int height)
|
|
{
|
|
EXPECT_EQ(angle, cap.get(CAP_PROP_ORIENTATION_META));
|
|
EXPECT_EQ(width, (int)cap.get(CAP_PROP_FRAME_WIDTH));
|
|
EXPECT_EQ(height, (int)cap.get(CAP_PROP_FRAME_HEIGHT));
|
|
|
|
Mat frame;
|
|
cap >> frame;
|
|
|
|
ASSERT_EQ(width, frame.cols);
|
|
ASSERT_EQ(height, frame.rows);
|
|
}
|
|
|
|
VideoCapture cap;
|
|
};
|
|
|
|
// Related issues:
|
|
// - https://github.com/opencv/opencv/issues/26795
|
|
// - https://github.com/opencv/opencv/issues/15499
|
|
TEST_P(VideoCaptureAPITests, mp4_orientation_default_auto)
|
|
{
|
|
EXPECT_TRUE(cap.get(CAP_PROP_ORIENTATION_AUTO));
|
|
orientationCheck(90., 270, 480);
|
|
}
|
|
|
|
TEST_P(VideoCaptureAPITests, mp4_orientation_forced)
|
|
{
|
|
EXPECT_TRUE(cap.set(CAP_PROP_ORIENTATION_AUTO, false));
|
|
orientationCheck(90., 480, 270);
|
|
}
|
|
|
|
TEST_P(VideoCaptureAPITests, mp4_orientation_switch)
|
|
{
|
|
SCOPED_TRACE("Initial orientation with autorotation");
|
|
orientationCheck(90., 270, 480);
|
|
SCOPED_TRACE("Disabled autorotation");
|
|
EXPECT_TRUE(cap.set(CAP_PROP_ORIENTATION_AUTO, false));
|
|
EXPECT_FALSE(cap.get(CAP_PROP_ORIENTATION_AUTO));
|
|
orientationCheck(90., 480, 270);
|
|
}
|
|
|
|
|
|
static cv::VideoCaptureAPIs supported_backends[] = {
|
|
#ifdef HAVE_AVFOUNDATION
|
|
CAP_AVFOUNDATION,
|
|
#endif
|
|
CAP_FFMPEG
|
|
};
|
|
|
|
INSTANTIATE_TEST_CASE_P(videoio, VideoCaptureAPITests, testing::ValuesIn(supported_backends));
|
|
|
|
#endif // WIN32
|
|
|
|
}} // namespace
|