From: Alexander Alekhin Date: Tue, 28 Jul 2020 17:15:02 +0000 (+0000) Subject: Merge remote-tracking branch 'upstream/3.4' into merge-3.4 X-Git-Tag: submit/tizen/20210224.033012~2^2~104 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=afe9993376fee68e016be4a8cd9eb44d154c02d6;p=platform%2Fupstream%2Fopencv.git Merge remote-tracking branch 'upstream/3.4' into merge-3.4 --- afe9993376fee68e016be4a8cd9eb44d154c02d6 diff --cc modules/videoio/src/cap_ffmpeg.cpp index b436b75,9d93637..1c73f6a --- a/modules/videoio/src/cap_ffmpeg.cpp +++ b/modules/videoio/src/cap_ffmpeg.cpp @@@ -113,6 -266,30 +117,30 @@@ public protected: CvCapture_FFMPEG* ffmpegCapture; + + void rotateFrame(cv::Mat &mat) const + { - bool rotation_auto = 0 != getProperty(CV_FFMPEG_CAP_PROP_ORIENTATION_AUTO); - int rotation_angle = static_cast(getProperty(CV_FFMPEG_CAP_PROP_ORIENTATION_META)); ++ bool rotation_auto = 0 != getProperty(CAP_PROP_ORIENTATION_AUTO); ++ int rotation_angle = static_cast(getProperty(CAP_PROP_ORIENTATION_META)); + + if(!rotation_auto || rotation_angle%360 == 0) + { + return; + } + + cv::RotateFlags flag; + if(rotation_angle == 90 || rotation_angle == -270) { // Rotate clockwise 90 degrees + flag = cv::ROTATE_90_CLOCKWISE; + } else if(rotation_angle == 270 || rotation_angle == -90) { // Rotate clockwise 270 degrees + flag = cv::ROTATE_90_COUNTERCLOCKWISE; + } else if(rotation_angle == 180 || rotation_angle == -180) { // Rotate clockwise 180 degrees + flag = cv::ROTATE_180; + } else { // Unsupported rotation + return; + } + + cv::rotate(mat, mat, flag); + } }; } // namespace diff --cc modules/videoio/src/cap_ffmpeg_impl.hpp index fb1a927,b5c0824..97524ef --- a/modules/videoio/src/cap_ffmpeg_impl.hpp +++ b/modules/videoio/src/cap_ffmpeg_impl.hpp @@@ -1385,19 -1405,19 +1398,19 @@@ double CvCapture_FFMPEG::getProperty( i return 0; } return (dts_to_sec(picture_pts) * 1000); - case CV_FFMPEG_CAP_PROP_POS_FRAMES: + case CAP_PROP_POS_FRAMES: return (double)frame_number; - case CV_FFMPEG_CAP_PROP_POS_AVI_RATIO: + case CAP_PROP_POS_AVI_RATIO: return r2d(ic->streams[video_stream]->time_base); - case CV_FFMPEG_CAP_PROP_FRAME_COUNT: + case CAP_PROP_FRAME_COUNT: return (double)get_total_frames(); - case CV_FFMPEG_CAP_PROP_FRAME_WIDTH: + case CAP_PROP_FRAME_WIDTH: - return (double)frame.width; + return (double)((rotation_auto && rotation_angle%180) ? frame.height : frame.width); - case CV_FFMPEG_CAP_PROP_FRAME_HEIGHT: + case CAP_PROP_FRAME_HEIGHT: - return (double)frame.height; + return (double)((rotation_auto && rotation_angle%180) ? frame.width : frame.height); - case CV_FFMPEG_CAP_PROP_FPS: + case CAP_PROP_FPS: return get_fps(); - case CV_FFMPEG_CAP_PROP_FOURCC: + case CAP_PROP_FOURCC: #if LIBAVFORMAT_BUILD > 4628 codec_id = video_st->codec->codec_id; codec_tag = (double) video_st->codec->codec_tag; @@@ -1436,8 -1456,17 +1449,17 @@@ if (rawMode) return -1; break; - case CV_FFMPEG_CAP_PROP_BITRATE: + case CAP_PROP_BITRATE: return static_cast(get_bitrate()); - case CV_FFMPEG_CAP_PROP_ORIENTATION_META: ++ case CAP_PROP_ORIENTATION_META: + return static_cast(rotation_angle); - case CV_FFMPEG_CAP_PROP_ORIENTATION_AUTO: ++ case CAP_PROP_ORIENTATION_AUTO: + #if ((LIBAVFORMAT_BUILD >= CALC_FFMPEG_VERSION(52, 111, 0)) && \ + (LIBAVUTIL_BUILD >= CALC_FFMPEG_VERSION(52, 94, 100))) + return static_cast(rotation_auto); + #else + return 0; + #endif default: break; } @@@ -1611,6 -1651,16 +1644,16 @@@ bool CvCapture_FFMPEG::setProperty( in if (value == -1) return setRaw(); return false; - case CV_FFMPEG_CAP_PROP_ORIENTATION_AUTO: ++ case CAP_PROP_ORIENTATION_AUTO: + #if ((LIBAVFORMAT_BUILD >= CALC_FFMPEG_VERSION(52, 111, 0)) && \ + (LIBAVUTIL_BUILD >= CALC_FFMPEG_VERSION(52, 94, 100))) + rotation_auto = static_cast(value); + return true; + #else + rotation_auto = 0; + return false; + #endif + break; default: return false; } diff --cc modules/videoio/test/test_ffmpeg.cpp index 7fb8339,6acc65f..4bda7f3 --- a/modules/videoio/test/test_ffmpeg.cpp +++ b/modules/videoio/test/test_ffmpeg.cpp @@@ -399,4 -636,57 +399,64 @@@ const ffmpeg_cap_properties_param_t vid INSTANTIATE_TEST_CASE_P(videoio, ffmpeg_cap_properties, testing::ValuesIn(videoio_ffmpeg_properties)); ++ ++ + // related issue: https://github.com/opencv/opencv/issues/15499 + TEST(videoio, mp4_orientation_meta_auto) + { ++ if (!videoio_registry::hasBackend(CAP_FFMPEG)) ++ throw SkipTestException("FFmpeg backend was not found"); ++ + string video_file = string(cvtest::TS::ptr()->get_data_path()) + "video/big_buck_bunny_rotated.mp4"; + + VideoCapture cap; + EXPECT_NO_THROW(cap.open(video_file, CAP_FFMPEG)); + ASSERT_TRUE(cap.isOpened()) << "Can't open the video: " << video_file << " with backend " << CAP_FFMPEG << std::endl; + + cap.set(CAP_PROP_ORIENTATION_AUTO, true); + if (cap.get(CAP_PROP_ORIENTATION_AUTO) == 0) + throw SkipTestException("FFmpeg frame rotation metadata is not supported"); + + Size actual; + EXPECT_NO_THROW(actual = Size((int)cap.get(CAP_PROP_FRAME_WIDTH), + (int)cap.get(CAP_PROP_FRAME_HEIGHT))); + EXPECT_EQ(384, actual.width); + EXPECT_EQ(672, actual.height); + + Mat frame; + + cap >> frame; + + ASSERT_EQ(384, frame.cols); + ASSERT_EQ(672, frame.rows); + } + + // related issue: https://github.com/opencv/opencv/issues/15499 + TEST(videoio, mp4_orientation_no_rotation) + { ++ if (!videoio_registry::hasBackend(CAP_FFMPEG)) ++ throw SkipTestException("FFmpeg backend was not found"); ++ + string video_file = string(cvtest::TS::ptr()->get_data_path()) + "video/big_buck_bunny_rotated.mp4"; + + VideoCapture cap; + EXPECT_NO_THROW(cap.open(video_file, CAP_FFMPEG)); + cap.set(CAP_PROP_ORIENTATION_AUTO, 0); + ASSERT_TRUE(cap.isOpened()) << "Can't open the video: " << video_file << " with backend " << CAP_FFMPEG << std::endl; + ASSERT_FALSE(cap.get(CAP_PROP_ORIENTATION_AUTO)); + + Size actual; + EXPECT_NO_THROW(actual = Size((int)cap.get(CAP_PROP_FRAME_WIDTH), + (int)cap.get(CAP_PROP_FRAME_HEIGHT))); + EXPECT_EQ(672, actual.width); + EXPECT_EQ(384, actual.height); + + Mat frame; + + cap >> frame; + + ASSERT_EQ(672, frame.cols); + ASSERT_EQ(384, frame.rows); + } + -#endif }} // namespace