fixed many warnings from GCC 4.6.1
[profile/ivi/opencv.git] / modules / highgui / test / test_video_io.cpp
1 /*M///////////////////////////////////////////////////////////////////////////////////////
2 //
3 //  IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
4 //
5 //  By downloading, copying, installing or using the software you agree to this license.
6 //  If you do not agree to this license, do not download, install,
7 //  copy or use the software.
8 //
9 //
10 //                           License Agreement
11 //                For Open Source Computer Vision Library
12 //
13 // Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
14 // Copyright (C) 2009, Willow Garage Inc., all rights reserved.
15 // Third party copyrights are property of their respective owners.
16 //
17 // Redistribution and use in source and binary forms, with or without modification,
18 // are permitted provided that the following conditions are met:
19 //
20 //   * Redistribution's of source code must retain the above copyright notice,
21 //     this list of conditions and the following disclaimer.
22 //
23 //   * Redistribution's in binary form must reproduce the above copyright notice,
24 //     this list of conditions and the following disclaimer in the documentation
25 //     and/or other materials provided with the distribution.
26 //
27 //   * The name of the copyright holders may not be used to endorse or promote products
28 //     derived from this software without specific prior written permission.
29 //
30 // This software is provided by the copyright holders and contributors "as is" and
31 // any express or implied warranties, including, but not limited to, the implied
32 // warranties of merchantability and fitness for a particular purpose are disclaimed.
33 // In no event shall the Intel Corporation or contributors be liable for any direct,
34 // indirect, incidental, special, exemplary, or consequential damages
35 // (including, but not limited to, procurement of substitute goods or services;
36 // loss of use, data, or profits; or business interruption) however caused
37 // and on any theory of liability, whether in contract, strict liability,
38 // or tort (including negligence or otherwise) arising in any way out of
39 // the use of this software, even if advised of the possibility of such damage.
40 //
41 //M*/
42
43 #include "test_precomp.hpp"
44 #include "opencv2/highgui/highgui.hpp"
45
46 using namespace cv;
47 using namespace std;
48
49 class CV_HighGuiTest : public cvtest::BaseTest
50 {
51 protected:
52     void ImageTest(const string& dir);
53     void VideoTest (const string& dir, int fourcc);
54     void SpecificImageTest (const string& dir);
55     void SpecificVideoFileTest (const string& dir, const char codecchars[4]);
56     void SpecificVideoCameraTest (const string& dir, const char codecchars[4]);
57
58 public:
59     CV_HighGuiTest();
60     ~CV_HighGuiTest();
61     virtual void run(int) = 0;
62 };
63
64 class CV_ImageTest : public CV_HighGuiTest
65 {
66 public:
67     CV_ImageTest();
68     ~CV_ImageTest();
69     void run(int);
70 };
71
72 class CV_SpecificImageTest : public CV_HighGuiTest
73 {
74 public:
75     CV_SpecificImageTest();
76     ~CV_SpecificImageTest();
77     void run(int);
78 };
79
80 class CV_VideoTest : public CV_HighGuiTest
81 {
82 public:
83     CV_VideoTest();
84     ~CV_VideoTest();
85     void run(int);
86 };
87
88 class CV_SpecificVideoFileTest : public CV_HighGuiTest
89 {
90 public:
91     CV_SpecificVideoFileTest();
92     ~CV_SpecificVideoFileTest();
93     void run(int);
94 };
95
96 class CV_SpecificVideoCameraTest : public CV_HighGuiTest
97 {
98 public:
99     CV_SpecificVideoCameraTest();
100     ~CV_SpecificVideoCameraTest();
101     void run(int);
102 };
103
104 CV_HighGuiTest::CV_HighGuiTest() {}
105 CV_HighGuiTest::~CV_HighGuiTest() {}
106
107 CV_ImageTest::CV_ImageTest() : CV_HighGuiTest() {}
108 CV_VideoTest::CV_VideoTest() : CV_HighGuiTest() {}
109 CV_SpecificImageTest::CV_SpecificImageTest() : CV_HighGuiTest() {}
110 CV_SpecificVideoFileTest::CV_SpecificVideoFileTest() : CV_HighGuiTest() {}
111 CV_SpecificVideoCameraTest::CV_SpecificVideoCameraTest() : CV_HighGuiTest() {}
112
113 CV_ImageTest::~CV_ImageTest() {}
114 CV_VideoTest::~CV_VideoTest() {}
115 CV_SpecificImageTest::~CV_SpecificImageTest() {}
116 CV_SpecificVideoFileTest::~CV_SpecificVideoFileTest() {}
117 CV_SpecificVideoCameraTest::~CV_SpecificVideoCameraTest() {}
118
119 double PSNR(const Mat& m1, const Mat& m2)
120 {               
121     Mat tmp;
122     absdiff( m1.reshape(1), m2.reshape(1), tmp);
123     multiply(tmp, tmp, tmp);
124
125     double MSE = 1.0/(tmp.cols * tmp.rows) * sum(tmp)[0];
126
127     return 20 * log10(255.0 / sqrt(MSE));
128 }
129
130 void CV_HighGuiTest::ImageTest(const string& dir)
131 {
132     string _name = dir + string("../cv/shared/baboon.jpg");
133     ts->printf(ts->LOG, "reading image : %s\n", _name.c_str());
134
135     Mat image = imread(_name);
136     image.convertTo(image, CV_8UC3);
137
138     if (image.empty())
139     {
140         ts->set_failed_test_info(ts->FAIL_MISSING_TEST_DATA);
141         return;
142     }
143
144     const string exts[] = {"png", "bmp", "tiff", "jpg", "jp2", "ppm", "ras" };
145     const size_t ext_num = sizeof(exts)/sizeof(exts[0]);
146
147     for(size_t i = 0; i < ext_num; ++i)
148     {
149         string ext = exts[i];
150         string full_name = dir + "img." + ext;
151         ts->printf(ts->LOG, " full_name : %s\n", full_name.c_str());
152
153         imwrite(full_name, image);
154
155         Mat loaded = imread(full_name);
156         if (loaded.empty())
157         {
158             ts->printf(ts->LOG, "Reading failed at fmt=%s\n", ext.c_str());
159             ts->set_failed_test_info(ts->FAIL_MISMATCH);
160             continue;
161         }
162
163         const double thresDbell = 20;
164         double psnr = PSNR(loaded, image);
165         if (psnr < thresDbell)
166         {
167             ts->printf(ts->LOG, "Reading image from file: too big difference (=%g) with fmt=%s\n", psnr, ext.c_str());
168             ts->set_failed_test_info(ts->FAIL_BAD_ACCURACY);
169             continue;
170         }
171
172         vector<uchar> from_file;
173
174         FILE *f = fopen(full_name.c_str(), "rb");
175         fseek(f, 0, SEEK_END);
176         long len = ftell(f);
177         from_file.resize((size_t)len);
178         fseek(f, 0, SEEK_SET);
179         from_file.resize(fread(&from_file[0], 1, from_file.size(), f));
180         fclose(f);
181
182         vector<uchar> buf;
183         imencode("." + exts[i], image, buf);
184
185         if (buf != from_file)
186         {
187             ts->printf(ts->LOG, "Encoding failed with fmt=%s\n", ext.c_str());
188             ts->set_failed_test_info(ts->FAIL_MISMATCH);
189             continue;
190         }
191
192         Mat buf_loaded = imdecode(Mat(buf), 1);
193
194         if (buf_loaded.empty())
195         {
196             ts->printf(ts->LOG, "Decoding failed with fmt=%s\n", ext.c_str());
197             ts->set_failed_test_info(ts->FAIL_MISMATCH);
198             continue;
199         }
200
201         psnr = PSNR(buf_loaded, image);
202
203         if (psnr < thresDbell)
204         {
205             ts->printf(ts->LOG, "Decoding image from memory: too small PSNR (=%gdb) with fmt=%s\n", psnr, ext.c_str());
206             ts->set_failed_test_info(ts->FAIL_MISMATCH);
207             continue;
208         }
209
210     }
211
212     ts->printf(ts->LOG, "end test function : ImagesTest \n");
213     ts->set_failed_test_info(ts->OK);
214 }
215
216 void CV_HighGuiTest::VideoTest(const string& dir, int fourcc)
217 {       
218     string src_file = dir + "../cv/shared/video_for_test.avi";
219     string tmp_name = dir + "video.avi";
220
221     ts->printf(ts->LOG, "reading video : %s\n", src_file.c_str());
222
223     CvCapture* cap = cvCaptureFromFile(src_file.c_str());
224
225     if (!cap)
226     {
227         ts->set_failed_test_info(ts->FAIL_MISMATCH);
228         return;
229     }
230
231     CvVideoWriter* writer = 0;
232
233     for(;;)
234     {
235         IplImage * img = cvQueryFrame( cap );
236
237         if (!img)
238             break;
239
240         if (writer == 0)
241         {
242             writer = cvCreateVideoWriter(tmp_name.c_str(), fourcc, 24, cvGetSize(img));
243             if (writer == 0)
244             {
245                 ts->printf(ts->LOG, "can't create writer (with fourcc : %d)\n", fourcc);
246                 cvReleaseCapture( &cap );
247                 ts->set_failed_test_info(ts->FAIL_MISMATCH);
248                 return;
249             }
250         }
251
252         cvWriteFrame(writer, img);
253     }
254
255     cvReleaseVideoWriter( &writer );
256     cvReleaseCapture( &cap );
257
258     cap = cvCaptureFromFile(src_file.c_str());
259
260     CvCapture *saved = cvCaptureFromFile(tmp_name.c_str());
261     if (!saved)
262     {
263         ts->set_failed_test_info(ts->FAIL_MISMATCH);
264         return;
265     }
266
267     const double thresDbell = 20;
268
269     for(;;)
270     {
271         IplImage* ipl  = cvQueryFrame( cap );
272         IplImage* ipl1 = cvQueryFrame( saved );
273
274         if (!ipl || !ipl1)
275             break;
276
277         Mat img(ipl);
278         Mat img1(ipl1);
279
280         if (PSNR(img1, img) < thresDbell)
281         {
282             ts->set_failed_test_info(ts->FAIL_MISMATCH);
283             break;
284         }
285     }
286
287     cvReleaseCapture( &cap );
288     cvReleaseCapture( &saved );
289
290     ts->printf(ts->LOG, "end test function : ImagesVideo \n");
291 }
292
293 void CV_HighGuiTest::SpecificImageTest(const string& dir)
294 {
295     const size_t IMAGE_COUNT = 10;
296
297     for (size_t i = 0; i < IMAGE_COUNT; ++i)
298     {
299         stringstream s; s << i;
300         string file_path = dir+"../python/images/QCIF_0"+s.str()+".bmp";
301         Mat image = imread(file_path);
302
303         if (image.empty())
304         {
305             ts->set_failed_test_info(ts->FAIL_MISSING_TEST_DATA);
306             return;
307         }
308
309         cv::resize(image, image, cv::Size(968, 757), 0.0, 0.0, cv::INTER_CUBIC);
310
311         stringstream s_digit; s_digit << i;
312
313         string full_name = dir + "img_"+s_digit.str()+".bmp";
314         ts->printf(ts->LOG, " full_name : %s\n", full_name.c_str());
315
316         imwrite(full_name, image);
317
318         Mat loaded = imread(full_name);
319         if (loaded.empty())
320         {
321             ts->printf(ts->LOG, "Reading failed at fmt=bmp\n");
322             ts->set_failed_test_info(ts->FAIL_MISMATCH);
323             continue;
324         }
325
326         const double thresDbell = 20;
327         double psnr = PSNR(loaded, image);
328         if (psnr < thresDbell)
329         {
330             ts->printf(ts->LOG, "Reading image from file: too big difference (=%g) with fmt=bmp\n", psnr);
331             ts->set_failed_test_info(ts->FAIL_BAD_ACCURACY);
332             continue;
333         }
334
335         vector<uchar> from_file;
336
337         FILE *f = fopen(full_name.c_str(), "rb");
338         fseek(f, 0, SEEK_END);
339         long len = ftell(f);
340         from_file.resize((size_t)len);
341         fseek(f, 0, SEEK_SET);
342         from_file.resize(fread(&from_file[0], 1, from_file.size(), f));
343         fclose(f);
344
345         vector<uchar> buf;
346         imencode(".bmp", image, buf);
347
348         if (buf != from_file)
349         {
350             ts->printf(ts->LOG, "Encoding failed with fmt=bmp\n");
351             ts->set_failed_test_info(ts->FAIL_MISMATCH);
352             continue;
353         }
354
355         Mat buf_loaded = imdecode(Mat(buf), 1);
356
357         if (buf_loaded.empty())
358         {
359             ts->printf(ts->LOG, "Decoding failed with fmt=bmp\n");
360             ts->set_failed_test_info(ts->FAIL_MISMATCH);
361             continue;
362         }
363
364         psnr = PSNR(buf_loaded, image);
365
366         if (psnr < thresDbell)
367         {
368             ts->printf(ts->LOG, "Decoding image from memory: too small PSNR (=%gdb) with fmt=bmp\n", psnr);
369             ts->set_failed_test_info(ts->FAIL_MISMATCH);
370             continue;
371         }
372     }
373
374     ts->printf(ts->LOG, "end test function : SpecificImageTest \n");
375     ts->set_failed_test_info(ts->OK);
376 }
377
378 void CV_HighGuiTest::SpecificVideoFileTest(const string& dir, const char codecchars[4])
379 {
380     const string ext[] = {"avi", "mov", "mp4", "mpg", "wmv"};
381
382     const size_t n = sizeof(ext)/sizeof(ext[0]);
383
384     for (size_t j = 0; j < n; ++j) 
385                 if ((ext[j]!="mp4")||(string(&codecchars[0], 4)!="IYUV"))
386         #if defined WIN32 || defined _WIN32
387                 if (((ext[j]!="mov")||(string(&codecchars[0], 4)=="XVID"))&&(ext[j]!="mp4"))
388         #endif
389     {
390         const string video_file = dir + "video_" + string(&codecchars[0], 4) + "." + ext[j];
391
392         VideoWriter writer = cv::VideoWriter(video_file, CV_FOURCC(codecchars[0], codecchars[1], codecchars[2], codecchars[3]), 25, cv::Size(968, 757), true);
393
394                 if (!writer.isOpened())
395                 {
396                         ts->printf(ts->LOG, "Creating a video in %s...\n", video_file.c_str());
397                         ts->printf(ts->LOG, "Cannot create VideoWriter object with codec %s.\n", string(&codecchars[0], 4).c_str());
398                         ts->set_failed_test_info(ts->FAIL_MISMATCH);
399                         continue;
400                 }
401
402         const size_t IMAGE_COUNT = 30;
403
404         for(size_t i = 0; i < IMAGE_COUNT; ++i)
405         {
406             stringstream s_digit;
407             if (i < 10) {s_digit << "0"; s_digit << i;}
408             else s_digit <<  i;
409
410             const string file_path = dir+"../python/images/QCIF_"+s_digit.str()+".bmp";
411
412             cv::Mat img = imread(file_path, CV_LOAD_IMAGE_COLOR);
413
414             if (img.empty())
415             {
416                 ts->printf(ts->LOG, "Creating a video in %s...\n", video_file.c_str());
417                 ts->printf(ts->LOG, "Error: cannot read frame from %s.\n", (ts->get_data_path()+"../python/images/QCIF_"+s_digit.str()+".bmp").c_str());
418                 ts->printf(ts->LOG, "Continue creating the video file...\n");
419                 ts->set_failed_test_info(ts->FAIL_INVALID_TEST_DATA);
420                 continue;
421             }
422
423             cv::resize(img, img, Size(968, 757), 0.0, 0.0, cv::INTER_CUBIC);
424
425             for (int k = 0; k < img.rows; ++k)
426                 for (int l = 0; l < img.cols; ++l)
427                     if (img.at<Vec3b>(k, l) == Vec3b::all(0))
428                         img.at<Vec3b>(k, l) = Vec3b(0, 255, 0);
429             else img.at<Vec3b>(k, l) = Vec3b(0, 0, 255);
430
431             imwrite(dir+"QCIF_"+s_digit.str()+".bmp", img);
432
433             writer << img;
434         }
435
436         writer.~VideoWriter();
437
438         cv::VideoCapture cap(video_file);
439
440         size_t FRAME_COUNT = (size_t)cap.get(CV_CAP_PROP_FRAME_COUNT);
441
442         if (FRAME_COUNT != IMAGE_COUNT)
443         {
444             ts->printf(ts->LOG, "\nFrame count checking for video_%s.%s...\n", string(&codecchars[0], 4).c_str(), ext[j].c_str());
445             ts->printf(ts->LOG, "Video codec: %s\n", string(&codecchars[0], 4).c_str());
446             ts->printf(ts->LOG, "Required frame count: %d; Returned frame count: %d\n", IMAGE_COUNT, FRAME_COUNT);
447             ts->printf(ts->LOG, "Error: Incorrect frame count in the video.\n");
448                         ts->printf(ts->LOG, "Continue checking...\n");
449             ts->set_failed_test_info(ts->FAIL_BAD_ACCURACY);
450         }
451
452         cap.set(CV_CAP_PROP_POS_FRAMES, -1);
453
454                 for (int i = -1; i < (int)std::min<size_t>(FRAME_COUNT, IMAGE_COUNT)-1; i++)
455         {
456             cv::Mat frame; cap >> frame;
457             if (frame.empty())
458             {
459                 ts->printf(ts->LOG, "\nVideo file directory: %s\n", dir.c_str());
460                 ts->printf(ts->LOG, "File name: video_%s.%s\n", string(&codecchars[0], 4).c_str(), ext[i].c_str());
461                 ts->printf(ts->LOG, "Video codec: %s\n", string(&codecchars[0], 4).c_str());
462                                 ts->printf(ts->LOG, "Error: cannot read the next frame with index %d.\n", i+1);
463                 ts->set_failed_test_info(ts->FAIL_MISSING_TEST_DATA);
464                 break;
465             }
466
467             stringstream s_digit;
468             if (i+1 < 10) {s_digit << "0"; s_digit << i+1;}
469             else s_digit << i+1;
470
471             cv::Mat img = imread(dir+"QCIF_"+s_digit.str()+".bmp", CV_LOAD_IMAGE_COLOR);
472
473             if (img.empty())
474             {
475                                 ts->printf(ts->LOG, "\nError: cannot read an image from %s.\n", (dir+"QCIF_"+s_digit.str()+".bmp").c_str());
476                 ts->set_failed_test_info(ts->FAIL_MISMATCH);
477                 continue;
478             }
479
480             const double thresDbell = 20;
481
482             double psnr = PSNR(img, frame);
483
484             if (psnr > thresDbell)
485             {
486                 ts->printf(ts->LOG, "\nReading frame from the file video_%s.%s...\n", string(&codecchars[0], 4).c_str(), ext[j].c_str());
487                                 ts->printf(ts->LOG, "Frame index: %d\n", i+1);
488                 ts->printf(ts->LOG, "Difference between saved and original images: %g\n", psnr);
489                 ts->printf(ts->LOG, "Maximum allowed difference: %g\n", thresDbell);
490                 ts->printf(ts->LOG, "Error: too big difference between saved and original images.\n");
491                 continue;
492             }
493
494         }
495
496         cap.~VideoCapture();
497     }
498 }
499
500 void CV_HighGuiTest::SpecificVideoCameraTest(const string& dir, const char codecchars[4])
501 {
502     const string ext[] = {"avi", "mov", "mp4", "mpg", "wmv"};
503
504     const size_t n = sizeof(ext)/sizeof(ext[0]);
505
506     const int IMAGE_COUNT = 125;
507
508     cv::VideoCapture cap(0);
509
510     if (!cap.isOpened())
511     {
512         ts->printf(ts->LOG, "\nError: cannot start working with device.\n");
513                 ts->set_failed_test_info(ts->OK);
514         return;
515     }
516
517     for (size_t i = 0; i < n; ++i) 
518                 if ((ext[i]!="mp4")||(string(&codecchars[0], 4)!="IYUV"))
519         #if defined WIN32 || defined _WIN32
520                 if (((ext[i]!="mov")||(string(&codecchars[0], 4)=="XVID"))&&(ext[i]!="mp4"))
521         #endif
522     {
523         Mat frame; int framecount = 0;
524         cv::VideoWriter writer;
525
526         std::vector <cv::Mat> tmp_img(IMAGE_COUNT);
527
528         writer.open(dir+"video_"+string(&codecchars[0], 4)+"."+ext[i], CV_FOURCC(codecchars[0], codecchars[1], codecchars[2], codecchars[3]), 25, Size(968, 757), true);
529
530         if (!writer.isOpened())
531         {
532             ts->printf(ts->LOG, "\nVideo file directory: %s\n", dir.c_str());
533             ts->printf(ts->LOG, "Video codec: %s\n", std::string(&codecchars[0], 4).c_str());
534             ts->printf(ts->LOG, "Error: cannot create VideoWriter object for video_%s.%s.\n", string(&codecchars[0]).c_str(), ext[i].c_str());
535             ts->set_failed_test_info(ts->FAIL_EXCEPTION);
536             continue;
537         }
538
539         for (;;)
540         {
541             cap >> frame;
542
543             if (frame.empty())
544             {
545                 ts->printf(ts->LOG, "\nVideo file directory: %s\n", dir.c_str());
546                 ts->printf(ts->LOG, "File name: video_%s.%s\n", string(&codecchars[0], 4).c_str(), ext[i].c_str());
547                 ts->printf(ts->LOG, "Video codec: %s\n", string(&codecchars[0], 4).c_str());
548                                 ts->printf(ts->LOG, "Error: cannot read next frame with index %d from the device.\n", framecount);
549                 break;
550             }
551
552             cv::resize(frame, frame, Size(968, 757), 0, 0, INTER_CUBIC);
553             writer << frame; tmp_img[framecount] = frame;
554
555             framecount++;
556             if (framecount == IMAGE_COUNT) break;
557         }
558
559         frame.~Mat();
560         writer.~VideoWriter();
561
562         cv::VideoCapture vcap(dir+"video_"+string(&codecchars[0], 4)+"."+ext[i]);
563
564         if (!vcap.isOpened())
565         {
566             ts->printf(ts->LOG, "\nVideo file directory: %s\n", dir.c_str());
567             ts->printf(ts->LOG, "File name: video_%s.%s\n",  string(&codecchars[0], 4).c_str(), ext[i].c_str());
568             ts->printf(ts->LOG, "Video codec: %s\n", string(&codecchars[0], 4).c_str());
569             ts->printf(ts->LOG, "Error: cannot open video file.\n");
570             continue;
571         }
572
573         int FRAME_COUNT = (int)vcap.get(CV_CAP_PROP_FRAME_COUNT);
574
575         if (FRAME_COUNT != IMAGE_COUNT)
576         {
577             ts->printf(ts->LOG, "\nChecking frame count...\n");
578             ts->printf(ts->LOG, "Video file directory: %s\n", dir.c_str());
579             ts->printf(ts->LOG, "File name: video_%s.%s\n", string(&codecchars[0], 4).c_str(), ext[i].c_str());
580             ts->printf(ts->LOG, "Video codec: %s\n", string(&codecchars[0], 4).c_str());
581             ts->printf(ts->LOG, "Required frame count: %d  Returned frame count: %d\n", IMAGE_COUNT, FRAME_COUNT);
582             ts->printf(ts->LOG, "Error: required and returned frame count are not matched.\n");
583                         ts->printf(ts->LOG, "Continue checking...\n");
584             ts->set_failed_test_info(ts->FAIL_INVALID_OUTPUT);
585         }
586
587         cv::Mat img; framecount = 0;
588         vcap.set(CV_CAP_PROP_POS_FRAMES, 0);
589
590         for ( ; framecount < std::min<int>(FRAME_COUNT, IMAGE_COUNT); framecount++ )
591         {
592             vcap >> img;
593
594             if (img.empty())
595             {
596                 ts->printf(ts->LOG, "\nVideo file directory: %s\n", dir.c_str());
597                 ts->printf(ts->LOG, "File name: video_%s.%s\n", string(&codecchars[0], 4).c_str(), ext[i].c_str());
598                 ts->printf(ts->LOG, "Video codec: %s\n", string(&codecchars[0], 4).c_str());
599                 ts->printf(ts->LOG, "Error: cannot read frame with index %d from the video.\n", framecount);
600                 break;
601             }
602
603             const double thresDbell = 20;
604             double psnr = PSNR(img, tmp_img[framecount]);
605
606             if (psnr > thresDbell)
607             {
608                 ts->printf(ts->LOG, "\nReading frame from the file video_%s.%s...\n", string(&codecchars[0], 4).c_str(), ext[i].c_str());
609                                 ts->printf(ts->LOG, "Frame index: %d\n", framecount);
610                 ts->printf(ts->LOG, "Difference between saved and original images: %g\n", psnr);
611                 ts->printf(ts->LOG, "Maximum allowed difference: %g\n", thresDbell);
612                 ts->printf(ts->LOG, "Error: too big difference between saved and original images.\n");
613                 continue;
614             }
615         }
616
617         img.~Mat();
618         vcap.~VideoCapture();
619     }
620
621     cap.~VideoCapture();
622 }
623
624 void CV_ImageTest::run(int)
625 {
626     ImageTest(ts->get_data_path());
627 }
628
629 void CV_SpecificImageTest::run(int)
630 {
631     SpecificImageTest(ts->get_data_path());
632 }
633
634 void CV_VideoTest::run(int)
635 {
636 #if defined WIN32 || (defined __linux__ && !defined ANDROID)
637 #if !defined HAVE_GSTREAMER || defined HAVE_GSTREAMER_APP
638
639     const char codecs[][4] = { {'I', 'Y', 'U', 'V'},
640                                {'X', 'V', 'I', 'D'},
641                                {'M', 'P', 'G', '2'},
642                                {'M', 'J', 'P', 'G'} };
643
644     printf("%s", ts->get_data_path().c_str());
645
646     int count = sizeof(codecs)/(4*sizeof(char));
647
648     for (int i = 0; i < count; ++i)
649     {
650         VideoTest(ts->get_data_path(), CV_FOURCC(codecs[i][0], codecs[i][1], codecs[i][2], codecs[i][3]));
651     }
652
653 #endif
654 #endif
655 }
656
657 void CV_SpecificVideoFileTest::run(int)
658 {
659 #if defined WIN32 || (defined __linux__ && !defined ANDROID)
660 #if !defined HAVE_GSTREAMER || defined HAVE_GSTREAMER_APP
661
662     const char codecs[][4] = { {'M', 'P', 'G', '2'},
663                                {'X', 'V', 'I', 'D'},
664                                {'M', 'J', 'P', 'G'},
665                                {'I', 'Y', 'U', 'V'} };
666
667     int count = sizeof(codecs)/(4*sizeof(char));
668
669     for (int i = 0; i < count; ++i)
670     {
671         SpecificVideoFileTest(ts->get_data_path(), codecs[i]);
672     }
673
674 #endif
675 #endif
676 }
677
678 void CV_SpecificVideoCameraTest::run(int)
679 {
680 #if defined WIN32 || (defined __linux__ && !defined ANDROID)
681 #if !defined HAVE_GSTREAMER || defined HAVE_GSTREAMER_APP
682
683     const char codecs[][4] = { {'M', 'P', 'G', '2'},
684                                {'X', 'V', 'I', 'D'},
685                                {'M', 'J', 'P', 'G'},
686                                {'I', 'Y', 'U', 'V'} };
687
688     int count = sizeof(codecs)/(4*sizeof(char));
689
690     for (int i = 0; i < count; ++i)
691     {
692         SpecificVideoCameraTest(ts->get_data_path(), codecs[i]);
693     }
694
695 #endif
696 #endif
697 }
698
699 TEST(Highgui_Image, regression) { CV_ImageTest test; test.safe_run(); }
700 TEST(Highgui_Video, regression) { CV_VideoTest test; test.safe_run(); }
701 TEST(Highgui_SpecificImage, regression) { CV_SpecificImageTest test; test.safe_run(); }
702 TEST(Highgui_SpecificVideoFile, regression) { CV_SpecificVideoFileTest test; test.safe_run(); }
703 TEST(Highgui_SpecificVideoCamera, regression) { CV_SpecificVideoCameraTest test; test.safe_run(); }