2011-02-10 04:55:11 +08:00
|
|
|
/*M///////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
|
|
|
//
|
|
|
|
// By downloading, copying, installing or using the software you agree to this license.
|
|
|
|
// If you do not agree to this license, do not download, install,
|
|
|
|
// copy or use the software.
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// License Agreement
|
|
|
|
// For Open Source Computer Vision Library
|
|
|
|
//
|
|
|
|
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
|
|
|
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
|
|
|
// Third party copyrights are property of their respective owners.
|
|
|
|
//
|
|
|
|
// Redistribution and use in source and binary forms, with or without modification,
|
|
|
|
// are permitted provided that the following conditions are met:
|
|
|
|
//
|
|
|
|
// * Redistribution's of source code must retain the above copyright notice,
|
|
|
|
// this list of conditions and the following disclaimer.
|
|
|
|
//
|
|
|
|
// * Redistribution's in binary form must reproduce the above copyright notice,
|
|
|
|
// this list of conditions and the following disclaimer in the documentation
|
|
|
|
// and/or other materials provided with the distribution.
|
|
|
|
//
|
|
|
|
// * The name of the copyright holders may not be used to endorse or promote products
|
|
|
|
// derived from this software without specific prior written permission.
|
|
|
|
//
|
|
|
|
// This software is provided by the copyright holders and contributors "as is" and
|
|
|
|
// any express or implied warranties, including, but not limited to, the implied
|
|
|
|
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
|
|
|
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
|
|
|
// indirect, incidental, special, exemplary, or consequential damages
|
|
|
|
// (including, but not limited to, procurement of substitute goods or services;
|
|
|
|
// loss of use, data, or profits; or business interruption) however caused
|
|
|
|
// and on any theory of liability, whether in contract, strict liability,
|
|
|
|
// or tort (including negligence or otherwise) arising in any way out of
|
|
|
|
// the use of this software, even if advised of the possibility of such damage.
|
|
|
|
//
|
|
|
|
//M*/
|
|
|
|
|
|
|
|
#include "test_precomp.hpp"
|
2014-07-10 22:27:32 +08:00
|
|
|
#include "opencv2/videoio/videoio_c.h"
|
2017-06-07 01:22:30 +08:00
|
|
|
#include "opencv2/highgui.hpp"
|
|
|
|
#include <cstdio>
|
2011-02-10 04:55:11 +08:00
|
|
|
|
|
|
|
using namespace cv;
|
|
|
|
using namespace std;
|
2017-06-07 01:22:30 +08:00
|
|
|
using namespace std::tr1;
|
2011-02-10 04:55:11 +08:00
|
|
|
|
2017-06-07 01:22:30 +08:00
|
|
|
class Videoio_Test_Base
|
2011-02-10 04:55:11 +08:00
|
|
|
{
|
2011-12-20 15:45:49 +08:00
|
|
|
protected:
|
2017-06-07 01:22:30 +08:00
|
|
|
string ext;
|
|
|
|
string video_file;
|
|
|
|
protected:
|
|
|
|
Videoio_Test_Base() {}
|
|
|
|
virtual ~Videoio_Test_Base() {}
|
|
|
|
virtual void checkFrameContent(Mat &, int) {}
|
|
|
|
virtual void checkFrameCount(int &) {}
|
|
|
|
void checkFrameRead(int idx, VideoCapture & cap)
|
2011-12-20 15:45:49 +08:00
|
|
|
{
|
2017-07-05 18:45:08 +08:00
|
|
|
//int frameID = (int)cap.get(CAP_PROP_POS_FRAMES);
|
2017-06-07 01:22:30 +08:00
|
|
|
Mat img; cap >> img;
|
2017-07-05 18:45:08 +08:00
|
|
|
//std::cout << "idx=" << idx << " img=" << img.size() << " frameID=" << frameID << std::endl;
|
|
|
|
ASSERT_FALSE(img.empty()) << "idx=" << idx;
|
2017-06-07 01:22:30 +08:00
|
|
|
checkFrameContent(img, idx);
|
2011-12-20 15:45:49 +08:00
|
|
|
}
|
2017-06-07 01:22:30 +08:00
|
|
|
void checkFrameSeek(int idx, VideoCapture & cap)
|
2011-12-20 15:45:49 +08:00
|
|
|
{
|
2017-07-05 18:45:08 +08:00
|
|
|
bool canSeek = cap.set(CAP_PROP_POS_FRAMES, idx);
|
|
|
|
if (!canSeek)
|
|
|
|
{
|
|
|
|
std::cout << "Seek to frame '" << idx << "' is not supported. SKIP." << std::endl;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
EXPECT_EQ(idx, (int)cap.get(CAP_PROP_POS_FRAMES));
|
2017-06-07 01:22:30 +08:00
|
|
|
checkFrameRead(idx, cap);
|
|
|
|
}
|
|
|
|
public:
|
|
|
|
void doTest()
|
|
|
|
{
|
|
|
|
VideoCapture cap(video_file);
|
2017-07-05 18:45:08 +08:00
|
|
|
if (!cap.isOpened())
|
|
|
|
{
|
|
|
|
std::cout << "SKIP test: Can't open video: " << video_file << std::endl;
|
|
|
|
return;
|
|
|
|
}
|
2012-02-11 23:28:03 +08:00
|
|
|
|
2017-06-07 01:22:30 +08:00
|
|
|
int n_frames = (int)cap.get(CAP_PROP_FRAME_COUNT);
|
2017-07-05 18:45:08 +08:00
|
|
|
if (n_frames > 0)
|
|
|
|
{
|
|
|
|
ASSERT_GT(n_frames, 0);
|
|
|
|
checkFrameCount(n_frames);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
std::cout << "CAP_PROP_FRAME_COUNT is not supported by backend. Assume 50 frames." << std::endl;
|
|
|
|
n_frames = 50;
|
|
|
|
}
|
2011-12-20 15:45:49 +08:00
|
|
|
|
|
|
|
{
|
2017-06-07 01:22:30 +08:00
|
|
|
SCOPED_TRACE("consecutive read");
|
|
|
|
for (int k = 0; k < n_frames; ++k)
|
|
|
|
{
|
|
|
|
checkFrameRead(k, cap);
|
|
|
|
}
|
2011-12-20 15:45:49 +08:00
|
|
|
}
|
|
|
|
|
2017-07-05 18:45:08 +08:00
|
|
|
bool canSeek = cap.set(CAP_PROP_POS_FRAMES, 0);
|
|
|
|
if (!canSeek)
|
2011-12-20 15:45:49 +08:00
|
|
|
{
|
2017-07-05 18:45:08 +08:00
|
|
|
std::cout << "Seek to frame '0' is not supported. SKIP all 'seek' tests." << std::endl;
|
|
|
|
return;
|
2011-12-20 15:45:49 +08:00
|
|
|
}
|
|
|
|
|
2017-06-07 01:22:30 +08:00
|
|
|
if (ext != "wmv")
|
2011-12-20 15:45:49 +08:00
|
|
|
{
|
2017-06-07 01:22:30 +08:00
|
|
|
SCOPED_TRACE("progressive seek");
|
|
|
|
ASSERT_TRUE(cap.set(CAP_PROP_POS_FRAMES, 0));
|
2017-07-05 18:45:08 +08:00
|
|
|
for (int k = 0; k < n_frames; k += 20)
|
2017-06-07 01:22:30 +08:00
|
|
|
{
|
|
|
|
checkFrameSeek(k, cap);
|
|
|
|
}
|
2011-12-20 15:45:49 +08:00
|
|
|
}
|
2017-07-05 18:45:08 +08:00
|
|
|
|
|
|
|
if (ext != "mpg" && ext != "wmv")
|
|
|
|
{
|
|
|
|
SCOPED_TRACE("random seek");
|
|
|
|
ASSERT_TRUE(cap.set(CAP_PROP_POS_FRAMES, 0));
|
|
|
|
for (int k = 0; k < 10; ++k)
|
|
|
|
{
|
|
|
|
checkFrameSeek(cvtest::TS::ptr()->get_rng().uniform(0, n_frames), cap);
|
|
|
|
}
|
|
|
|
}
|
2011-12-20 15:45:49 +08:00
|
|
|
}
|
2017-06-07 01:22:30 +08:00
|
|
|
};
|
2011-12-20 15:45:49 +08:00
|
|
|
|
2017-06-07 01:22:30 +08:00
|
|
|
//==================================================================================================
|
2012-04-30 22:33:52 +08:00
|
|
|
|
2017-06-07 01:22:30 +08:00
|
|
|
class Videoio_Bunny : public Videoio_Test_Base, public testing::TestWithParam<string>
|
2012-03-28 23:27:55 +08:00
|
|
|
{
|
2017-06-07 01:22:30 +08:00
|
|
|
public:
|
|
|
|
Videoio_Bunny()
|
2011-12-20 15:45:49 +08:00
|
|
|
{
|
2017-06-07 01:22:30 +08:00
|
|
|
ext = GetParam();
|
|
|
|
video_file = cvtest::TS::ptr()->get_data_path() + "video/big_buck_bunny." + ext;
|
2011-12-20 15:45:49 +08:00
|
|
|
}
|
2017-06-07 01:22:30 +08:00
|
|
|
void doFrameCountTest()
|
2011-12-20 15:45:49 +08:00
|
|
|
{
|
2017-06-07 01:22:30 +08:00
|
|
|
VideoCapture cap(video_file);
|
2017-07-05 18:45:08 +08:00
|
|
|
if (!cap.isOpened())
|
|
|
|
{
|
|
|
|
std::cout << "SKIP test: Can't open video: " << video_file << std::endl;
|
|
|
|
return;
|
|
|
|
}
|
2017-06-07 01:22:30 +08:00
|
|
|
|
|
|
|
const int width_gt = 672;
|
|
|
|
const int height_gt = 384;
|
|
|
|
const int fps_gt = 24;
|
|
|
|
const double time_gt = 5.21;
|
|
|
|
const int count_gt = cvRound(fps_gt * time_gt); // 5.21 sec * 24 fps
|
|
|
|
|
|
|
|
EXPECT_EQ(width_gt, cap.get(CAP_PROP_FRAME_WIDTH));
|
|
|
|
EXPECT_EQ(height_gt, cap.get(CAP_PROP_FRAME_HEIGHT));
|
|
|
|
|
2017-07-05 18:45:08 +08:00
|
|
|
double fps_prop = cap.get(CAP_PROP_FPS);
|
|
|
|
if (fps_prop > 0)
|
|
|
|
EXPECT_NEAR(fps_prop, fps_gt, 1);
|
|
|
|
else
|
|
|
|
std::cout << "FPS is not available. SKIP check." << std::endl;
|
2017-06-07 01:22:30 +08:00
|
|
|
|
|
|
|
int count_prop = (int)cap.get(CAP_PROP_FRAME_COUNT);
|
2017-07-05 18:45:08 +08:00
|
|
|
|
2017-06-07 01:22:30 +08:00
|
|
|
// mpg file reports 5.08 sec * 24 fps => property returns 122 frames
|
|
|
|
// but actual number of frames returned is 125
|
|
|
|
if (ext != "mpg")
|
2011-12-20 15:45:49 +08:00
|
|
|
{
|
2017-07-05 18:45:08 +08:00
|
|
|
if (count_prop > 0)
|
2017-09-11 21:04:00 +08:00
|
|
|
{
|
2017-07-05 18:45:08 +08:00
|
|
|
EXPECT_EQ(count_gt, count_prop);
|
2017-09-11 21:04:00 +08:00
|
|
|
}
|
2011-12-20 15:45:49 +08:00
|
|
|
}
|
|
|
|
|
2017-06-07 01:22:30 +08:00
|
|
|
int count_actual = 0;
|
|
|
|
while (cap.isOpened())
|
|
|
|
{
|
|
|
|
Mat frame;
|
|
|
|
cap >> frame;
|
|
|
|
if (frame.empty())
|
|
|
|
break;
|
|
|
|
EXPECT_EQ(width_gt, frame.cols);
|
|
|
|
EXPECT_EQ(height_gt, frame.rows);
|
|
|
|
count_actual += 1;
|
|
|
|
}
|
2017-07-05 18:45:08 +08:00
|
|
|
if (count_prop > 0)
|
2017-09-11 21:04:00 +08:00
|
|
|
{
|
2017-07-05 18:45:08 +08:00
|
|
|
EXPECT_NEAR(count_gt, count_actual, 1);
|
2017-09-11 21:04:00 +08:00
|
|
|
}
|
2017-07-05 18:45:08 +08:00
|
|
|
else
|
|
|
|
std::cout << "Frames counter is not available. Actual frames: " << count_actual << ". SKIP check." << std::endl;
|
2011-12-20 15:45:49 +08:00
|
|
|
}
|
2017-06-07 01:22:30 +08:00
|
|
|
};
|
2011-12-20 15:45:49 +08:00
|
|
|
|
2017-06-07 01:22:30 +08:00
|
|
|
typedef tuple<string, string, float> Ext_Fourcc_PSNR;
|
|
|
|
typedef tuple<Size, Ext_Fourcc_PSNR> Size_Ext_Fourcc_PSNR;
|
2011-12-20 15:45:49 +08:00
|
|
|
|
2017-06-07 01:22:30 +08:00
|
|
|
class Videoio_Synthetic : public Videoio_Test_Base, public testing::TestWithParam<Size_Ext_Fourcc_PSNR>
|
|
|
|
{
|
|
|
|
Size frame_size;
|
|
|
|
int fourcc;
|
|
|
|
float PSNR_GT;
|
|
|
|
int frame_count;
|
|
|
|
double fps;
|
|
|
|
public:
|
|
|
|
Videoio_Synthetic()
|
2011-12-20 15:45:49 +08:00
|
|
|
{
|
2017-06-07 01:22:30 +08:00
|
|
|
frame_size = get<0>(GetParam());
|
|
|
|
const Ext_Fourcc_PSNR ¶m = get<1>(GetParam());
|
|
|
|
ext = get<0>(param);
|
|
|
|
fourcc = fourccFromString(get<1>(param));
|
|
|
|
PSNR_GT = get<2>(param);
|
|
|
|
video_file = cv::tempfile((fourccToString(fourcc) + "." + ext).c_str());
|
|
|
|
frame_count = 100;
|
|
|
|
fps = 25.;
|
2011-12-20 15:45:49 +08:00
|
|
|
}
|
2017-06-07 01:22:30 +08:00
|
|
|
void SetUp()
|
2011-12-20 15:45:49 +08:00
|
|
|
{
|
2017-06-07 01:22:30 +08:00
|
|
|
Mat img(frame_size, CV_8UC3);
|
|
|
|
VideoWriter writer(video_file, fourcc, fps, frame_size, true);
|
|
|
|
ASSERT_TRUE(writer.isOpened());
|
|
|
|
for(int i = 0; i < frame_count; ++i )
|
2011-12-20 15:45:49 +08:00
|
|
|
{
|
2017-06-07 01:22:30 +08:00
|
|
|
generateFrame(i, frame_count, img);
|
|
|
|
writer << img;
|
2011-12-20 15:45:49 +08:00
|
|
|
}
|
2017-06-07 01:22:30 +08:00
|
|
|
writer.release();
|
2011-12-20 15:45:49 +08:00
|
|
|
}
|
2017-06-07 01:22:30 +08:00
|
|
|
void TearDown()
|
2012-02-11 23:28:03 +08:00
|
|
|
{
|
2017-06-07 01:22:30 +08:00
|
|
|
remove(video_file.c_str());
|
2012-02-11 23:28:03 +08:00
|
|
|
}
|
2017-06-07 01:22:30 +08:00
|
|
|
virtual void checkFrameContent(Mat & img, int idx)
|
2012-04-30 22:33:52 +08:00
|
|
|
{
|
2017-06-07 01:22:30 +08:00
|
|
|
Mat imgGT(frame_size, CV_8UC3);
|
|
|
|
generateFrame(idx, frame_count, imgGT);
|
|
|
|
double psnr = cvtest::PSNR(img, imgGT);
|
|
|
|
ASSERT_GT(psnr, PSNR_GT) << "frame " << idx;
|
2012-04-30 22:33:52 +08:00
|
|
|
}
|
2017-06-07 01:22:30 +08:00
|
|
|
virtual void checkFrameCount(int &actual)
|
2012-04-30 22:33:52 +08:00
|
|
|
{
|
2017-06-07 01:22:30 +08:00
|
|
|
Range expected_frame_count = Range(frame_count, frame_count);
|
|
|
|
|
|
|
|
// Hack! Newer FFmpeg versions in this combination produce a file
|
|
|
|
// whose reported duration is one frame longer than needed, and so
|
|
|
|
// the calculated frame count is also off by one. Ideally, we'd want
|
|
|
|
// to fix both writing (to produce the correct duration) and reading
|
|
|
|
// (to correctly report frame count for such files), but I don't know
|
|
|
|
// how to do either, so this is a workaround for now.
|
|
|
|
if (fourcc == VideoWriter::fourcc('M', 'P', 'E', 'G') && ext == "mkv")
|
|
|
|
expected_frame_count.end += 1;
|
|
|
|
|
|
|
|
// Hack! Some GStreamer encoding pipelines drop last frame in the video
|
|
|
|
#ifdef HAVE_GSTREAMER
|
|
|
|
expected_frame_count.start -= 1;
|
|
|
|
#endif
|
2012-06-09 23:00:04 +08:00
|
|
|
|
2017-06-07 01:22:30 +08:00
|
|
|
ASSERT_LE(expected_frame_count.start, actual);
|
|
|
|
ASSERT_GE(expected_frame_count.end, actual);
|
2012-02-11 23:28:03 +08:00
|
|
|
|
2017-06-07 01:22:30 +08:00
|
|
|
actual = expected_frame_count.start; // adjust actual frame boundary to possible minimum
|
2012-02-11 23:28:03 +08:00
|
|
|
}
|
2017-06-07 01:22:30 +08:00
|
|
|
};
|
2012-02-11 23:28:03 +08:00
|
|
|
|
2017-06-07 01:22:30 +08:00
|
|
|
//==================================================================================================
|
2013-10-24 18:09:08 +08:00
|
|
|
|
|
|
|
|
2017-06-07 01:22:30 +08:00
|
|
|
string bunny_params[] = {
|
|
|
|
#ifdef HAVE_VIDEO_INPUT
|
|
|
|
string("avi"),
|
|
|
|
string("mov"),
|
|
|
|
string("mp4"),
|
|
|
|
string("mpg"),
|
|
|
|
string("wmv"),
|
2014-09-16 21:05:36 +08:00
|
|
|
#endif
|
2017-06-07 01:22:30 +08:00
|
|
|
string("mjpg.avi")
|
|
|
|
};
|
2014-09-16 21:05:36 +08:00
|
|
|
|
2017-06-07 01:22:30 +08:00
|
|
|
TEST_P(Videoio_Bunny, read_position) { doTest(); }
|
2014-09-16 17:57:44 +08:00
|
|
|
|
2017-06-07 01:22:30 +08:00
|
|
|
TEST_P(Videoio_Bunny, frame_count) { doFrameCountTest(); }
|
2012-02-11 23:28:03 +08:00
|
|
|
|
2017-06-07 01:22:30 +08:00
|
|
|
INSTANTIATE_TEST_CASE_P(videoio, Videoio_Bunny,
|
|
|
|
testing::ValuesIn(bunny_params));
|
2012-02-11 23:28:03 +08:00
|
|
|
|
|
|
|
|
2017-06-07 01:22:30 +08:00
|
|
|
//==================================================================================================
|
2012-02-11 23:28:03 +08:00
|
|
|
|
2017-06-07 01:22:30 +08:00
|
|
|
inline Ext_Fourcc_PSNR makeParam(const char * ext, const char * fourcc, float psnr)
|
2012-02-11 23:28:03 +08:00
|
|
|
{
|
2017-06-07 01:22:30 +08:00
|
|
|
return make_tuple(string(ext), string(fourcc), (float)psnr);
|
2012-02-11 23:28:03 +08:00
|
|
|
}
|
|
|
|
|
2017-06-07 01:22:30 +08:00
|
|
|
Ext_Fourcc_PSNR synthetic_params[] = {
|
2012-02-11 23:28:03 +08:00
|
|
|
|
2017-06-07 01:22:30 +08:00
|
|
|
#if defined(HAVE_VIDEO_INPUT) && defined(HAVE_VIDEO_OUTPUT) && !defined(__APPLE__)
|
2012-02-11 23:28:03 +08:00
|
|
|
|
2017-06-07 01:22:30 +08:00
|
|
|
#ifdef HAVE_MSMF
|
2011-02-10 04:55:11 +08:00
|
|
|
|
2017-06-07 01:22:30 +08:00
|
|
|
#if !defined(_M_ARM)
|
2017-07-05 18:45:08 +08:00
|
|
|
makeParam("wmv", "WMV1", 30.f),
|
|
|
|
makeParam("wmv", "WMV2", 30.f),
|
2012-03-22 21:36:07 +08:00
|
|
|
#endif
|
2017-07-05 18:45:08 +08:00
|
|
|
makeParam("wmv", "WMV3", 30.f),
|
|
|
|
makeParam("avi", "H264", 30.f),
|
|
|
|
makeParam("wmv", "WVC1", 30.f),
|
2017-06-07 01:22:30 +08:00
|
|
|
|
|
|
|
#else // HAVE_MSMF
|
|
|
|
|
2017-07-05 18:45:08 +08:00
|
|
|
makeParam("avi", "XVID", 30.f),
|
|
|
|
makeParam("avi", "MPEG", 30.f),
|
|
|
|
makeParam("avi", "IYUV", 30.f),
|
|
|
|
makeParam("mkv", "XVID", 30.f),
|
|
|
|
makeParam("mkv", "MPEG", 30.f),
|
|
|
|
makeParam("mkv", "MJPG", 30.f),
|
2017-06-07 01:22:30 +08:00
|
|
|
#ifndef HAVE_GSTREAMER
|
2017-07-05 18:45:08 +08:00
|
|
|
makeParam("mov", "mp4v", 30.f),
|
2012-04-30 22:33:52 +08:00
|
|
|
#endif
|
|
|
|
|
2017-06-07 01:22:30 +08:00
|
|
|
#endif // HAVE_MSMF
|
|
|
|
|
|
|
|
#endif // HAVE_VIDEO_INPUT && HAVE_VIDEO_OUTPUT ...
|
|
|
|
|
2017-07-05 18:45:08 +08:00
|
|
|
makeParam("avi", "MJPG", 30.f)
|
2017-06-07 01:22:30 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
Size all_sizes[] = {
|
|
|
|
Size(640, 480),
|
|
|
|
Size(976, 768)
|
|
|
|
};
|
|
|
|
|
|
|
|
TEST_P(Videoio_Synthetic, write_read_position) { doTest(); }
|
|
|
|
|
|
|
|
INSTANTIATE_TEST_CASE_P(videoio, Videoio_Synthetic,
|
|
|
|
testing::Combine(
|
|
|
|
testing::ValuesIn(all_sizes),
|
|
|
|
testing::ValuesIn(synthetic_params)));
|