Split highgui module to videoio and highgui

This commit is contained in:
vbystricky
2014-07-10 18:27:32 +04:00
committed by VBystricky
parent f773cd9a3e
commit d58f736935
149 changed files with 1673 additions and 1309 deletions

View File

@@ -1,400 +0,0 @@
/*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"
#include "opencv2/highgui.hpp"
using namespace cv;
#ifdef HAVE_FFMPEG
using namespace std;
class CV_FFmpegWriteBigVideoTest : public cvtest::BaseTest
{
public:
void run(int)
{
const int img_r = 4096;
const int img_c = 4096;
const double fps0 = 15;
const double time_sec = 1;
const int tags[] = {
0,
//VideoWriter::fourcc('D', 'I', 'V', '3'),
//VideoWriter::fourcc('D', 'I', 'V', 'X'),
VideoWriter::fourcc('D', 'X', '5', '0'),
VideoWriter::fourcc('F', 'L', 'V', '1'),
VideoWriter::fourcc('H', '2', '6', '1'),
VideoWriter::fourcc('H', '2', '6', '3'),
VideoWriter::fourcc('I', '4', '2', '0'),
//VideoWriter::fourcc('j', 'p', 'e', 'g'),
VideoWriter::fourcc('M', 'J', 'P', 'G'),
VideoWriter::fourcc('m', 'p', '4', 'v'),
VideoWriter::fourcc('M', 'P', 'E', 'G'),
//VideoWriter::fourcc('W', 'M', 'V', '1'),
//VideoWriter::fourcc('W', 'M', 'V', '2'),
VideoWriter::fourcc('X', 'V', 'I', 'D'),
//VideoWriter::fourcc('Y', 'U', 'Y', '2'),
};
const size_t n = sizeof(tags)/sizeof(tags[0]);
bool created = false;
for (size_t j = 0; j < n; ++j)
{
int tag = tags[j];
stringstream s;
s << tag;
const string filename = tempfile((s.str()+".avi").c_str());
try
{
double fps = fps0;
Size frame_s = Size(img_c, img_r);
if( tag == VideoWriter::fourcc('H', '2', '6', '1') )
frame_s = Size(352, 288);
else if( tag == VideoWriter::fourcc('H', '2', '6', '3') )
frame_s = Size(704, 576);
/*else if( tag == CV_FOURCC('M', 'J', 'P', 'G') ||
tag == CV_FOURCC('j', 'p', 'e', 'g') )
frame_s = Size(1920, 1080);*/
if( tag == VideoWriter::fourcc('M', 'P', 'E', 'G') )
{
frame_s = Size(720, 576);
fps = 25;
}
VideoWriter writer(filename, tag, fps, frame_s);
if (writer.isOpened() == false)
{
ts->printf(ts->LOG, "\n\nFile name: %s\n", filename.c_str());
ts->printf(ts->LOG, "Codec id: %d Codec tag: %c%c%c%c\n", j,
tag & 255, (tag >> 8) & 255, (tag >> 16) & 255, (tag >> 24) & 255);
ts->printf(ts->LOG, "Error: cannot create video file.");
ts->set_failed_test_info(ts->FAIL_INVALID_OUTPUT);
}
else
{
Mat img(frame_s, CV_8UC3, Scalar::all(0));
const int coeff = cvRound(min(frame_s.width, frame_s.height)/(fps0 * time_sec));
for (int i = 0 ; i < static_cast<int>(fps * time_sec); i++ )
{
//circle(img, Point2i(img_c / 2, img_r / 2), min(img_r, img_c) / 2 * (i + 1), Scalar(255, 0, 0, 0), 2);
rectangle(img, Point2i(coeff * i, coeff * i), Point2i(coeff * (i + 1), coeff * (i + 1)),
Scalar::all(255 * (1.0 - static_cast<double>(i) / (fps * time_sec * 2) )), -1);
writer << img;
}
if (!created) created = true;
else remove(filename.c_str());
}
}
catch(...)
{
ts->set_failed_test_info(ts->FAIL_INVALID_OUTPUT);
}
ts->set_failed_test_info(cvtest::TS::OK);
}
}
};
TEST(Highgui_Video, ffmpeg_writebig) { CV_FFmpegWriteBigVideoTest test; test.safe_run(); }
class CV_FFmpegReadImageTest : public cvtest::BaseTest
{
public:
void run(int)
{
try
{
string filename = ts->get_data_path() + "readwrite/ordinary.bmp";
VideoCapture cap(filename);
Mat img0 = imread(filename, 1);
Mat img, img_next;
cap >> img;
cap >> img_next;
CV_Assert( !img0.empty() && !img.empty() && img_next.empty() );
double diff = cvtest::norm(img0, img, CV_C);
CV_Assert( diff == 0 );
}
catch(...)
{
ts->set_failed_test_info(ts->FAIL_INVALID_OUTPUT);
}
ts->set_failed_test_info(cvtest::TS::OK);
}
};
TEST(Highgui_Video, ffmpeg_image) { CV_FFmpegReadImageTest test; test.safe_run(); }
#endif
#if defined(HAVE_FFMPEG)
//////////////////////////////// Parallel VideoWriters and VideoCaptures ////////////////////////////////////
class CreateVideoWriterInvoker :
public ParallelLoopBody
{
public:
const static Size FrameSize;
static std::string TmpDirectory;
CreateVideoWriterInvoker(std::vector<VideoWriter*>& _writers, std::vector<std::string>& _files) :
ParallelLoopBody(), writers(&_writers), files(&_files)
{
}
virtual void operator() (const Range& range) const
{
for (int i = range.start; i != range.end; ++i)
{
std::ostringstream stream;
stream << i << ".avi";
std::string fileName = tempfile(stream.str().c_str());
files->operator[](i) = fileName;
writers->operator[](i) = new VideoWriter(fileName, VideoWriter::fourcc('X','V','I','D'), 25.0f, FrameSize);
CV_Assert(writers->operator[](i)->isOpened());
}
}
private:
std::vector<VideoWriter*>* writers;
std::vector<std::string>* files;
};
std::string CreateVideoWriterInvoker::TmpDirectory;
const Size CreateVideoWriterInvoker::FrameSize(1020, 900);
class WriteVideo_Invoker :
public ParallelLoopBody
{
public:
enum { FrameCount = 300 };
static const Scalar ObjectColor;
static const Point Center;
WriteVideo_Invoker(const std::vector<VideoWriter*>& _writers) :
ParallelLoopBody(), writers(&_writers)
{
}
static void GenerateFrame(Mat& frame, unsigned int i)
{
frame = Scalar::all(i % 255);
std::string text = to_string(i);
putText(frame, text, Point(50, Center.y), FONT_HERSHEY_SIMPLEX, 5.0, ObjectColor, 5, CV_AA);
circle(frame, Center, i + 2, ObjectColor, 2, CV_AA);
}
virtual void operator() (const Range& range) const
{
for (int j = range.start; j < range.end; ++j)
{
VideoWriter* writer = writers->operator[](j);
CV_Assert(writer != NULL);
CV_Assert(writer->isOpened());
Mat frame(CreateVideoWriterInvoker::FrameSize, CV_8UC3);
for (unsigned int i = 0; i < FrameCount; ++i)
{
GenerateFrame(frame, i);
writer->operator<< (frame);
}
}
}
protected:
static std::string to_string(unsigned int i)
{
std::stringstream stream(std::ios::out);
stream << "frame #" << i;
return stream.str();
}
private:
const std::vector<VideoWriter*>* writers;
};
const Scalar WriteVideo_Invoker::ObjectColor(Scalar::all(0));
const Point WriteVideo_Invoker::Center(CreateVideoWriterInvoker::FrameSize.height / 2,
CreateVideoWriterInvoker::FrameSize.width / 2);
class CreateVideoCaptureInvoker :
public ParallelLoopBody
{
public:
CreateVideoCaptureInvoker(std::vector<VideoCapture*>& _readers, const std::vector<std::string>& _files) :
ParallelLoopBody(), readers(&_readers), files(&_files)
{
}
virtual void operator() (const Range& range) const
{
for (int i = range.start; i != range.end; ++i)
{
readers->operator[](i) = new VideoCapture(files->operator[](i));
CV_Assert(readers->operator[](i)->isOpened());
}
}
private:
std::vector<VideoCapture*>* readers;
const std::vector<std::string>* files;
};
class ReadImageAndTest :
public ParallelLoopBody
{
public:
ReadImageAndTest(const std::vector<VideoCapture*>& _readers, cvtest::TS* _ts) :
ParallelLoopBody(), readers(&_readers), ts(_ts)
{
}
virtual void operator() (const Range& range) const
{
for (int j = range.start; j < range.end; ++j)
{
VideoCapture* capture = readers->operator[](j);
CV_Assert(capture != NULL);
CV_Assert(capture->isOpened());
const static double eps = 23.0;
unsigned int frameCount = static_cast<unsigned int>(capture->get(CAP_PROP_FRAME_COUNT));
CV_Assert(frameCount == WriteVideo_Invoker::FrameCount);
Mat reference(CreateVideoWriterInvoker::FrameSize, CV_8UC3);
for (unsigned int i = 0; i < frameCount && next; ++i)
{
Mat actual;
(*capture) >> actual;
WriteVideo_Invoker::GenerateFrame(reference, i);
EXPECT_EQ(reference.cols, actual.cols);
EXPECT_EQ(reference.rows, actual.rows);
EXPECT_EQ(reference.depth(), actual.depth());
EXPECT_EQ(reference.channels(), actual.channels());
double psnr = cvtest::PSNR(actual, reference);
if (psnr < eps)
{
#define SUM cvtest::TS::SUMMARY
ts->printf(SUM, "\nPSNR: %lf\n", psnr);
ts->printf(SUM, "Video #: %d\n", range.start);
ts->printf(SUM, "Frame #: %d\n", i);
#undef SUM
ts->set_failed_test_info(cvtest::TS::FAIL_BAD_ACCURACY);
ts->set_gtest_status();
Mat diff;
absdiff(actual, reference, diff);
EXPECT_EQ(countNonZero(diff.reshape(1) > 1), 0);
next = false;
}
}
}
}
static bool next;
private:
const std::vector<VideoCapture*>* readers;
cvtest::TS* ts;
};
bool ReadImageAndTest::next;
TEST(Highgui_Video_parallel_writers_and_readers, accuracy)
{
const unsigned int threadsCount = 4;
cvtest::TS* ts = cvtest::TS::ptr();
// creating VideoWriters
std::vector<VideoWriter*> writers(threadsCount);
Range range(0, threadsCount);
std::vector<std::string> files(threadsCount);
CreateVideoWriterInvoker invoker1(writers, files);
parallel_for_(range, invoker1);
// write a video
parallel_for_(range, WriteVideo_Invoker(writers));
// deleting the writers
for (std::vector<VideoWriter*>::iterator i = writers.begin(), end = writers.end(); i != end; ++i)
delete *i;
writers.clear();
std::vector<VideoCapture*> readers(threadsCount);
CreateVideoCaptureInvoker invoker2(readers, files);
parallel_for_(range, invoker2);
ReadImageAndTest::next = true;
parallel_for_(range, ReadImageAndTest(readers, ts));
// deleting tmp video files
for (std::vector<std::string>::const_iterator i = files.begin(), end = files.end(); i != end; ++i)
{
int code = remove(i->c_str());
if (code == 1)
std::cerr << "Couldn't delete " << *i << std::endl;
}
}
#endif

View File

@@ -1,115 +0,0 @@
/*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"
#include "opencv2/highgui.hpp"
#undef DEFINE_GUID
#define DEFINE_GUID(n, fourcc, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10) fourcc,
unsigned long allfourcc[] = {
DEFINE_GUID(MEDIASUBTYPE_GREY, 0x59455247, 0x0000, 0x0010, 0x80, 0x00,
0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71)
DEFINE_GUID(MEDIASUBTYPE_Y8, 0x20203859, 0x0000, 0x0010, 0x80, 0x00,
0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71)
DEFINE_GUID(MEDIASUBTYPE_Y800, 0x30303859, 0x0000, 0x0010, 0x80, 0x00,
0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71)
DEFINE_GUID(CLSID_CaptureGraphBuilder2,0xbf87b6e1,0x8c27,0x11d0,0xb3,0xf0,0x00,0xaa,0x00,0x37,0x61,0xc5)
DEFINE_GUID(CLSID_FilterGraph,0xe436ebb3,0x524f,0x11ce,0x9f,0x53,0x00,0x20,0xaf,0x0b,0xa7,0x70)
DEFINE_GUID(CLSID_NullRenderer,0xc1f400a4,0x3f08,0x11d3,0x9f,0x0b,0x00,0x60,0x08,0x03,0x9e,0x37)
DEFINE_GUID(CLSID_SampleGrabber,0xc1f400a0,0x3f08,0x11d3,0x9f,0x0b,0x00,0x60,0x08,0x03,0x9e,0x37)
DEFINE_GUID(CLSID_SystemDeviceEnum,0x62be5d10,0x60eb,0x11d0,0xbd,0x3b,0x00,0xa0,0xc9,0x11,0xce,0x86)
DEFINE_GUID(CLSID_VideoInputDeviceCategory,0x860bb310,0x5d01,0x11d0,0xbd,0x3b,0x00,0xa0,0xc9,0x11,0xce,0x86)
DEFINE_GUID(FORMAT_VideoInfo,0x05589f80,0xc356,0x11ce,0xbf,0x01,0x00,0xaa,0x00,0x55,0x59,0x5a)
DEFINE_GUID(IID_IAMAnalogVideoDecoder,0xc6e13350,0x30ac,0x11d0,0xa1,0x8c,0x00,0xa0,0xc9,0x11,0x89,0x56)
DEFINE_GUID(IID_IAMCameraControl,0xc6e13370,0x30ac,0x11d0,0xa1,0x8c,0x00,0xa0,0xc9,0x11,0x89,0x56)
DEFINE_GUID(IID_IAMCrossbar,0xc6e13380,0x30ac,0x11d0,0xa1,0x8c,0x00,0xa0,0xc9,0x11,0x89,0x56)
DEFINE_GUID(IID_IAMStreamConfig,0xc6e13340,0x30ac,0x11d0,0xa1,0x8c,0x00,0xa0,0xc9,0x11,0x89,0x56)
DEFINE_GUID(IID_IAMVideoProcAmp,0xc6e13360,0x30ac,0x11d0,0xa1,0x8c,0x00,0xa0,0xc9,0x11,0x89,0x56)
DEFINE_GUID(IID_IBaseFilter,0x56a86895,0x0ad4,0x11ce,0xb0,0x3a,0x00,0x20,0xaf,0x0b,0xa7,0x70)
DEFINE_GUID(IID_ICaptureGraphBuilder2,0x93e5a4e0,0x2d50,0x11d2,0xab,0xfa,0x00,0xa0,0xc9,0xc6,0xe3,0x8d)
DEFINE_GUID(IID_ICreateDevEnum,0x29840822,0x5b84,0x11d0,0xbd,0x3b,0x00,0xa0,0xc9,0x11,0xce,0x86)
DEFINE_GUID(IID_IGraphBuilder,0x56a868a9,0x0ad4,0x11ce,0xb0,0x3a,0x00,0x20,0xaf,0x0b,0xa7,0x70)
DEFINE_GUID(IID_IMPEG2PIDMap,0xafb6c2a1,0x2c41,0x11d3,0x8a,0x60,0x00,0x00,0xf8,0x1e,0x0e,0x4a)
DEFINE_GUID(IID_IMediaControl,0x56a868b1,0x0ad4,0x11ce,0xb0,0x3a,0x00,0x20,0xaf,0x0b,0xa7,0x70)
DEFINE_GUID(IID_IMediaFilter,0x56a86899,0x0ad4,0x11ce,0xb0,0x3a,0x00,0x20,0xaf,0x0b,0xa7,0x70)
DEFINE_GUID(IID_ISampleGrabber,0x6b652fff,0x11fe,0x4fce,0x92,0xad,0x02,0x66,0xb5,0xd7,0xc7,0x8f)
DEFINE_GUID(LOOK_UPSTREAM_ONLY,0xac798be0,0x98e3,0x11d1,0xb3,0xf1,0x00,0xaa,0x00,0x37,0x61,0xc5)
DEFINE_GUID(MEDIASUBTYPE_AYUV,0x56555941,0x0000,0x0010,0x80,0x00,0x00,0xaa,0x00,0x38,0x9b,0x71)
DEFINE_GUID(MEDIASUBTYPE_IYUV,0x56555949,0x0000,0x0010,0x80,0x00,0x00,0xaa,0x00,0x38,0x9b,0x71)
DEFINE_GUID(MEDIASUBTYPE_RGB24,0xe436eb7d,0x524f,0x11ce,0x9f,0x53,0x00,0x20,0xaf,0x0b,0xa7,0x70)
DEFINE_GUID(MEDIASUBTYPE_RGB32,0xe436eb7e,0x524f,0x11ce,0x9f,0x53,0x00,0x20,0xaf,0x0b,0xa7,0x70)
DEFINE_GUID(MEDIASUBTYPE_RGB555,0xe436eb7c,0x524f,0x11ce,0x9f,0x53,0x00,0x20,0xaf,0x0b,0xa7,0x70)
DEFINE_GUID(MEDIASUBTYPE_RGB565,0xe436eb7b,0x524f,0x11ce,0x9f,0x53,0x00,0x20,0xaf,0x0b,0xa7,0x70)
DEFINE_GUID(MEDIASUBTYPE_I420,0x49343230,0x0000,0x0010,0x80,0x00,0x00,0xaa,0x00,0x38,0x9b,0x71)
DEFINE_GUID(MEDIASUBTYPE_UYVY,0x59565955,0x0000,0x0010,0x80,0x00,0x00,0xaa,0x00,0x38,0x9b,0x71)
DEFINE_GUID(MEDIASUBTYPE_Y211,0x31313259,0x0000,0x0010,0x80,0x00,0x00,0xaa,0x00,0x38,0x9b,0x71)
DEFINE_GUID(MEDIASUBTYPE_Y411,0x31313459,0x0000,0x0010,0x80,0x00,0x00,0xaa,0x00,0x38,0x9b,0x71)
DEFINE_GUID(MEDIASUBTYPE_Y41P,0x50313459,0x0000,0x0010,0x80,0x00,0x00,0xaa,0x00,0x38,0x9b,0x71)
DEFINE_GUID(MEDIASUBTYPE_YUY2,0x32595559,0x0000,0x0010,0x80,0x00,0x00,0xaa,0x00,0x38,0x9b,0x71)
DEFINE_GUID(MEDIASUBTYPE_YUYV,0x56595559,0x0000,0x0010,0x80,0x00,0x00,0xaa,0x00,0x38,0x9b,0x71)
DEFINE_GUID(MEDIASUBTYPE_YV12,0x32315659,0x0000,0x0010,0x80,0x00,0x00,0xaa,0x00,0x38,0x9b,0x71)
DEFINE_GUID(MEDIASUBTYPE_YVU9,0x39555659,0x0000,0x0010,0x80,0x00,0x00,0xaa,0x00,0x38,0x9b,0x71)
DEFINE_GUID(MEDIASUBTYPE_YVYU,0x55595659,0x0000,0x0010,0x80,0x00,0x00,0xaa,0x00,0x38,0x9b,0x71)
DEFINE_GUID(MEDIASUBTYPE_MJPG,0x47504A4D, 0x0000, 0x0010, 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71) // MGB
DEFINE_GUID(MEDIATYPE_Interleaved,0x73766169,0x0000,0x0010,0x80,0x00,0x00,0xaa,0x00,0x38,0x9b,0x71)
DEFINE_GUID(MEDIATYPE_Video,0x73646976,0x0000,0x0010,0x80,0x00,0x00,0xaa,0x00,0x38,0x9b,0x71)
DEFINE_GUID(PIN_CATEGORY_CAPTURE,0xfb6c4281,0x0353,0x11d1,0x90,0x5f,0x00,0x00,0xc0,0xcc,0x16,0xba)
DEFINE_GUID(PIN_CATEGORY_PREVIEW,0xfb6c4282,0x0353,0x11d1,0x90,0x5f,0x00,0x00,0xc0,0xcc,0x16,0xba)
0};
TEST(Highgui_dshow, fourcc_conversion)
{
for(int i = 0; allfourcc[i]; ++i)
{
unsigned long fourcc = allfourcc[i];
double paramValue = fourcc;
int fourccFromParam = (int)(unsigned long)(paramValue);
EXPECT_EQ(fourcc, (unsigned long)(unsigned)fourccFromParam);
}
}

View File

@@ -1,114 +0,0 @@
/*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"
#include "opencv2/highgui/highgui_c.h"
#include <stdio.h>
using namespace cv;
using namespace std;
class CV_FramecountTest: public cvtest::BaseTest
{
public:
void run(int);
};
void CV_FramecountTest::run(int)
{
const int time_sec = 5, fps = 25;
const string ext[] = {"avi", "mov", "mp4"};
const size_t n = sizeof(ext)/sizeof(ext[0]);
const string src_dir = ts->get_data_path();
ts->printf(cvtest::TS::LOG, "\n\nSource files directory: %s\n", (src_dir+"video/").c_str());
Ptr<CvCapture> cap;
for (size_t i = 0; i < n; ++i)
{
string file_path = src_dir+"video/big_buck_bunny."+ext[i];
cap.reset(cvCreateFileCapture(file_path.c_str()));
if (!cap)
{
ts->printf(cvtest::TS::LOG, "\nFile information (video %d): \n\nName: big_buck_bunny.%s\nFAILED\n\n", i+1, ext[i].c_str());
ts->printf(cvtest::TS::LOG, "Error: cannot read source video file.\n");
ts->set_failed_test_info(cvtest::TS::FAIL_INVALID_TEST_DATA);
return;
}
//cvSetCaptureProperty(cap, CV_CAP_PROP_POS_FRAMES, 0);
IplImage* frame; int FrameCount = 0;
for(;;)
{
frame = cvQueryFrame(cap);
if( !frame )
break;
FrameCount++;
}
int framecount = (int)cvGetCaptureProperty(cap, CAP_PROP_FRAME_COUNT);
ts->printf(cvtest::TS::LOG, "\nFile information (video %d): \n"\
"\nName: big_buck_bunny.%s\nActual frame count: %d\n"\
"Frame count computed in the cycle of queries of frames: %d\n"\
"Frame count returned by cvGetCaptureProperty function: %d\n",
i+1, ext[i].c_str(), time_sec*fps, FrameCount, framecount);
if( (FrameCount != cvRound(time_sec*fps) ||
FrameCount != framecount) && ext[i] != "mpg" )
{
ts->printf(cvtest::TS::LOG, "FAILED\n");
ts->printf(cvtest::TS::LOG, "\nError: actual frame count and returned frame count are not matched.\n");
ts->set_failed_test_info(cvtest::TS::FAIL_INVALID_OUTPUT);
return;
}
}
}
#if BUILD_WITH_VIDEO_INPUT_SUPPORT && defined HAVE_FFMPEG
TEST(Highgui_Video, framecount) {CV_FramecountTest test; test.safe_run();}
#endif

View File

@@ -1,223 +0,0 @@
/*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"
#include "opencv2/highgui/highgui_c.h"
#include <stdio.h>
using namespace cv;
using namespace std;
class CV_VideoPositioningTest: public cvtest::BaseTest
{
public:
enum {PROGRESSIVE, RANDOM};
CV_VideoPositioningTest();
~CV_VideoPositioningTest();
virtual void run(int) = 0;
protected:
vector <int> idx;
void run_test(int method);
private:
void generate_idx_seq(CvCapture *cap, int method);
};
class CV_VideoProgressivePositioningTest: public CV_VideoPositioningTest
{
public:
CV_VideoProgressivePositioningTest() : CV_VideoPositioningTest() { }
~CV_VideoProgressivePositioningTest();
void run(int);
};
class CV_VideoRandomPositioningTest: public CV_VideoPositioningTest
{
public:
CV_VideoRandomPositioningTest(): CV_VideoPositioningTest() { }
~CV_VideoRandomPositioningTest();
void run(int);
};
CV_VideoPositioningTest::CV_VideoPositioningTest() {}
CV_VideoPositioningTest::~CV_VideoPositioningTest() {}
CV_VideoProgressivePositioningTest::~CV_VideoProgressivePositioningTest() {}
CV_VideoRandomPositioningTest::~CV_VideoRandomPositioningTest() {}
void CV_VideoPositioningTest::generate_idx_seq(CvCapture* cap, int method)
{
idx.clear();
int N = (int)cvGetCaptureProperty(cap, CAP_PROP_FRAME_COUNT);
switch(method)
{
case PROGRESSIVE:
{
int pos = 1, step = 20;
do
{
idx.push_back(pos);
pos += step;
}
while (pos <= N);
break;
}
case RANDOM:
{
RNG rng(N);
idx.clear();
for( int i = 0; i < N-1; i++ )
idx.push_back(rng.uniform(0, N));
idx.push_back(N-1);
std::swap(idx.at(rng.uniform(0, N-1)), idx.at(N-1));
break;
}
default:break;
}
}
void CV_VideoPositioningTest::run_test(int method)
{
const string& src_dir = ts->get_data_path();
ts->printf(cvtest::TS::LOG, "\n\nSource files directory: %s\n", (src_dir+"video/").c_str());
const string ext[] = {"avi", "mov", "mp4", "mpg"};
int n = (int)(sizeof(ext)/sizeof(ext[0]));
int failed_videos = 0;
for (int i = 0; i < n; ++i)
{
// skip random positioning test in plain mpegs
if( method == RANDOM && ext[i] == "mpg" )
continue;
string file_path = src_dir + "video/big_buck_bunny." + ext[i];
ts->printf(cvtest::TS::LOG, "\nReading video file in %s...\n", file_path.c_str());
CvCapture* cap = cvCreateFileCapture(file_path.c_str());
if (!cap)
{
ts->printf(cvtest::TS::LOG, "\nFile information (video %d): \n\nName: big_buck_bunny.%s\nFAILED\n\n", i+1, ext[i].c_str());
ts->printf(cvtest::TS::LOG, "Error: cannot read source video file.\n");
ts->set_failed_test_info(cvtest::TS::FAIL_INVALID_TEST_DATA);
failed_videos++; continue;
}
cvSetCaptureProperty(cap, CAP_PROP_POS_FRAMES, 0);
generate_idx_seq(cap, method);
int N = (int)idx.size(), failed_frames = 0, failed_positions = 0, failed_iterations = 0;
for (int j = 0; j < N; ++j)
{
bool flag = false;
cvSetCaptureProperty(cap, CAP_PROP_POS_FRAMES, idx.at(j));
/* IplImage* frame = cvRetrieveFrame(cap);
if (!frame)
{
if (!failed_frames)
{
ts->printf(cvtest::TS::LOG, "\nFile information (video %d): \n\nName: big_buck_bunny.%s\n", i+1, ext[i].c_str());
}
failed_frames++;
ts->printf(cvtest::TS::LOG, "\nIteration: %d\n\nError: cannot read a frame with index %d.\n", j, idx.at(j));
ts->set_failed_test_info(cvtest::TS::FAIL_EXCEPTION);
flag = !flag;
} */
int val = (int)cvGetCaptureProperty(cap, CAP_PROP_POS_FRAMES);
if (idx.at(j) != val)
{
if (!(failed_frames||failed_positions))
{
ts->printf(cvtest::TS::LOG, "\nFile information (video %d): \n\nName: big_buck_bunny.%s\n", i+1, ext[i].c_str());
}
failed_positions++;
if (!failed_frames)
{
ts->printf(cvtest::TS::LOG, "\nIteration: %d\n", j);
}
ts->printf(cvtest::TS::LOG, "Required pos: %d\nReturned pos: %d\n", idx.at(j), val);
ts->printf(cvtest::TS::LOG, "Error: required and returned positions are not matched.\n");
ts->set_failed_test_info(cvtest::TS::FAIL_INVALID_OUTPUT);
flag = true;
}
if (flag)
{
failed_iterations++;
failed_videos++;
break;
}
}
cvReleaseCapture(&cap);
}
ts->printf(cvtest::TS::LOG, "\nSuccessfull experiments: %d (%d%%)\n", n-failed_videos, 100*(n-failed_videos)/n);
ts->printf(cvtest::TS::LOG, "Failed experiments: %d (%d%%)\n", failed_videos, 100*failed_videos/n);
}
void CV_VideoProgressivePositioningTest::run(int)
{
run_test(PROGRESSIVE);
}
void CV_VideoRandomPositioningTest::run(int)
{
run_test(RANDOM);
}
#if BUILD_WITH_VIDEO_INPUT_SUPPORT && defined HAVE_FFMPEG
TEST (Highgui_Video, seek_progressive) { CV_VideoProgressivePositioningTest test; test.safe_run(); }
TEST (Highgui_Video, seek_random) { CV_VideoRandomPositioningTest test; test.safe_run(); }
#endif

View File

@@ -11,81 +11,11 @@
#include <iostream>
#include "opencv2/ts.hpp"
#include "opencv2/imgproc.hpp"
#include "opencv2/imgcodecs.hpp"
#include "opencv2/highgui.hpp"
#include "opencv2/imgproc/imgproc_c.h"
//#include "opencv2/imgproc.hpp"
//#include "opencv2/imgcodecs.hpp"
//#include "opencv2/highgui.hpp"
//#include "opencv2/imgproc/imgproc_c.h"
#include "opencv2/core/private.hpp"
#if defined(HAVE_DSHOW) || \
defined(HAVE_TYZX) || \
defined(HAVE_VFW) || \
defined(HAVE_LIBV4L) || \
(defined(HAVE_CAMV4L) && defined(HAVE_CAMV4L2)) || \
defined(HAVE_GSTREAMER) || \
defined(HAVE_DC1394_2) || \
defined(HAVE_DC1394) || \
defined(HAVE_CMU1394) || \
defined(HAVE_MIL) || \
defined(HAVE_QUICKTIME) || \
defined(HAVE_QTKIT) || \
defined(HAVE_UNICAP) || \
defined(HAVE_PVAPI) || \
defined(HAVE_OPENNI) || \
defined(HAVE_XIMEA) || \
defined(HAVE_AVFOUNDATION) || \
defined(HAVE_GIGE_API) || \
defined(HAVE_INTELPERC) || \
(0)
//defined(HAVE_ANDROID_NATIVE_CAMERA) || - enable after #1193
# define BUILD_WITH_CAMERA_SUPPORT 1
#else
# define BUILD_WITH_CAMERA_SUPPORT 0
#endif
#if defined(HAVE_XINE) || \
defined(HAVE_GSTREAMER) || \
defined(HAVE_QUICKTIME) || \
defined(HAVE_QTKIT) || \
defined(HAVE_AVFOUNDATION) || \
/*defined(HAVE_OPENNI) || too specialized */ \
defined(HAVE_FFMPEG) || \
defined(HAVE_MSMF)
# define BUILD_WITH_VIDEO_INPUT_SUPPORT 1
#else
# define BUILD_WITH_VIDEO_INPUT_SUPPORT 0
#endif
#if /*defined(HAVE_XINE) || */\
defined(HAVE_GSTREAMER) || \
defined(HAVE_QUICKTIME) || \
defined(HAVE_QTKIT) || \
defined(HAVE_AVFOUNDATION) || \
defined(HAVE_FFMPEG) || \
defined(HAVE_MSMF)
# define BUILD_WITH_VIDEO_OUTPUT_SUPPORT 1
#else
# define BUILD_WITH_VIDEO_OUTPUT_SUPPORT 0
#endif
namespace cvtest
{
string fourccToString(int fourcc);
struct VideoFormat
{
VideoFormat() { fourcc = -1; }
VideoFormat(const string& _ext, int _fourcc) : ext(_ext), fourcc(_fourcc) {}
bool empty() const { return ext.empty(); }
string ext;
int fourcc;
};
extern const VideoFormat g_specific_fmt_list[];
}
//#include "opencv2/core/private.hpp"
#endif

View File

@@ -1,579 +0,0 @@
/*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"
#include "opencv2/highgui/highgui_c.h"
using namespace cv;
using namespace std;
namespace cvtest
{
string fourccToString(int fourcc)
{
return format("%c%c%c%c", fourcc & 255, (fourcc >> 8) & 255, (fourcc >> 16) & 255, (fourcc >> 24) & 255);
}
#ifdef HAVE_MSMF
const VideoFormat g_specific_fmt_list[] =
{
/*VideoFormat("wmv", CV_FOURCC_MACRO('d', 'v', '2', '5')),
VideoFormat("wmv", CV_FOURCC_MACRO('d', 'v', '5', '0')),
VideoFormat("wmv", CV_FOURCC_MACRO('d', 'v', 'c', ' ')),
VideoFormat("wmv", CV_FOURCC_MACRO('d', 'v', 'h', '1')),
VideoFormat("wmv", CV_FOURCC_MACRO('d', 'v', 'h', 'd')),
VideoFormat("wmv", CV_FOURCC_MACRO('d', 'v', 's', 'd')),
VideoFormat("wmv", CV_FOURCC_MACRO('d', 'v', 's', 'l')),
VideoFormat("wmv", CV_FOURCC_MACRO('H', '2', '6', '3')),
VideoFormat("wmv", CV_FOURCC_MACRO('M', '4', 'S', '2')),
VideoFormat("avi", CV_FOURCC_MACRO('M', 'J', 'P', 'G')),
VideoFormat("mp4", CV_FOURCC_MACRO('M', 'P', '4', 'S')),
VideoFormat("mp4", CV_FOURCC_MACRO('M', 'P', '4', 'V')),
VideoFormat("wmv", CV_FOURCC_MACRO('M', 'P', '4', '3')),
VideoFormat("wmv", CV_FOURCC_MACRO('M', 'P', 'G', '1')),
VideoFormat("wmv", CV_FOURCC_MACRO('M', 'S', 'S', '1')),
VideoFormat("wmv", CV_FOURCC_MACRO('M', 'S', 'S', '2')),*/
#if !defined(_M_ARM)
VideoFormat("wmv", CV_FOURCC_MACRO('W', 'M', 'V', '1')),
VideoFormat("wmv", CV_FOURCC_MACRO('W', 'M', 'V', '2')),
#endif
VideoFormat("wmv", CV_FOURCC_MACRO('W', 'M', 'V', '3')),
VideoFormat("avi", CV_FOURCC_MACRO('H', '2', '6', '4')),
//VideoFormat("wmv", CV_FOURCC_MACRO('W', 'V', 'C', '1')),
VideoFormat()
};
#else
const VideoFormat g_specific_fmt_list[] =
{
VideoFormat("avi", VideoWriter::fourcc('X', 'V', 'I', 'D')),
VideoFormat("avi", VideoWriter::fourcc('M', 'P', 'E', 'G')),
VideoFormat("avi", VideoWriter::fourcc('M', 'J', 'P', 'G')),
//VideoFormat("avi", VideoWriter::fourcc('I', 'Y', 'U', 'V')),
VideoFormat("mkv", VideoWriter::fourcc('X', 'V', 'I', 'D')),
VideoFormat("mkv", VideoWriter::fourcc('M', 'P', 'E', 'G')),
VideoFormat("mkv", VideoWriter::fourcc('M', 'J', 'P', 'G')),
VideoFormat("mov", VideoWriter::fourcc('m', 'p', '4', 'v')),
VideoFormat()
};
#endif
}
class CV_HighGuiTest : public cvtest::BaseTest
{
protected:
void ImageTest (const string& dir);
void VideoTest (const string& dir, const cvtest::VideoFormat& fmt);
void SpecificImageTest (const string& dir);
void SpecificVideoTest (const string& dir, const cvtest::VideoFormat& fmt);
CV_HighGuiTest() {}
~CV_HighGuiTest() {}
virtual void run(int) = 0;
};
class CV_ImageTest : public CV_HighGuiTest
{
public:
CV_ImageTest() {}
~CV_ImageTest() {}
void run(int);
};
class CV_SpecificImageTest : public CV_HighGuiTest
{
public:
CV_SpecificImageTest() {}
~CV_SpecificImageTest() {}
void run(int);
};
class CV_VideoTest : public CV_HighGuiTest
{
public:
CV_VideoTest() {}
~CV_VideoTest() {}
void run(int);
};
class CV_SpecificVideoTest : public CV_HighGuiTest
{
public:
CV_SpecificVideoTest() {}
~CV_SpecificVideoTest() {}
void run(int);
};
void CV_HighGuiTest::ImageTest(const string& dir)
{
string _name = dir + string("../cv/shared/baboon.png");
ts->printf(ts->LOG, "reading image : %s\n", _name.c_str());
Mat image = imread(_name);
image.convertTo(image, CV_8UC3);
if (image.empty())
{
ts->set_failed_test_info(ts->FAIL_MISSING_TEST_DATA);
return;
}
const string exts[] = {
#ifdef HAVE_PNG
"png",
#endif
#ifdef HAVE_TIFF
"tiff",
#endif
#ifdef HAVE_JPEG
"jpg",
#endif
#ifdef HAVE_JASPER
"jp2",
#endif
#if 0 /*defined HAVE_OPENEXR && !defined __APPLE__*/
"exr",
#endif
"bmp",
"ppm",
"ras"
};
const size_t ext_num = sizeof(exts)/sizeof(exts[0]);
for(size_t i = 0; i < ext_num; ++i)
{
string ext = exts[i];
string full_name = cv::tempfile(ext.c_str());
ts->printf(ts->LOG, " full_name : %s\n", full_name.c_str());
imwrite(full_name, image);
Mat loaded = imread(full_name);
if (loaded.empty())
{
ts->printf(ts->LOG, "Reading failed at fmt=%s\n", ext.c_str());
ts->set_failed_test_info(ts->FAIL_MISMATCH);
continue;
}
const double thresDbell = 20;
double psnr = cvtest::PSNR(loaded, image);
if (psnr < thresDbell)
{
ts->printf(ts->LOG, "Reading image from file: too big difference (=%g) with fmt=%s\n", psnr, ext.c_str());
ts->set_failed_test_info(ts->FAIL_BAD_ACCURACY);
continue;
}
vector<uchar> from_file;
FILE *f = fopen(full_name.c_str(), "rb");
fseek(f, 0, SEEK_END);
long len = ftell(f);
from_file.resize((size_t)len);
fseek(f, 0, SEEK_SET);
from_file.resize(fread(&from_file[0], 1, from_file.size(), f));
fclose(f);
vector<uchar> buf;
imencode("." + exts[i], image, buf);
if (buf != from_file)
{
ts->printf(ts->LOG, "Encoding failed with fmt=%s\n", ext.c_str());
ts->set_failed_test_info(ts->FAIL_MISMATCH);
continue;
}
Mat buf_loaded = imdecode(Mat(buf), 1);
if (buf_loaded.empty())
{
ts->printf(ts->LOG, "Decoding failed with fmt=%s\n", ext.c_str());
ts->set_failed_test_info(ts->FAIL_MISMATCH);
continue;
}
psnr = cvtest::PSNR(buf_loaded, image);
if (psnr < thresDbell)
{
ts->printf(ts->LOG, "Decoding image from memory: too small PSNR (=%gdb) with fmt=%s\n", psnr, ext.c_str());
ts->set_failed_test_info(ts->FAIL_MISMATCH);
continue;
}
}
ts->printf(ts->LOG, "end test function : ImagesTest \n");
ts->set_failed_test_info(ts->OK);
}
void CV_HighGuiTest::VideoTest(const string& dir, const cvtest::VideoFormat& fmt)
{
string src_file = dir + "../cv/shared/video_for_test.avi";
string tmp_name = cv::tempfile((cvtest::fourccToString(fmt.fourcc) + "." + fmt.ext).c_str());
ts->printf(ts->LOG, "reading video : %s and converting it to %s\n", src_file.c_str(), tmp_name.c_str());
CvCapture* cap = cvCaptureFromFile(src_file.c_str());
if (!cap)
{
ts->set_failed_test_info(ts->FAIL_MISMATCH);
return;
}
CvVideoWriter* writer = 0;
vector<Mat> frames;
for(;;)
{
IplImage* img = cvQueryFrame( cap );
if (!img)
break;
frames.push_back(cv::cvarrToMat(img, true));
if (writer == NULL)
{
writer = cvCreateVideoWriter(tmp_name.c_str(), fmt.fourcc, 24, cvGetSize(img));
if (writer == NULL)
{
ts->printf(ts->LOG, "can't create writer (with fourcc : %s)\n",
cvtest::fourccToString(fmt.fourcc).c_str());
cvReleaseCapture( &cap );
ts->set_failed_test_info(ts->FAIL_MISMATCH);
return;
}
}
cvWriteFrame(writer, img);
}
cvReleaseVideoWriter( &writer );
cvReleaseCapture( &cap );
CvCapture *saved = cvCaptureFromFile(tmp_name.c_str());
if (!saved)
{
ts->set_failed_test_info(ts->FAIL_MISMATCH);
return;
}
const double thresDbell = 20;
for(int i = 0;; i++)
{
IplImage* ipl1 = cvQueryFrame( saved );
if (!ipl1)
break;
Mat img = frames[i];
Mat img1 = cv::cvarrToMat(ipl1);
double psnr = cvtest::PSNR(img1, img);
if (psnr < thresDbell)
{
ts->printf(ts->LOG, "Too low frame %d psnr = %gdb\n", i, psnr);
ts->set_failed_test_info(ts->FAIL_MISMATCH);
//imwrite("original.png", img);
//imwrite("after_test.png", img1);
//Mat diff;
//absdiff(img, img1, diff);
//imwrite("diff.png", diff);
break;
}
}
cvReleaseCapture( &saved );
ts->printf(ts->LOG, "end test function : ImagesVideo \n");
}
void CV_HighGuiTest::SpecificImageTest(const string& dir)
{
const size_t IMAGE_COUNT = 10;
for (size_t i = 0; i < IMAGE_COUNT; ++i)
{
stringstream s; s << i;
string file_path = dir+"../python/images/QCIF_0"+s.str()+".bmp";
Mat image = imread(file_path);
if (image.empty())
{
ts->set_failed_test_info(ts->FAIL_MISSING_TEST_DATA);
return;
}
resize(image, image, Size(968, 757), 0.0, 0.0, INTER_CUBIC);
stringstream s_digit; s_digit << i;
string full_name = cv::tempfile((s_digit.str() + ".bmp").c_str());
ts->printf(ts->LOG, " full_name : %s\n", full_name.c_str());
imwrite(full_name, image);
Mat loaded = imread(full_name);
if (loaded.empty())
{
ts->printf(ts->LOG, "Reading failed at fmt=bmp\n");
ts->set_failed_test_info(ts->FAIL_MISMATCH);
continue;
}
const double thresDbell = 20;
double psnr = cvtest::PSNR(loaded, image);
if (psnr < thresDbell)
{
ts->printf(ts->LOG, "Reading image from file: too big difference (=%g) with fmt=bmp\n", psnr);
ts->set_failed_test_info(ts->FAIL_BAD_ACCURACY);
continue;
}
vector<uchar> from_file;
FILE *f = fopen(full_name.c_str(), "rb");
fseek(f, 0, SEEK_END);
long len = ftell(f);
from_file.resize((size_t)len);
fseek(f, 0, SEEK_SET);
from_file.resize(fread(&from_file[0], 1, from_file.size(), f));
fclose(f);
vector<uchar> buf;
imencode(".bmp", image, buf);
if (buf != from_file)
{
ts->printf(ts->LOG, "Encoding failed with fmt=bmp\n");
ts->set_failed_test_info(ts->FAIL_MISMATCH);
continue;
}
Mat buf_loaded = imdecode(Mat(buf), 1);
if (buf_loaded.empty())
{
ts->printf(ts->LOG, "Decoding failed with fmt=bmp\n");
ts->set_failed_test_info(ts->FAIL_MISMATCH);
continue;
}
psnr = cvtest::PSNR(buf_loaded, image);
if (psnr < thresDbell)
{
ts->printf(ts->LOG, "Decoding image from memory: too small PSNR (=%gdb) with fmt=bmp\n", psnr);
ts->set_failed_test_info(ts->FAIL_MISMATCH);
continue;
}
}
ts->printf(ts->LOG, "end test function : SpecificImageTest \n");
ts->set_failed_test_info(ts->OK);
}
void CV_HighGuiTest::SpecificVideoTest(const string& dir, const cvtest::VideoFormat& fmt)
{
string ext = fmt.ext;
int fourcc = fmt.fourcc;
string fourcc_str = cvtest::fourccToString(fourcc);
const string video_file = cv::tempfile((fourcc_str + "." + ext).c_str());
Size frame_size(968 & -2, 757 & -2);
VideoWriter writer(video_file, fourcc, 25, frame_size, true);
if (!writer.isOpened())
{
// call it repeatedly for easier debugging
VideoWriter writer2(video_file, fourcc, 25, frame_size, true);
ts->printf(ts->LOG, "Creating a video in %s...\n", video_file.c_str());
ts->printf(ts->LOG, "Cannot create VideoWriter object with codec %s.\n", fourcc_str.c_str());
ts->set_failed_test_info(ts->FAIL_MISMATCH);
return;
}
const size_t IMAGE_COUNT = 30;
vector<Mat> images;
for( size_t i = 0; i < IMAGE_COUNT; ++i )
{
string file_path = format("%s../python/images/QCIF_%02d.bmp", dir.c_str(), i);
Mat img = imread(file_path, IMREAD_COLOR);
if (img.empty())
{
ts->printf(ts->LOG, "Creating a video in %s...\n", video_file.c_str());
ts->printf(ts->LOG, "Error: cannot read frame from %s.\n", file_path.c_str());
ts->printf(ts->LOG, "Continue creating the video file...\n");
ts->set_failed_test_info(ts->FAIL_INVALID_TEST_DATA);
break;
}
for (int k = 0; k < img.rows; ++k)
for (int l = 0; l < img.cols; ++l)
if (img.at<Vec3b>(k, l) == Vec3b::all(0))
img.at<Vec3b>(k, l) = Vec3b(0, 255, 0);
else img.at<Vec3b>(k, l) = Vec3b(0, 0, 255);
resize(img, img, frame_size, 0.0, 0.0, INTER_CUBIC);
images.push_back(img);
writer << img;
}
writer.release();
VideoCapture cap(video_file);
size_t FRAME_COUNT = (size_t)cap.get(CAP_PROP_FRAME_COUNT);
size_t allowed_extra_frames = 0;
// 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.
// See also the same hack in CV_PositioningTest::run.
if (fourcc == VideoWriter::fourcc('M', 'P', 'E', 'G') && ext == "mkv")
allowed_extra_frames = 1;
if (FRAME_COUNT < IMAGE_COUNT || FRAME_COUNT > IMAGE_COUNT + allowed_extra_frames)
{
ts->printf(ts->LOG, "\nFrame count checking for video_%s.%s...\n", fourcc_str.c_str(), ext.c_str());
ts->printf(ts->LOG, "Video codec: %s\n", fourcc_str.c_str());
if (allowed_extra_frames != 0)
ts->printf(ts->LOG, "Required frame count: %d-%d; Returned frame count: %d\n",
IMAGE_COUNT, IMAGE_COUNT + allowed_extra_frames, FRAME_COUNT);
else
ts->printf(ts->LOG, "Required frame count: %d; Returned frame count: %d\n", IMAGE_COUNT, FRAME_COUNT);
ts->printf(ts->LOG, "Error: Incorrect frame count in the video.\n");
ts->printf(ts->LOG, "Continue checking...\n");
ts->set_failed_test_info(ts->FAIL_BAD_ACCURACY);
return;
}
for (int i = 0; (size_t)i < IMAGE_COUNT; i++)
{
Mat frame; cap >> frame;
if (frame.empty())
{
ts->printf(ts->LOG, "\nVideo file directory: %s\n", ".");
ts->printf(ts->LOG, "File name: video_%s.%s\n", fourcc_str.c_str(), ext.c_str());
ts->printf(ts->LOG, "Video codec: %s\n", fourcc_str.c_str());
ts->printf(ts->LOG, "Error: cannot read the next frame with index %d.\n", i+1);
ts->set_failed_test_info(ts->FAIL_MISSING_TEST_DATA);
break;
}
Mat img = images[i];
const double thresDbell = 40;
double psnr = cvtest::PSNR(img, frame);
if (psnr > thresDbell)
{
ts->printf(ts->LOG, "\nReading frame from the file video_%s.%s...\n", fourcc_str.c_str(), ext.c_str());
ts->printf(ts->LOG, "Frame index: %d\n", i+1);
ts->printf(ts->LOG, "Difference between saved and original images: %g\n", psnr);
ts->printf(ts->LOG, "Maximum allowed difference: %g\n", thresDbell);
ts->printf(ts->LOG, "Error: too big difference between saved and original images.\n");
break;
}
}
}
void CV_ImageTest::run(int)
{
ImageTest(ts->get_data_path());
}
void CV_SpecificImageTest::run(int)
{
SpecificImageTest(ts->get_data_path());
}
void CV_VideoTest::run(int)
{
for (int i = 0; ; ++i)
{
const cvtest::VideoFormat& fmt = cvtest::g_specific_fmt_list[i];
if( fmt.empty() )
break;
VideoTest(ts->get_data_path(), fmt);
}
}
void CV_SpecificVideoTest::run(int)
{
for (int i = 0; ; ++i)
{
const cvtest::VideoFormat& fmt = cvtest::g_specific_fmt_list[i];
if( fmt.empty() )
break;
SpecificVideoTest(ts->get_data_path(), fmt);
}
}
#ifdef HAVE_JPEG
TEST(Highgui_Image, regression) { CV_ImageTest test; test.safe_run(); }
#endif
#if BUILD_WITH_VIDEO_INPUT_SUPPORT && BUILD_WITH_VIDEO_OUTPUT_SUPPORT && !defined(__APPLE__)
TEST(Highgui_Video, regression) { CV_VideoTest test; test.safe_run(); }
TEST(Highgui_Video, write_read) { CV_SpecificVideoTest test; test.safe_run(); }
#endif
TEST(Highgui_Image, write_read) { CV_SpecificImageTest test; test.safe_run(); }

View File

@@ -1,183 +0,0 @@
/*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"
#include "opencv2/highgui.hpp"
using namespace cv;
using namespace std;
class CV_PositioningTest : public cvtest::BaseTest
{
public:
CV_PositioningTest()
{
framesize = Size(640, 480);
}
Mat drawFrame(int i)
{
Mat mat = Mat::zeros(framesize, CV_8UC3);
mat = Scalar(fabs(cos(i*0.08)*255), fabs(sin(i*0.05)*255), i);
putText(mat, format("%03d", i), Point(10, 350), 0, 10, Scalar(128, 255, 255), 15);
return mat;
}
string getFilename(const cvtest::VideoFormat& fmt)
{
return cv::tempfile((cvtest::fourccToString(fmt.fourcc) + "." + fmt.ext).c_str());
}
bool CreateTestVideo(const cvtest::VideoFormat& fmt, int framecount, string filename)
{
VideoWriter writer(filename, fmt.fourcc, 25, framesize, true);
if( !writer.isOpened() )
return false;
for (int i = 0; i < framecount; ++i)
{
Mat img = drawFrame(i);
writer << img;
}
return true;
}
void run(int)
{
int n_frames = 100;
for( int testcase = 0; ; testcase++ )
{
const cvtest::VideoFormat& fmt = cvtest::g_specific_fmt_list[testcase];
if( fmt.empty() )
break;
string filename = getFilename(fmt);
ts->printf(ts->LOG, "\nFile: %s\n", filename.c_str());
if( !CreateTestVideo(fmt, n_frames, filename) )
{
ts->printf(ts->LOG, "\nError: cannot create video file");
ts->set_failed_test_info(ts->FAIL_INVALID_OUTPUT);
return;
}
VideoCapture cap(filename);
if (!cap.isOpened())
{
ts->printf(ts->LOG, "\nError: cannot read video file.");
ts->set_failed_test_info(ts->FAIL_INVALID_TEST_DATA);
return;
}
int N0 = (int)cap.get(CAP_PROP_FRAME_COUNT);
cap.set(CAP_PROP_POS_FRAMES, 0);
int N = (int)cap.get(CAP_PROP_FRAME_COUNT);
// See the same hack in CV_HighGuiTest::SpecificVideoTest for explanation.
int allowed_extra_frames = 0;
if (fmt.fourcc == VideoWriter::fourcc('M', 'P', 'E', 'G') && fmt.ext == "mkv")
allowed_extra_frames = 1;
if (N < n_frames || N > n_frames + allowed_extra_frames || N != N0)
{
ts->printf(ts->LOG, "\nError: returned frame count (N0=%d, N=%d) is different from the reference number %d\n", N0, N, n_frames);
ts->set_failed_test_info(ts->FAIL_INVALID_OUTPUT);
return;
}
for (int k = 0; k < n_frames; ++k)
{
int idx = theRNG().uniform(0, n_frames);
if( !cap.set(CAP_PROP_POS_FRAMES, idx) )
{
ts->printf(ts->LOG, "\nError: cannot seek to frame %d.\n", idx);
ts->set_failed_test_info(ts->FAIL_INVALID_OUTPUT);
return;
}
int idx1 = (int)cap.get(CAP_PROP_POS_FRAMES);
Mat img; cap >> img;
Mat img0 = drawFrame(idx);
if( idx != idx1 )
{
ts->printf(ts->LOG, "\nError: the current position (%d) after seek is different from specified (%d)\n",
idx1, idx);
ts->printf(ts->LOG, "Saving both frames ...\n");
ts->set_failed_test_info(ts->FAIL_INVALID_OUTPUT);
// imwrite("opencv_test_highgui_postest_actual.png", img);
// imwrite("opencv_test_highgui_postest_expected.png", img0);
return;
}
if (img.empty())
{
ts->printf(ts->LOG, "\nError: cannot read a frame at position %d.\n", idx);
ts->set_failed_test_info(ts->FAIL_INVALID_OUTPUT);
return;
}
double err = cvtest::PSNR(img, img0);
if( err < 20 )
{
ts->printf(ts->LOG, "The frame read after positioning to %d is incorrect (PSNR=%g)\n", idx, err);
ts->printf(ts->LOG, "Saving both frames ...\n");
ts->set_failed_test_info(ts->FAIL_INVALID_OUTPUT);
// imwrite("opencv_test_highgui_postest_actual.png", img);
// imwrite("opencv_test_highgui_postest_expected.png", img0);
return;
}
}
}
}
Size framesize;
};
#if BUILD_WITH_VIDEO_INPUT_SUPPORT && BUILD_WITH_VIDEO_OUTPUT_SUPPORT && defined HAVE_FFMPEG
TEST(Highgui_Video, seek_random_synthetic) { CV_PositioningTest test; test.safe_run(); }
#endif