test_video_io.cpp 18.3 KB
Newer Older
wester committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
/*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"
wester committed
44
#include "opencv2/highgui/highgui.hpp"
wester committed
45 46 47 48

using namespace cv;
using namespace std;

a  
Kai Westerkamp committed
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
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[] =
{
wester committed
88 89 90 91 92 93 94
    VideoFormat("avi", CV_FOURCC('X', 'V', 'I', 'D')),
    VideoFormat("avi", CV_FOURCC('M', 'P', 'E', 'G')),
    VideoFormat("avi", CV_FOURCC('M', 'J', 'P', 'G')),
    //VideoFormat("avi", CV_FOURCC('I', 'Y', 'U', 'V')),
    VideoFormat("mkv", CV_FOURCC('X', 'V', 'I', 'D')),
    VideoFormat("mkv", CV_FOURCC('M', 'P', 'E', 'G')),
    VideoFormat("mkv", CV_FOURCC('M', 'J', 'P', 'G')),
a  
Kai Westerkamp committed
95
#ifndef HAVE_GSTREAMER
wester committed
96
    VideoFormat("mov", CV_FOURCC('m', 'p', '4', 'v')),
a  
Kai Westerkamp committed
97 98 99 100 101 102 103
#endif
    VideoFormat()
};
#endif

}

wester committed
104
class CV_HighGuiTest : public cvtest::BaseTest
wester committed
105 106
{
protected:
a  
Kai Westerkamp committed
107 108 109 110 111
    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);

wester committed
112 113
    CV_HighGuiTest() {}
    ~CV_HighGuiTest() {}
a  
Kai Westerkamp committed
114 115 116
    virtual void run(int) = 0;
};

wester committed
117
class CV_ImageTest : public CV_HighGuiTest
a  
Kai Westerkamp committed
118 119 120 121 122 123 124
{
public:
    CV_ImageTest() {}
    ~CV_ImageTest() {}
    void run(int);
};

wester committed
125
class CV_SpecificImageTest : public CV_HighGuiTest
a  
Kai Westerkamp committed
126 127 128 129 130 131 132
{
public:
    CV_SpecificImageTest() {}
    ~CV_SpecificImageTest() {}
    void run(int);
};

wester committed
133
class CV_VideoTest : public CV_HighGuiTest
a  
Kai Westerkamp committed
134 135 136 137 138 139 140
{
public:
    CV_VideoTest() {}
    ~CV_VideoTest() {}
    void run(int);
};

wester committed
141
class CV_SpecificVideoTest : public CV_HighGuiTest
a  
Kai Westerkamp committed
142 143 144 145 146 147 148 149
{
public:
    CV_SpecificVideoTest() {}
    ~CV_SpecificVideoTest() {}
    void run(int);
};


wester committed
150
void CV_HighGuiTest::ImageTest(const string& dir)
a  
Kai Westerkamp committed
151 152 153 154 155 156 157 158
{
    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())
wester committed
159
    {
a  
Kai Westerkamp committed
160 161
        ts->set_failed_test_info(ts->FAIL_MISSING_TEST_DATA);
        return;
wester committed
162
    }
a  
Kai Westerkamp committed
163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186

    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)
wester committed
187
    {
a  
Kai Westerkamp committed
188 189 190 191 192 193 194 195
        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())
wester committed
196
        {
a  
Kai Westerkamp committed
197 198 199
            ts->printf(ts->LOG, "Reading failed at fmt=%s\n", ext.c_str());
            ts->set_failed_test_info(ts->FAIL_MISMATCH);
            continue;
wester committed
200 201
        }

a  
Kai Westerkamp committed
202
        const double thresDbell = 20;
wester committed
203
        double psnr = PSNR(loaded, image);
a  
Kai Westerkamp committed
204
        if (psnr < thresDbell)
wester committed
205
        {
a  
Kai Westerkamp committed
206 207 208
            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;
wester committed
209
        }
a  
Kai Westerkamp committed
210 211 212 213 214 215 216 217 218 219 220 221 222 223 224

        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)
wester committed
225
        {
a  
Kai Westerkamp committed
226 227 228
            ts->printf(ts->LOG, "Encoding failed with fmt=%s\n", ext.c_str());
            ts->set_failed_test_info(ts->FAIL_MISMATCH);
            continue;
wester committed
229 230
        }

a  
Kai Westerkamp committed
231 232 233
        Mat buf_loaded = imdecode(Mat(buf), 1);

        if (buf_loaded.empty())
wester committed
234
        {
a  
Kai Westerkamp committed
235 236 237
            ts->printf(ts->LOG, "Decoding failed with fmt=%s\n", ext.c_str());
            ts->set_failed_test_info(ts->FAIL_MISMATCH);
            continue;
wester committed
238 239
        }

wester committed
240
        psnr = PSNR(buf_loaded, image);
a  
Kai Westerkamp committed
241 242

        if (psnr < thresDbell)
wester committed
243
        {
a  
Kai Westerkamp committed
244 245 246
            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;
wester committed
247 248
        }

a  
Kai Westerkamp committed
249 250 251 252 253 254 255
    }

    ts->printf(ts->LOG, "end test function : ImagesTest \n");
    ts->set_failed_test_info(ts->OK);
}


wester committed
256
void CV_HighGuiTest::VideoTest(const string& dir, const cvtest::VideoFormat& fmt)
a  
Kai Westerkamp committed
257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280
{
    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;

wester committed
281
        frames.push_back(Mat(img).clone());
a  
Kai Westerkamp committed
282 283

        if (writer == NULL)
wester committed
284
        {
a  
Kai Westerkamp committed
285 286
            writer = cvCreateVideoWriter(tmp_name.c_str(), fmt.fourcc, 24, cvGetSize(img));
            if (writer == NULL)
wester committed
287
            {
a  
Kai Westerkamp committed
288 289 290 291 292
                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;
wester committed
293 294 295
            }
        }

a  
Kai Westerkamp committed
296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318
        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];
wester committed
319
        Mat img1(ipl1);
a  
Kai Westerkamp committed
320

wester committed
321
        double psnr = PSNR(img1, img);
a  
Kai Westerkamp committed
322
        if (psnr < thresDbell)
wester committed
323
        {
a  
Kai Westerkamp committed
324 325 326 327 328 329 330 331 332 333
            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;
wester committed
334 335 336
        }
    }

a  
Kai Westerkamp committed
337
    cvReleaseCapture( &saved );
wester committed
338

a  
Kai Westerkamp committed
339 340 341
    ts->printf(ts->LOG, "end test function : ImagesVideo \n");
}

wester committed
342
void CV_HighGuiTest::SpecificImageTest(const string& dir)
wester committed
343
{
a  
Kai Westerkamp committed
344 345 346
    const size_t IMAGE_COUNT = 10;

    for (size_t i = 0; i < IMAGE_COUNT; ++i)
wester committed
347
    {
a  
Kai Westerkamp committed
348 349 350 351 352
        stringstream s; s << i;
        string file_path = dir+"../python/images/QCIF_0"+s.str()+".bmp";
        Mat image = imread(file_path);

        if (image.empty())
wester committed
353
        {
a  
Kai Westerkamp committed
354
            ts->set_failed_test_info(ts->FAIL_MISSING_TEST_DATA);
wester committed
355 356 357
            return;
        }

a  
Kai Westerkamp committed
358
        resize(image, image, Size(968, 757), 0.0, 0.0, INTER_CUBIC);
wester committed
359

a  
Kai Westerkamp committed
360
        stringstream s_digit; s_digit << i;
wester committed
361

a  
Kai Westerkamp committed
362 363
        string full_name = cv::tempfile((s_digit.str() + ".bmp").c_str());
        ts->printf(ts->LOG, " full_name : %s\n", full_name.c_str());
wester committed
364

a  
Kai Westerkamp committed
365
        imwrite(full_name, image);
wester committed
366

a  
Kai Westerkamp committed
367 368
        Mat loaded = imread(full_name);
        if (loaded.empty())
wester committed
369
        {
a  
Kai Westerkamp committed
370 371 372
            ts->printf(ts->LOG, "Reading failed at fmt=bmp\n");
            ts->set_failed_test_info(ts->FAIL_MISMATCH);
            continue;
wester committed
373 374
        }

a  
Kai Westerkamp committed
375
        const double thresDbell = 20;
wester committed
376
        double psnr = PSNR(loaded, image);
a  
Kai Westerkamp committed
377
        if (psnr < thresDbell)
wester committed
378
        {
a  
Kai Westerkamp committed
379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412
            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;
        }

wester committed
413
        psnr = PSNR(buf_loaded, image);
a  
Kai Westerkamp committed
414 415 416 417 418 419

        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;
wester committed
420 421 422
        }
    }

a  
Kai Westerkamp committed
423 424 425 426
    ts->printf(ts->LOG, "end test function : SpecificImageTest \n");
    ts->set_failed_test_info(ts->OK);
}

wester committed
427

wester committed
428
void CV_HighGuiTest::SpecificVideoTest(const string& dir, const cvtest::VideoFormat& fmt)
wester committed
429
{
a  
Kai Westerkamp committed
430 431 432 433 434 435 436 437 438 439
    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())
wester committed
440
    {
a  
Kai Westerkamp committed
441 442 443 444 445 446
        // 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;
wester committed
447
    }
a  
Kai Westerkamp committed
448 449 450 451 452

    const size_t IMAGE_COUNT = 30;
    vector<Mat> images;

    for( size_t i = 0; i < IMAGE_COUNT; ++i )
wester committed
453
    {
a  
Kai Westerkamp committed
454
        string file_path = format("%s../python/images/QCIF_%02d.bmp", dir.c_str(), i);
wester committed
455
        Mat img = imread(file_path, CV_LOAD_IMAGE_COLOR);
a  
Kai Westerkamp committed
456 457

        if (img.empty())
wester committed
458
        {
a  
Kai Westerkamp committed
459 460 461 462 463
            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;
wester committed
464 465
        }

a  
Kai Westerkamp committed
466 467 468 469 470 471 472
        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);
wester committed
473

a  
Kai Westerkamp committed
474 475
        images.push_back(img);
        writer << img;
wester committed
476 477
    }

a  
Kai Westerkamp committed
478 479 480
    writer.release();
    VideoCapture cap(video_file);

wester committed
481
    size_t FRAME_COUNT = (size_t)cap.get(CV_CAP_PROP_FRAME_COUNT);
a  
Kai Westerkamp committed
482 483

    size_t allowed_extra_frames = 0;
wester committed
484

a  
Kai Westerkamp committed
485 486 487 488 489 490 491
    // 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.
wester committed
492
    if (fourcc == CV_FOURCC('M', 'P', 'E', 'G') && ext == "mkv")
a  
Kai Westerkamp committed
493
        allowed_extra_frames = 1;
wester committed
494

a  
Kai Westerkamp committed
495 496 497 498
    // Hack! Some GStreamer encoding pipelines drop last frame in the video
    int allowed_frame_frop = 0;
#ifdef HAVE_GSTREAMER
    allowed_frame_frop = 1;
wester committed
499 500
#endif

a  
Kai Westerkamp committed
501 502 503 504 505 506 507 508 509 510 511 512 513 514
    if (FRAME_COUNT < IMAGE_COUNT - allowed_frame_frop || 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;
    }
wester committed
515

a  
Kai Westerkamp committed
516 517 518 519 520 521 522 523 524 525 526 527
    for (int i = 0; (size_t)i < IMAGE_COUNT-allowed_frame_frop; 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;
        }
wester committed
528

a  
Kai Westerkamp committed
529
        Mat img = images[i];
wester committed
530

a  
Kai Westerkamp committed
531
        const double thresDbell = 40;
wester committed
532
        double psnr = PSNR(img, frame);
wester committed
533

a  
Kai Westerkamp committed
534 535 536 537 538 539 540 541 542 543 544
        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;
        }
    }
}
wester committed
545

a  
Kai Westerkamp committed
546
void CV_ImageTest::run(int)
wester committed
547
{
a  
Kai Westerkamp committed
548
    ImageTest(ts->get_data_path());
wester committed
549 550
}

a  
Kai Westerkamp committed
551 552 553 554
void CV_SpecificImageTest::run(int)
{
    SpecificImageTest(ts->get_data_path());
}
wester committed
555

a  
Kai Westerkamp committed
556 557 558 559 560 561 562 563 564 565
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);
    }
}
wester committed
566

a  
Kai Westerkamp committed
567 568 569 570 571 572 573 574 575 576
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);
    }
}
wester committed
577

a  
Kai Westerkamp committed
578
#ifdef HAVE_JPEG
wester committed
579
TEST(Highgui_Image, regression) { CV_ImageTest test; test.safe_run(); }
wester committed
580 581
#endif

a  
Kai Westerkamp committed
582
#if BUILD_WITH_VIDEO_INPUT_SUPPORT && BUILD_WITH_VIDEO_OUTPUT_SUPPORT && !defined(__APPLE__)
wester committed
583 584
TEST(Highgui_Video, regression) { CV_VideoTest test; test.safe_run(); }
TEST(Highgui_Video, write_read) { CV_SpecificVideoTest test; test.safe_run(); }
a  
Kai Westerkamp committed
585
#endif
wester committed
586

wester committed
587
TEST(Highgui_Image, write_read) { CV_SpecificImageTest test; test.safe_run(); }