1 /*M///////////////////////////////////////////////////////////////////////////////////////
3 // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
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.
11 // For Open Source Computer Vision Library
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.
17 // Redistribution and use in source and binary forms, with or without modification,
18 // are permitted provided that the following conditions are met:
20 // * Redistribution's of source code must retain the above copyright notice,
21 // this list of conditions and the following disclaimer.
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.
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.
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.
43 #include "test_precomp.hpp"
44 #include "opencv2/highgui/highgui.hpp"
50 enum NAVIGATION_METHOD {PROGRESSIVE, RANDOM};
52 class CV_VideoPositioningTest: public cvtest::BaseTest
55 CV_VideoPositioningTest();
56 ~CV_VideoPositioningTest();
57 virtual void run(int) = 0;
61 void run_test(int method);
64 void generate_idx_seq(CvCapture *cap, int method);
67 class CV_VideoProgressivePositioningTest: public CV_VideoPositioningTest
70 CV_VideoProgressivePositioningTest() : CV_VideoPositioningTest() {};
71 ~CV_VideoProgressivePositioningTest();
75 class CV_VideoRandomPositioningTest: public CV_VideoPositioningTest
78 CV_VideoRandomPositioningTest(): CV_VideoPositioningTest() {};
79 ~CV_VideoRandomPositioningTest();
83 CV_VideoPositioningTest::CV_VideoPositioningTest() {}
84 CV_VideoPositioningTest::~CV_VideoPositioningTest() {}
85 CV_VideoProgressivePositioningTest::~CV_VideoProgressivePositioningTest() {}
86 CV_VideoRandomPositioningTest::~CV_VideoRandomPositioningTest() {}
88 void CV_VideoPositioningTest::generate_idx_seq(CvCapture* cap, int method)
91 int N = (int)cvGetCaptureProperty(cap, CV_CAP_PROP_FRAME_COUNT);
96 int pos = 1, step = 20;
109 for( int i = 0; i < N-1; i++ )
110 idx.push_back(rng.uniform(0, N));
112 std::swap(idx.at(rng.uniform(0, N-1)), idx.at(N-1));
119 void CV_VideoPositioningTest::run_test(int method)
121 const string& src_dir = ts->get_data_path();
123 ts->printf(cvtest::TS::LOG, "\n\nSource files directory: %s\n", (src_dir+"video/").c_str());
125 const string ext[] = {"mov", "avi", "mp4", "mpg", "wmv"};
127 size_t n = sizeof(ext)/sizeof(ext[0]);
129 int failed_videos = 0;
131 for (size_t i = 0; i < n; ++i)
133 string file_path = src_dir + "video/big_buck_bunny." + ext[i];
135 printf("\nReading video file in %s...\n", file_path.c_str());
137 CvCapture* cap = cvCreateFileCapture(file_path.c_str());
141 ts->printf(cvtest::TS::LOG, "\nFile information (video %d): \n\nName: big_buck_bunny.%s\nFAILED\n\n", i+1, ext[i].c_str());
142 ts->printf(cvtest::TS::LOG, "Error: cannot read source video file.\n");
143 ts->set_failed_test_info(cvtest::TS::FAIL_INVALID_TEST_DATA);
144 failed_videos++; continue;
147 cvSetCaptureProperty(cap, CV_CAP_PROP_POS_FRAMES, 0);
149 generate_idx_seq(cap, method);
151 int N = idx.size(), failed_frames = 0, failed_positions = 0, failed_iterations = 0;
153 for (int j = 0; j < N; ++j)
157 cvSetCaptureProperty(cap, CV_CAP_PROP_POS_FRAMES, idx.at(j));
159 /* IplImage* frame = cvRetrieveFrame(cap);
165 ts->printf(cvtest::TS::LOG, "\nFile information (video %d): \n\nName: big_buck_bunny.%s\n", i+1, ext[i].c_str());
168 ts->printf(cvtest::TS::LOG, "\nIteration: %d\n\nError: cannot read a frame with index %d.\n", j, idx.at(j));
169 ts->set_failed_test_info(cvtest::TS::FAIL_EXCEPTION);
173 int val = (int)cvGetCaptureProperty(cap, CV_CAP_PROP_POS_FRAMES);
175 if (idx.at(j) != val)
177 if (!(failed_frames||failed_positions))
179 ts->printf(cvtest::TS::LOG, "\nFile information (video %d): \n\nName: big_buck_bunny.%s\n", i+1, ext[i].c_str());
184 ts->printf(cvtest::TS::LOG, "\nIteration: %d\n", j);
186 ts->printf(cvtest::TS::LOG, "Required pos: %d\nReturned pos: %d\n", idx.at(j), val);
187 ts->printf(cvtest::TS::LOG, "Error: required and returned positions are not matched.\n");
188 ts->set_failed_test_info(cvtest::TS::FAIL_INVALID_OUTPUT);
189 if (!flag) flag = !flag;
192 if (flag) failed_iterations++;
195 ts->printf(cvtest::TS::LOG, "\nSuccessfull iterations: %d (%d%%)\n", idx.size()-failed_iterations, 100*(idx.size()-failed_iterations)/idx.size());
196 ts->printf(cvtest::TS::LOG, "Failed iterations: %d (%d%%)\n", failed_iterations, 100*failed_iterations/idx.size());
198 if (failed_frames||failed_positions)
200 ts->printf(cvtest::TS::LOG, "\nFAILED\n----------\n"); failed_videos++;
203 cvReleaseCapture(&cap);
206 ts->printf(cvtest::TS::LOG, "\nSuccessfull experiments: %d (%d%%)\n", n-failed_videos, 100*(n-failed_videos)/n);
207 ts->printf(cvtest::TS::LOG, "Failed experiments: %d (%d%%)\n", failed_videos, 100*failed_videos/n);
210 void CV_VideoProgressivePositioningTest::run(int)
212 #if defined WIN32 || (defined __linux__ && !defined ANDROID)
213 #if !defined HAVE_GSTREAMER || defined HAVE_GSTREAMER_APP
215 run_test(PROGRESSIVE);
221 void CV_VideoRandomPositioningTest::run(int)
223 #if defined WIN32 || (defined __linux__ && !defined ANDROID)
224 #if !defined HAVE_GSTREAMER || defined HAVE_GSTREAMER_APP
232 TEST (HighguiPositioning, progressive) { CV_VideoProgressivePositioningTest test; test.safe_run(); }
233 TEST (HighguiPositioning, random) { CV_VideoRandomPositioningTest test; test.safe_run(); }