Commit 19900d98 authored by Andrey Morozov's avatar Andrey Morozov

converted all highgui tests to the format of google test system

parent b884c3c4
...@@ -406,5 +406,4 @@ int CV_DrawingTest_C::checkLineIterator( Mat& _img ) ...@@ -406,5 +406,4 @@ int CV_DrawingTest_C::checkLineIterator( Mat& _img )
} }
TEST(Highgui_Drawing_CPP, regression) { CV_DrawingTest_CPP test; test.safe_run(); } TEST(Highgui_Drawing_CPP, regression) { CV_DrawingTest_CPP test; test.safe_run(); }
TEST(Highgui_Drawing_C, regression) { CV_DrawingTest_C test; test.safe_run(); } TEST(Highgui_Drawing_C, regression) { CV_DrawingTest_C test; test.safe_run(); }
\ No newline at end of file
...@@ -112,42 +112,48 @@ string ext_from_int(int ext) ...@@ -112,42 +112,48 @@ string ext_from_int(int ext)
return ""; return "";
} }
class CV_FFmpegWriteSequenceImageTest : public cvtest::BaseTest //class CV_FFmpegWriteSequenceImageTest : public cvtest::BaseTest
{ //{
public: // public:
void run(int) // void run(int)
{ // {
try // try
{ // {
const int img_r = 640; // const int img_r = 640;
const int img_c = 480; // const int img_c = 480;
Size frame_s = Size(img_c, img_r); // Size frame_s = Size(img_c, img_r);
//
for (size_t ext = 0; ext < 5; ++ext) // 0 - png, 1 - jpg, 2 - bmp, 3 - pgm, 4 - tiff // for (size_t ext = 0; ext < 5; ++ext) // 0 - png, 1 - jpg, 2 - bmp, 3 - pgm, 4 - tiff
for (size_t k = 1; k <= 3; ++k) // for (size_t k = 1; k <= 3; ++k)
for (size_t num_channels = 1; num_channels <= 4; ++num_channels) // for (size_t num_channels = 1; num_channels <= 4; ++num_channels)
for (size_t depth = CV_8U; depth <= CV_16U; ++depth) // for (size_t depth = CV_8U; depth <= CV_16U; ++depth)
{ // {
Mat img(img_r * k, img_c * k, CV_MAKETYPE(depth, num_channels), Scalar::all(0)); // ts->printf(ts->LOG, "image type depth:%d channels:%d ext: %s\n", depth, num_channels, ext_from_int(ext).c_str());
circle(img, Point2i((img_c * k) / 2, (img_r * k) / 2), cv::min((img_r * k), (img_c * k)) / 4 , Scalar::all(255)); // ts->printf(ts->LOG, "creating image\n");
imwrite(string(ts->get_data_path()) + "readwrite/test" + ext_from_int(ext), img); // Mat img(img_r * k, img_c * k, CV_MAKETYPE(depth, num_channels), Scalar::all(0));
Mat img_test = imread(string(ts->get_data_path()) + "readwrite/test" + ext_from_int(ext)); // ts->printf(ts->LOG, "drawing circle\n");
CV_Assert(img.size() == img_test.size()); // circle(img, Point2i((img_c * k) / 2, (img_r * k) / 2), cv::min((img_r * k), (img_c * k)) / 4 , Scalar::all(255));
CV_Assert(img.type() == img_test.type()); // ts->printf(ts->LOG, "writing image : %s\n", string(string(ts->get_data_path()) + "readwrite/test" + ext_from_int(ext)).c_str());
ts->printf(ts->LOG, "image type depth:%d channels:%d ext: %s\n", depth, num_channels, ext_from_int(ext).c_str()); // imwrite(string(ts->get_data_path()) + "readwrite/test" + ext_from_int(ext), img);
if (countNonZero(img != img_test) != 0) // ts->printf(ts->LOG, "reading test image : %s\n", string(string(ts->get_data_path()) + "readwrite/test" + ext_from_int(ext)).c_str());
ts->set_failed_test_info(cvtest::TS::FAIL_GENERIC); // Mat img_test = imread(string(ts->get_data_path()) + "readwrite/test" + ext_from_int(ext));
} //
} // CV_Assert(img.size() == img_test.size());
catch(...) // CV_Assert(img.type() == img_test.type());
{ //
ts->set_failed_test_info(cvtest::TS::FAIL_EXCEPTION); // ts->printf(ts->LOG, "checking test image\n");
} // if (countNonZero(img != img_test) != 0)
ts->set_failed_test_info(cvtest::TS::OK); // ts->set_failed_test_info(cvtest::TS::FAIL_GENERIC);
} // }
}; // }
// catch(...)
// {
// ts->set_failed_test_info(cvtest::TS::FAIL_EXCEPTION);
// }
// ts->set_failed_test_info(cvtest::TS::OK);
// }
//};
TEST(Highgui_FFmpeg_WriteSequenceImage, regression) { CV_FFmpegWriteSequenceImageTest test; test.safe_run(); } //TEST(Highgui_FFmpeg_WriteBigImage, regression) { CV_FFmpegWriteBigImageTest test; test.safe_run(); }
TEST(Highgui_FFmpeg_WriteBigImage, regression) { CV_FFmpegWriteBigImageTest test; test.safe_run(); } //TEST(Highgui_FFmpeg_WriteBigVideo, regression) { CV_FFmpegWriteBigVideoTest test; test.safe_run(); }
TEST(Highgui_FFmpeg_WriteBigVideo, regression) { CV_FFmpegWriteBigVideoTest test; test.safe_run(); }
...@@ -41,70 +41,46 @@ ...@@ -41,70 +41,46 @@
//M*/ //M*/
#include "test_precomp.hpp" #include "test_precomp.hpp"
#include "opencv2/highgui/highgui.hpp"
#if 0
#include <string>
#include <iostream>
#include <fstream>
#include <iterator>
#include <iostream>
#include "cvaux.h"
using namespace cv; using namespace cv;
using namespace std; using namespace std;
//#if defined WIN32 || defined _WIN32 || defined WIN64 || defined _WIN64 class CV_HighGuiOnlyGuiTest : public cvtest::BaseTest
#define MARKERS
#ifdef MARKERS
#define marker(x) cout << (x) << endl
#else
#define marker(x)
#endif
class CV_HighGuiOnlyGuiTest : public CvTest
{ {
public: protected:
CV_HighGuiOnlyGuiTest(); void run(int);
~CV_HighGuiOnlyGuiTest();
protected:
void run(int);
}; };
CV_HighGuiOnlyGuiTest::CV_HighGuiOnlyGuiTest(): CvTest( "z-highgui-gui-only", "?" )
{
support_testing_modes = CvTS::CORRECTNESS_CHECK_MODE;
}
CV_HighGuiOnlyGuiTest::~CV_HighGuiOnlyGuiTest() {}
void Foo(int /*k*/, void* /*z*/) {} void Foo(int /*k*/, void* /*z*/) {}
void CV_HighGuiOnlyGuiTest::run( int /*start_from */) void CV_HighGuiOnlyGuiTest::run( int /*start_from */)
{ {
cout << "GUI 1" << endl; ts->printf(ts->LOG, "GUI 1\n");
namedWindow("Win"); namedWindow("Win");
cout << "GUI 2" << endl;
Mat m(30, 30, CV_8U); ts->printf(ts->LOG, "GUI 2\n");
Mat m(256, 256, CV_8U);
m = Scalar(128); m = Scalar(128);
cout << "GUI 3" << endl;
ts->printf(ts->LOG, "GUI 3\n");
imshow("Win", m); imshow("Win", m);
cout << "GUI 4" << endl;
ts->printf(ts->LOG, "GUI 4\n");
int value = 50; int value = 50;
cout << "GUI 5" << endl;
ts->printf(ts->LOG, "GUI 5\n");
createTrackbar( "trackbar", "Win", &value, 100, Foo, &value); createTrackbar( "trackbar", "Win", &value, 100, Foo, &value);
cout << "GUI 6" << endl;
ts->printf(ts->LOG, "GUI 6\n");
getTrackbarPos( "trackbar", "Win" ); getTrackbarPos( "trackbar", "Win" );
cout << "GUI 7" << endl;
ts->printf(ts->LOG, "GUI 7\n");
waitKey(500); waitKey(500);
cout << "GUI 8" << endl;
ts->printf(ts->LOG, "GUI 8\n");
cvDestroyAllWindows(); cvDestroyAllWindows();
cout << "GUI 9" << endl; ts->set_failed_test_info(cvtest::TS::OK);
ts->set_failed_test_info(CvTS::OK);
} }
CV_HighGuiOnlyGuiTest highGuiOnlyGui_test; TEST(Highgui_GUI, regression) { CV_HighGuiOnlyGuiTest test; test.safe_run(); }
#endif
...@@ -41,103 +41,62 @@ ...@@ -41,103 +41,62 @@
//M*/ //M*/
#include "test_precomp.hpp" #include "test_precomp.hpp"
#include "opencv2/highgui/highgui.hpp"
#if 0
#include <string>
#include <iostream>
#include <fstream>
#include <iterator>
using namespace cv; using namespace cv;
using namespace std; using namespace std;
#if defined WIN32 || defined _WIN32 class CV_HighGuiTest : public cvtest::BaseTest
//#if 0
#else
#define MARKERS1
#ifdef MARKERS
#define marker(x) cout << (x) << endl
#else
#define marker(x)
#endif
struct TempDirHolder
{ {
string temp_folder; protected:
TempDirHolder() void ImagesTest(const string& dir);
{ void VideoTest (const string& dir, int fourcc);
temp_folder = tempfile();
exec_cmd("mkdir " + temp_folder);
}
~TempDirHolder() { exec_cmd("rm -rf " + temp_folder); }
static void exec_cmd(const string& cmd) { marker(cmd); int res = system( cmd.c_str() ); (void)res; }
TempDirHolder& operator=(const TempDirHolder&);
};
public:
class CV_HighGuiTest : public CvTest void run(int);
{
public:
CV_HighGuiTest();
~CV_HighGuiTest();
protected:
void run(int);
bool ImagesTest(const string& dir, const string& tmp);
bool VideoTest(const string& dir, const string& tmp, int fourcc);
bool GuiTest(const string& dir, const string& tmp);
}; };
CV_HighGuiTest::CV_HighGuiTest(): CvTest( "z-highgui", "?" )
{
support_testing_modes = CvTS::CORRECTNESS_CHECK_MODE;
}
CV_HighGuiTest::~CV_HighGuiTest() {}
double PSNR(const Mat& m1, const Mat& m2) double PSNR(const Mat& m1, const Mat& m2)
{ {
Mat tmp; Mat tmp;
absdiff( m1.reshape(1), m2.reshape(1), tmp); absdiff( m1.reshape(1), m2.reshape(1), tmp);
multiply(tmp, tmp, tmp); multiply(tmp, tmp, tmp);
double MSE = 1.0/(tmp.cols * tmp.rows) * sum(tmp)[0]; double MSE = 1.0/(tmp.cols * tmp.rows) * sum(tmp)[0];
return 20 * log10(255.0 / sqrt(MSE)); return 20 * log10(255.0 / sqrt(MSE));
} }
bool CV_HighGuiTest::ImagesTest(const string& dir, const string& tmp) void CV_HighGuiTest::ImagesTest(const string& dir)
{ {
int code = CvTS::OK; string _name = dir + string("shared/baboon.jpg");
ts->printf(ts->LOG, "reading image : %s\n", _name.c_str());
Mat image = imread(dir + "shared/baboon.jpg"); Mat image = imread(dir + "shared/baboon.jpg");
image.convertTo(image, CV_8UC3);
if (image.empty()) if (image.empty())
{ {
ts->set_failed_test_info(CvTS::FAIL_MISSING_TEST_DATA); ts->set_failed_test_info(ts->FAIL_MISSING_TEST_DATA);
return false; return;
} }
const string exts[] = {"png", "bmp", "tiff", "jpg", "jp2", "ppm", "ras"}; const string exts[] = {"png", "bmp", "tiff", "jpg", "jp2", "ppm", "ras" };
const size_t ext_num = sizeof(exts)/sizeof(exts[0]); const size_t ext_num = sizeof(exts)/sizeof(exts[0]);
for(size_t i = 0; i < ext_num; ++i) for(size_t i = 0; i < ext_num; ++i)
{ {
ts->printf(CvTS::LOG, "ext=%s\n", exts[i].c_str());
string ext = exts[i]; string ext = exts[i];
string full_name = tmp + "/img." + ext; string full_name = dir + "img." + ext;
marker(exts[i]); ts->printf(ts->LOG, " full_name : %s\n", full_name.c_str());
imwrite(full_name, image); imwrite(full_name, image);
Mat loaded = imread(full_name); Mat loaded = imread(full_name);
if (loaded.empty()) if (loaded.empty())
{ {
ts->printf(CvTS::LOG, "Reading failed at fmt=%s\n", ext.c_str()); ts->printf(ts->LOG, "Reading failed at fmt=%s\n", ext.c_str());
code = CvTS::FAIL_MISMATCH; ts->set_failed_test_info(ts->FAIL_MISMATCH);
continue; continue;
} }
...@@ -145,62 +104,68 @@ bool CV_HighGuiTest::ImagesTest(const string& dir, const string& tmp) ...@@ -145,62 +104,68 @@ bool CV_HighGuiTest::ImagesTest(const string& dir, const string& tmp)
double psnr = PSNR(loaded, image); double psnr = PSNR(loaded, image);
if (psnr < thresDbell) if (psnr < thresDbell)
{ {
ts->printf(CvTS::LOG, "Reading image from file: too big difference (=%g) with fmt=%s\n", psnr, ext.c_str()); ts->printf(ts->LOG, "Reading image from file: too big difference (=%g) with fmt=%s\n", psnr, ext.c_str());
code = CvTS::FAIL_BAD_ACCURACY; ts->set_failed_test_info(ts->FAIL_BAD_ACCURACY);
continue; continue;
} }
vector<uchar> from_file;
FILE *f = fopen(full_name.c_str(), "rb"); FILE *f = fopen(full_name.c_str(), "rb");
fseek(f, 0, SEEK_END); fseek(f, 0, SEEK_END);
size_t len = ftell(f); long len = ftell(f);
vector<uchar> from_file(len); from_file.resize((size_t)len);
fseek(f, 0, SEEK_SET); fseek(f, 0, SEEK_SET);
size_t read = fread(&from_file[0], len, sizeof(vector<uchar>::value_type), f); (void)read; from_file.resize(fread(&from_file[0], 1, from_file.size(), f));
fclose(f); fclose(f);
vector<uchar> buf; vector<uchar> buf;
imencode("." + exts[i], image, buf); imencode("." + exts[i], image, buf);
if (buf != from_file) if (buf != from_file)
{ {
ts->printf(CvTS::LOG, "Encoding failed with fmt=%s\n", ext.c_str()); ts->printf(ts->LOG, "Encoding failed with fmt=%s\n", ext.c_str());
code = CvTS::FAIL_MISMATCH; ts->set_failed_test_info(ts->FAIL_MISMATCH);
continue; continue;
} }
Mat buf_loaded = imdecode(Mat(buf), 1); Mat buf_loaded = imdecode(Mat(buf), 1);
if (buf_loaded.empty()) if (buf_loaded.empty())
{ {
ts->printf(CvTS::LOG, "Decoding failed with fmt=%s\n", ext.c_str()); ts->printf(ts->LOG, "Decoding failed with fmt=%s\n", ext.c_str());
code = CvTS::FAIL_MISMATCH; ts->set_failed_test_info(ts->FAIL_MISMATCH);
continue; continue;
} }
psnr = PSNR(buf_loaded, image); psnr = PSNR(buf_loaded, image);
if (psnr < thresDbell) if (psnr < thresDbell)
{ {
ts->printf(CvTS::LOG, "Decoding image from memory: too small PSNR (=%gdb) with fmt=%s\n", psnr, ext.c_str()); ts->printf(ts->LOG, "Decoding image from memory: too small PSNR (=%gdb) with fmt=%s\n", psnr, ext.c_str());
code = CvTS::FAIL_MISMATCH; ts->set_failed_test_info(ts->FAIL_MISMATCH);
continue; continue;
} }
} }
ts->set_failed_test_info(code);
return code == CvTS::OK; ts->printf(ts->LOG, "end test function : ImagesTest \n");
ts->set_failed_test_info(ts->OK);
} }
bool CV_HighGuiTest::VideoTest(const string& dir, const string& tmp, int fourcc) void CV_HighGuiTest::VideoTest(const string& dir, int fourcc)
{ {
string src_file = dir + "shared/video_for_test.avi"; string src_file = dir + "shared/video_for_test.avi";
string tmp_name = tmp + "/video.avi"; string tmp_name = dir + "video.avi";
ts->printf(ts->LOG, "reading video : %s\n", src_file.c_str());
CvCapture* cap = cvCaptureFromFile(src_file.c_str()); CvCapture* cap = cvCaptureFromFile(src_file.c_str());
if (!cap) if (!cap)
{ {
ts->set_failed_test_info(CvTS::FAIL_MISMATCH); ts->set_failed_test_info(ts->FAIL_MISMATCH);
return false; return;
} }
CvVideoWriter* writer = 0; CvVideoWriter* writer = 0;
...@@ -208,7 +173,7 @@ bool CV_HighGuiTest::VideoTest(const string& dir, const string& tmp, int fourcc) ...@@ -208,7 +173,7 @@ bool CV_HighGuiTest::VideoTest(const string& dir, const string& tmp, int fourcc)
int counter = 0; int counter = 0;
for(;;) for(;;)
{ {
IplImage* img = cvQueryFrame( cap ); IplImage * img = cvQueryFrame( cap );
if (!img) if (!img)
break; break;
...@@ -218,42 +183,35 @@ bool CV_HighGuiTest::VideoTest(const string& dir, const string& tmp, int fourcc) ...@@ -218,42 +183,35 @@ bool CV_HighGuiTest::VideoTest(const string& dir, const string& tmp, int fourcc)
writer = cvCreateVideoWriter(tmp_name.c_str(), fourcc, 24, cvGetSize(img)); writer = cvCreateVideoWriter(tmp_name.c_str(), fourcc, 24, cvGetSize(img));
if (writer == 0) if (writer == 0)
{ {
marker("can't craete writer"); ts->printf(ts->LOG, "can't create writer\n");
cvReleaseCapture( &cap ); cvReleaseCapture( &cap );
ts->set_failed_test_info(CvTS::FAIL_MISMATCH); ts->set_failed_test_info(ts->FAIL_MISMATCH);
return false; return;
} }
} }
cvWriteFrame(writer, img); cvWriteFrame(writer, img);
} }
cvReleaseVideoWriter( &writer ); cvReleaseVideoWriter( &writer );
cvReleaseCapture( &cap ); cvReleaseCapture( &cap );
marker("mid++");
cap = cvCaptureFromFile(src_file.c_str()); cap = cvCaptureFromFile(src_file.c_str());
marker("mid1");
CvCapture *saved = cvCaptureFromFile(tmp_name.c_str()); CvCapture *saved = cvCaptureFromFile(tmp_name.c_str());
if (!saved) if (!saved)
{ {
ts->set_failed_test_info(CvTS::FAIL_MISMATCH); ts->set_failed_test_info(ts->FAIL_MISMATCH);
return false; return;
} }
const double thresDbell = 20; const double thresDbell = 20;
bool error = false;
counter = 0; counter = 0;
for(;;) for(;;)
{ {
IplImage* ipl = cvQueryFrame( cap );
IplImage* ipl = cvQueryFrame( cap );
IplImage* ipl1 = cvQueryFrame( saved ); IplImage* ipl1 = cvQueryFrame( saved );
if (!ipl || !ipl1) if (!ipl || !ipl1)
break; break;
...@@ -263,54 +221,35 @@ bool CV_HighGuiTest::VideoTest(const string& dir, const string& tmp, int fourcc) ...@@ -263,54 +221,35 @@ bool CV_HighGuiTest::VideoTest(const string& dir, const string& tmp, int fourcc)
if (PSNR(img1, img) < thresDbell) if (PSNR(img1, img) < thresDbell)
{ {
error = true; ts->set_failed_test_info(ts->FAIL_MISMATCH);
break; break;
} }
} }
cvReleaseCapture( &cap ); cvReleaseCapture( &cap );
cvReleaseCapture( &saved ); cvReleaseCapture( &saved );
if (error) ts->printf(ts->LOG, "end test function : ImagesVideo \n");
{
ts->set_failed_test_info(CvTS::FAIL_MISMATCH);
return false;
}
return true;
} }
void CV_HighGuiTest::run( int /*start_from */) void CV_HighGuiTest::run( int /*start_from */)
{ {
TempDirHolder th; ImagesTest(ts->get_data_path());
if (!ImagesTest(ts->get_data_path(), th.temp_folder))
return;
#if defined WIN32 || defined __linux__ #if defined WIN32 || defined __linux__
#if !defined HAVE_GSTREAMER || defined HAVE_GSTREAMER_APP #if !defined HAVE_GSTREAMER || defined HAVE_GSTREAMER_APP
if (!VideoTest(ts->get_data_path(), th.temp_folder, CV_FOURCC_DEFAULT))
return;
VideoTest(ts->get_data_path(), CV_FOURCC_DEFAULT);
if (!VideoTest(ts->get_data_path(), th.temp_folder, CV_FOURCC('M', 'J', 'P', 'G'))) VideoTest(ts->get_data_path(), CV_FOURCC('X', 'V', 'I', 'D'));
return;
VideoTest(ts->get_data_path(), CV_FOURCC('M', 'P', 'G', '2'));
if (!VideoTest(ts->get_data_path(), th.temp_folder, CV_FOURCC('M', 'P', 'G', '2')))
return;
#endif
//if (!VideoTest(ts->get_data_path(), th.temp_folder, CV_FOURCC('D', 'X', '5', '0'))) return;
#endif
ts->set_failed_test_info(CvTS::OK);
}
CV_HighGuiTest HighGui_test;
VideoTest(ts->get_data_path(), CV_FOURCC('M', 'J', 'P', 'G'));
#endif #endif
#endif #endif
}
TEST(Highgui_HighGui, regression) { CV_HighGuiTest test; test.safe_run(); }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment