9afc1ade8aa262d29cce3f61148ef17d44a645c4
[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     int counter = 0;
234     for(;;)
235     {
236         IplImage * img = cvQueryFrame( cap );
237
238         if (!img)
239             break;
240
241         if (writer == 0)
242         {
243             writer = cvCreateVideoWriter(tmp_name.c_str(), fourcc, 24, cvGetSize(img));
244             if (writer == 0)
245             {
246                 ts->printf(ts->LOG, "can't create writer (with fourcc : %d)\n", fourcc);
247                 cvReleaseCapture( &cap );
248                 ts->set_failed_test_info(ts->FAIL_MISMATCH);
249                 return;
250             }
251         }
252
253         cvWriteFrame(writer, img);
254     }
255
256     cvReleaseVideoWriter( &writer );
257     cvReleaseCapture( &cap );
258
259     cap = cvCaptureFromFile(src_file.c_str());
260
261     CvCapture *saved = cvCaptureFromFile(tmp_name.c_str());
262     if (!saved)
263     {
264         ts->set_failed_test_info(ts->FAIL_MISMATCH);
265         return;
266     }
267
268     const double thresDbell = 20;
269
270     counter = 0;
271     for(;;)
272     {
273         IplImage* ipl  = cvQueryFrame( cap );
274         IplImage* ipl1 = cvQueryFrame( saved );
275
276         if (!ipl || !ipl1)
277             break;
278
279         Mat img(ipl);
280         Mat img1(ipl1);
281
282         if (PSNR(img1, img) < thresDbell)
283         {
284             ts->set_failed_test_info(ts->FAIL_MISMATCH);
285             break;
286         }
287     }
288
289     cvReleaseCapture( &cap );
290     cvReleaseCapture( &saved );
291
292     ts->printf(ts->LOG, "end test function : ImagesVideo \n");
293 }
294
295 void CV_HighGuiTest::SpecificImageTest(const string& dir)
296 {
297     const size_t IMAGE_COUNT = 10;
298
299     for (size_t i = 0; i < IMAGE_COUNT; ++i)
300     {
301         stringstream s; s << i;
302         string file_path = dir+"../python/images/QCIF_0"+s.str()+".bmp";
303         Mat image = imread(file_path);
304
305         if (image.empty())
306         {
307             ts->set_failed_test_info(ts->FAIL_MISSING_TEST_DATA);
308             return;
309         }
310
311         cv::resize(image, image, cv::Size(968, 757), 0.0, 0.0, cv::INTER_CUBIC);
312
313         stringstream s_digit; s_digit << i;
314
315         string full_name = dir + "img_"+s_digit.str()+".bmp";
316         ts->printf(ts->LOG, " full_name : %s\n", full_name.c_str());
317
318         imwrite(full_name, image);
319
320         Mat loaded = imread(full_name);
321         if (loaded.empty())
322         {
323             ts->printf(ts->LOG, "Reading failed at fmt=bmp\n");
324             ts->set_failed_test_info(ts->FAIL_MISMATCH);
325             continue;
326         }
327
328         const double thresDbell = 20;
329         double psnr = PSNR(loaded, image);
330         if (psnr < thresDbell)
331         {
332             ts->printf(ts->LOG, "Reading image from file: too big difference (=%g) with fmt=bmp\n", psnr);
333             ts->set_failed_test_info(ts->FAIL_BAD_ACCURACY);
334             continue;
335         }
336
337         vector<uchar> from_file;
338
339         FILE *f = fopen(full_name.c_str(), "rb");
340         fseek(f, 0, SEEK_END);
341         long len = ftell(f);
342         from_file.resize((size_t)len);
343         fseek(f, 0, SEEK_SET);
344         from_file.resize(fread(&from_file[0], 1, from_file.size(), f));
345         fclose(f);
346
347         vector<uchar> buf;
348         imencode(".bmp", image, buf);
349
350         if (buf != from_file)
351         {
352             ts->printf(ts->LOG, "Encoding failed with fmt=bmp\n");
353             ts->set_failed_test_info(ts->FAIL_MISMATCH);
354             continue;
355         }
356
357         Mat buf_loaded = imdecode(Mat(buf), 1);
358
359         if (buf_loaded.empty())
360         {
361             ts->printf(ts->LOG, "Decoding failed with fmt=bmp\n");
362             ts->set_failed_test_info(ts->FAIL_MISMATCH);
363             continue;
364         }
365
366         psnr = PSNR(buf_loaded, image);
367
368         if (psnr < thresDbell)
369         {
370             ts->printf(ts->LOG, "Decoding image from memory: too small PSNR (=%gdb) with fmt=bmp\n", psnr);
371             ts->set_failed_test_info(ts->FAIL_MISMATCH);
372             continue;
373         }
374     }
375
376     ts->printf(ts->LOG, "end test function : SpecificImageTest \n");
377     ts->set_failed_test_info(ts->OK);
378 }
379
380 void CV_HighGuiTest::SpecificVideoFileTest(const string& dir, const char codecchars[4])
381 {
382     const string ext[] = {"avi", "mov", "mp4"/*, "mpg", "wmv"*/};
383
384     const size_t n = sizeof(ext)/sizeof(ext[0]);
385
386     for (size_t j = 0; j < n; ++j) if ((ext[j]!="mp4")||(string(&codecchars[0], 4)!="IYUV"))
387     {
388         const string video_file = dir + "video_" + string(&codecchars[0], 4) + "." + ext[j];
389
390         VideoWriter writer;
391
392         const size_t IMAGE_COUNT = 30;
393
394         for(size_t i = 0; i < IMAGE_COUNT; ++i)
395         {
396             stringstream s_digit;
397             if (i < 10) {s_digit << "0"; s_digit << i;}
398             else s_digit <<  i;
399
400             const string file_path = dir+"../python/images/QCIF_"+s_digit.str()+".bmp";
401
402             cv::Mat img = imread(file_path, CV_LOAD_IMAGE_COLOR);
403
404             if (img.empty())
405             {
406                 ts->printf(ts->LOG, "Creating a video in %s...\n", video_file.c_str());
407                 ts->printf(ts->LOG, "Error: cannot read frame from %s.\n", (ts->get_data_path()+"../python/images/QCIF_"+s_digit.str()+".bmp").c_str());
408                 ts->printf(ts->LOG, "Continue creating the video file...\n");
409                 ts->set_failed_test_info(ts->FAIL_INVALID_TEST_DATA);
410                 continue;
411             }
412
413             cv::resize(img, img, Size(968, 757), 0.0, 0.0, cv::INTER_CUBIC);
414
415             for (int k = 0; k < img.rows; ++k)
416                 for (int l = 0; l < img.cols; ++l)
417                     if (img.at<Vec3b>(k, l) == Vec3b::all(0))
418                         img.at<Vec3b>(k, l) = Vec3b(0, 255, 0);
419             else img.at<Vec3b>(k, l) = Vec3b(0, 0, 255);
420
421             imwrite(dir+"QCIF_"+s_digit.str()+".bmp", img);
422
423             if (!writer.isOpened())
424             {
425                 writer = cv::VideoWriter(video_file, CV_FOURCC(codecchars[0], codecchars[1], codecchars[2], codecchars[3]), 25, cv::Size(img.cols, img.rows), true);
426
427                 if (!writer.isOpened())
428                 {
429                     ts->printf(ts->LOG, "Creating a video in %s...\n", video_file.c_str());
430                     ts->printf(ts->LOG, "Cannot create VideoWriter with codec %s.\n", string(&codecchars[0], 4).c_str());
431                     ts->set_failed_test_info(ts->FAIL_MISMATCH);
432                     return;
433                 }
434             }
435
436             writer << img;
437         }
438
439         writer.~VideoWriter();
440
441         cv::VideoCapture cap(video_file);
442
443         size_t FRAME_COUNT = (size_t)cap.get(CV_CAP_PROP_FRAME_COUNT);
444
445         if (FRAME_COUNT != IMAGE_COUNT)
446         {
447             ts->printf(ts->LOG, "\nFrame count checking for video_%s.%s...\n", string(&codecchars[0], 4).c_str(), ext[j].c_str());
448             ts->printf(ts->LOG, "Video codec: %s\n", string(&codecchars[0], 4).c_str());
449             ts->printf(ts->LOG, "Required frame count: %d; Returned frame count: %d\n", IMAGE_COUNT, FRAME_COUNT);
450             ts->printf(ts->LOG, "Error: Incorrect frame count in the video.\n");
451             ts->set_failed_test_info(ts->FAIL_BAD_ACCURACY);
452             continue;
453         }
454
455         cap.set(CV_CAP_PROP_POS_FRAMES, -1);
456
457         for (size_t i = -1; i < FRAME_COUNT-1; i++)
458         {
459             cv::Mat frame; cap >> frame;
460             if (frame.empty())
461             {
462                 ts->printf(ts->LOG, "\nError: 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 < 10) {s_digit << "0"; s_digit << i;}
469             else s_digit <<  i;
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 with index %d.\n", i+1);
476                 ts->set_failed_test_info(ts->FAIL_MISMATCH);
477                 break;
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, "Difference between saved and original images: %g\n", psnr);
488                 ts->printf(ts->LOG, "Maximum allowed difference: %g", thresDbell);
489                 ts->printf(ts->LOG, "Error: too big difference between saved and original images.\n");
490                 continue;
491             }
492
493         }
494
495         cap.~VideoCapture();
496     }
497 }
498
499 void CV_HighGuiTest::SpecificVideoCameraTest(const string& dir, const char codecchars[4])
500 {
501     const string ext[] = {"avi", "mov", "mp4"/*, "mpg", "wmv"*/};
502
503     const size_t n = sizeof(ext)/sizeof(ext[0]);
504
505     const int IMAGE_COUNT = 125;
506
507     cv::VideoCapture cap(0);
508
509     if (!cap.isOpened())
510     {
511         ts->printf(ts->LOG, "\nError: cannot start working with device.\n");
512         ts->set_failed_test_info(ts->FAIL_EXCEPTION);
513         return;
514     }
515
516     for (size_t i = 0; i < n; ++i) if ((ext[i]!="mp4")||(string(&codecchars[0], 4)!="IYUV"))
517     {
518         Mat frame; int framecount = 0;
519         cv::VideoWriter writer;
520
521         std::vector <cv::Mat> tmp_img(IMAGE_COUNT);
522
523         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);
524
525         if (!writer.isOpened())
526         {
527             ts->printf(ts->LOG, "\nVideo file directory: %s\n", dir.c_str());
528             ts->printf(ts->LOG, "Video codec: %s\n", std::string(&codecchars[0], 4).c_str());
529             ts->printf(ts->LOG, "Error: cannot create VideoWriter object for video_%s.%s.\n", string(&codecchars[0]).c_str(), ext[i].c_str());
530             ts->set_failed_test_info(ts->FAIL_EXCEPTION);
531             continue;
532         }
533
534         for (;;)
535         {
536             cap >> frame;
537
538             if (frame.empty())
539             {
540                 ts->printf(ts->LOG, "\nVideo file directory: %s\n", dir.c_str());
541                 ts->printf(ts->LOG, "File name: video_%s.%s\n", string(&codecchars[0], 4).c_str(), ext[i].c_str());
542                 ts->printf(ts->LOG, "Video codec: %s\n", string(&codecchars[0], 4).c_str());
543                 ts->printf(ts->LOG, "Frame index: %d\n", framecount);
544                 ts->printf(ts->LOG, "Error: cannot read next frame from the device.\n");
545                 break;
546             }
547
548             cv::resize(frame, frame, Size(968, 757), 0, 0, INTER_CUBIC);
549             writer << frame; tmp_img[framecount] = frame;
550
551             framecount++;
552             if (framecount == IMAGE_COUNT) break;
553         }
554
555         frame.~Mat();
556         writer.~VideoWriter();
557
558         cv::VideoCapture vcap(dir+"video_"+string(&codecchars[0], 4)+"."+ext[i]);
559
560         if (!vcap.isOpened())
561         {
562             ts->printf(ts->LOG, "\nVideo file directory: %s\n", dir.c_str());
563             ts->printf(ts->LOG, "File name: video_%s.%s\n",  string(&codecchars[0], 4).c_str(), ext[i].c_str());
564             ts->printf(ts->LOG, "Video codec: %s\n", string(&codecchars[0], 4).c_str());
565             ts->printf(ts->LOG, "Error: cannot open video file.\n");
566             continue;
567         }
568
569         int FRAME_COUNT = (int)vcap.get(CV_CAP_PROP_FRAME_COUNT);
570
571         if (FRAME_COUNT != IMAGE_COUNT)
572         {
573             ts->printf(ts->LOG, "\nChecking frame count...\n");
574             ts->printf(ts->LOG, "Video file directory: %s\n", dir.c_str());
575             ts->printf(ts->LOG, "File name: video_%s.%s\n", string(&codecchars[0], 4).c_str(), ext[i].c_str());
576             ts->printf(ts->LOG, "Video codec: %s\n", string(&codecchars[0], 4).c_str());
577             ts->printf(ts->LOG, "Required frame count: %d  Returned frame count: %d\n", IMAGE_COUNT, FRAME_COUNT);
578             ts->printf(ts->LOG, "Error: required and returned frame count are not matched.\n");
579             ts->set_failed_test_info(ts->FAIL_INVALID_OUTPUT);
580             continue;
581         }
582
583         cv::Mat img; framecount = 0;
584         vcap.set(CV_CAP_PROP_POS_FRAMES, 0);
585
586         for ( ; framecount <= std::min<int>(FRAME_COUNT, IMAGE_COUNT); framecount++ )
587         {
588             vcap >> img;
589
590             if (img.empty())
591             {
592                 ts->printf(ts->LOG, "\nVideo file directory: %s\n", dir.c_str());
593                 ts->printf(ts->LOG, "File name: video_%s.%s\n", string(&codecchars[0], 4).c_str(), ext[i].c_str());
594                 ts->printf(ts->LOG, "Video codec: %s\n", string(&codecchars[0], 4).c_str());
595                 ts->printf(ts->LOG, "Frame index: %d\n", framecount);
596                 ts->printf(ts->LOG, "Error: cannot read next frame from the video.\n");
597                 break;
598             }
599
600             const double thresDbell = 20;
601             double psnr = PSNR(img, tmp_img[framecount]);
602
603             if (psnr > thresDbell)
604             {
605                 ts->printf(ts->LOG, "\nReading frame from the file video_%s.%s...\n", string(&codecchars[0], 4).c_str(), ext[i].c_str());
606                 ts->printf(ts->LOG, "Difference between saved and original images: %g\n", psnr);
607                 ts->printf(ts->LOG, "Maximum allowed difference: %g", thresDbell);
608                 ts->printf(ts->LOG, "Error: too big difference between saved and original images.\n");
609                 continue;
610             }
611         }
612
613         img.~Mat();
614         vcap.~VideoCapture();
615     }
616
617     cap.~VideoCapture();
618 }
619
620 void CV_ImageTest::run(int)
621 {
622     ImageTest(ts->get_data_path());
623 }
624
625 void CV_SpecificImageTest::run(int)
626 {
627     SpecificImageTest(ts->get_data_path());
628 }
629
630 void CV_VideoTest::run(int)
631 {
632 #if defined WIN32 || (defined __linux__ && !defined ANDROID)
633 #if !defined HAVE_GSTREAMER || defined HAVE_GSTREAMER_APP
634
635     const char codecs[][4] = { {'I', 'Y', 'U', 'V'},
636                                {'X', 'V', 'I', 'D'},
637                                {'M', 'P', 'G', '2'},
638                                {'M', 'J', 'P', 'G'} };
639
640     printf("%s", ts->get_data_path().c_str());
641
642     int count = sizeof(codecs)/(4*sizeof(char));
643
644     for (int i = 0; i < count; ++i)
645     {
646         VideoTest(ts->get_data_path(), CV_FOURCC(codecs[i][0], codecs[i][1], codecs[i][2], codecs[i][3]));
647     }
648
649 #endif
650 #endif
651 }
652
653 void CV_SpecificVideoFileTest::run(int)
654 {
655 #if defined WIN32 || (defined __linux__ && !defined ANDROID)
656 #if !defined HAVE_GSTREAMER || defined HAVE_GSTREAMER_APP
657
658     const char codecs[][4] = { {'M', 'P', 'G', '2'},
659                                {'X', 'V', 'I', 'D'},
660                                {'M', 'J', 'P', 'G'},
661                                {'I', 'Y', 'U', 'V'} };
662
663     int count = sizeof(codecs)/(4*sizeof(char));
664
665     for (int i = 0; i < count; ++i)
666     {
667         SpecificVideoFileTest(ts->get_data_path(), codecs[i]);
668     }
669
670 #endif
671 #endif
672 }
673
674 void CV_SpecificVideoCameraTest::run(int)
675 {
676 #if defined WIN32 || (defined __linux__ && !defined ANDROID)
677 #if !defined HAVE_GSTREAMER || defined HAVE_GSTREAMER_APP
678
679     const char codecs[][4] = { {'M', 'P', 'G', '2'},
680                                {'X', 'V', 'I', 'D'},
681                                {'M', 'J', 'P', 'G'},
682                                {'I', 'Y', 'U', 'V'} };
683
684     int count = sizeof(codecs)/(4*sizeof(char));
685
686     for (int i = 0; i < count; ++i)
687     {
688         SpecificVideoCameraTest(ts->get_data_path(), codecs[i]);
689     }
690
691 #endif
692 #endif
693 }
694
695 TEST(Highgui_Image, regression) { CV_ImageTest test; test.safe_run(); }
696 TEST(Highgui_Video, regression) { CV_VideoTest test; test.safe_run(); }
697 TEST(Highgui_SpecificImage, regression) { CV_SpecificImageTest test; test.safe_run(); }
698 TEST(Highgui_SpecificVideoFile, regression) { CV_SpecificVideoFileTest test; test.safe_run(); }
699 TEST(Highgui_SpecificVideoCamera, regression) { CV_SpecificVideoCameraTest test; test.safe_run(); }