class CV_PositioningTest : public cvtest::BaseTest\r
{\r
public:\r
- void CreateTestVideo(const string& format, int codec);\r
+ void CreateTestVideo(const string& format, int codec, int framecount = 125);\r
void run(int);\r
};\r
\r
-void CV_PositioningTest::CreateTestVideo(const string& format, int codec)\r
+void CV_PositioningTest::CreateTestVideo(const string& format, int codec, int framecount)\r
{\r
- const size_t frame_count = 2500;\r
-\r
stringstream s; s << codec;\r
\r
- cv::VideoWriter writer(ts->get_data_path()+"video/test_video_"+s.str()+format, codec, 25, cv::Size(640, 480), false);\r
+ cv::VideoWriter writer(ts->get_data_path()+"video/test_video_"+s.str()+"."+format, codec, 25, cv::Size(640, 480), false);\r
\r
- for (size_t i = 0; i < frame_count; ++i)\r
+ for (int i = 0; i < framecount; ++i)\r
{\r
cv::Mat mat(480, 640, CV_8UC1);\r
size_t n = 32, tmp = i;\r
- vector<char> tmp_code; tmp_code.clear();\r
\r
- while ( tmp > 1 )\r
- {\r
- tmp_code.push_back(tmp%2);\r
- tmp /= 2;\r
- }\r
- tmp_code.push_back(1);\r
+ vector<char> tmp_code; tmp_code.clear();\r
\r
- vector<char> i_code(n);\r
- for (size_t j = 0; j < n; ++j)\r
- {\r
- char val = j < n - tmp_code.size() ? 0 : tmp_code.at(j+tmp_code.size()-n);\r
- i_code.push_back(val);\r
- }\r
+ while ( tmp > 1 )\r
+ {\r
+ tmp_code.push_back(tmp%2);\r
+ tmp /= 2;\r
+ }\r
+ tmp_code.push_back(tmp);\r
\r
- const size_t w = 480/n;\r
+ vector<char> i_code;\r
\r
- for (size_t j = 0; j < n; ++j)\r
- {\r
- for (size_t k = w*j; k < w*(j+1); ++k)\r
- mat.row(k) = i_code[j] ? 255*cv::Mat::ones(1, 640, CV_8UC1) : cv::Mat::zeros(1, 640, CV_8UC1);\r
- }\r
+ for (size_t j = 0; j < n; ++j)\r
+ {\r
+ char val = j < n - tmp_code.size() ? 0 : tmp_code.at(n-1-j);\r
+ i_code.push_back(val);\r
+ }\r
\r
- writer << mat;\r
+ const size_t w = 480/n;\r
\r
- //imshow("test image", mat); waitKey();\r
+ for (size_t j = 0; j < n; ++j)\r
+ {\r
+ cv::Scalar color = i_code[j] ? 255 : 0;\r
+ rectangle(mat, Rect(0, w*j, 640, w), color, -1);\r
+ }\r
\r
+ writer << mat;\r
}\r
\r
writer.~VideoWriter();\r
\r
void CV_PositioningTest::run(int)\r
{\r
- const size_t n_codec = sizeof(codec_bmp_tags)/sizeof(codec_bmp_tags[0]);\r
+#if defined WIN32 || (defined __linux__ && !defined ANDROID)\r
+#if !defined HAVE_GSTREAMER || defined HAVE_GSTREAMER_APP\r
\r
- const string format[] = {"avi", "mov", "mp4", "mpg", "wmv"};\r
- const size_t n_format = sizeof(format)/sizeof(format[0]);\r
+ const string format[] = {"avi", "mov", "mp4", "mpg", "wmv", "3gp"};\r
+\r
+ const char codec[][4] = { {'X', 'V', 'I', 'D'},\r
+ {'M', 'P', 'G', '2'},\r
+ {'M', 'J', 'P', 'G'} };\r
+\r
+ size_t n_format = sizeof(format)/sizeof(format[0]),\r
+ n_codec = sizeof(codec)/sizeof(codec[0]);\r
\r
for (size_t i = 0; i < n_format; ++i)\r
for (size_t j = 0; j < n_codec; ++j)\r
{\r
- CreateTestVideo(format[i], codec_bmp_tags[j].tag);\r
-\r
- stringstream s; s << codec_bmp_tags[j].tag;\r
- \r
- cv::VideoCapture cap(ts->get_data_path()+"video/test_video_"+s.str()+format[i]);\r
- cap.set(CV_CAP_PROP_POS_FRAMES, 0.0);\r
-\r
- int N = cap.get(CV_CAP_PROP_FRAME_COUNT);\r
-\r
- vector <int> idx;\r
-\r
- RNG rng(N);\r
- idx.clear();\r
- for( int i = 0; i < N-1; i++ )\r
- idx.push_back(rng.uniform(0, N));\r
- idx.push_back(N-1);\r
- swap(idx.at(rng.uniform(0, N-1)), idx.at(N-1));\r
-\r
- for (int i = 0; i < N; ++i)\r
- {\r
- cap.set(CV_CAP_PROP_POS_FRAMES, (double)idx[i]);\r
-\r
- cv::Mat img; cap.retrieve(img);\r
-\r
- const double thresh = 128.0;\r
-\r
- const size_t n = 32, w = img.rows/n;\r
-\r
- int index = 0, deg = n-1;\r
-\r
- for (size_t j = 0; j < n; ++j)\r
- {\r
- cv::Mat mat = img.rowRange(w*j, w*(j+1)-1);\r
- Scalar mat_mean = cv::mean(mat);\r
- if (mat_mean[0] > thresh)\r
- {\r
- index += (2<<deg);\r
- }\r
-\r
- deg--;\r
- }\r
-\r
- if (index != idx[i])\r
- {\r
- ts->printf(ts->LOG, "Required position: %d Returned position: %d\n FAILED", idx[i], index);\r
- }\r
- }\r
+ CreateTestVideo(format[i], CV_FOURCC(codec[j][0], codec[j][1], codec[j][2], codec[j][3]), 125);\r
+\r
+ stringstream s; s << CV_FOURCC(codec[j][0], codec[j][1], codec[j][2], codec[j][3]); //codec_bmp_tags[j].tag;\r
+\r
+ const string file_path = ts->get_data_path()+"video/test_video_"+s.str()+"."+format[i];\r
+\r
+ bool error = false; int failed = 0;\r
+\r
+ cv::VideoCapture cap(file_path);\r
+\r
+ if (!cap.isOpened())\r
+ {\r
+ ts->printf(ts->LOG, "\nFile: %s\n", file_path.c_str());\r
+ ts->printf(ts->LOG, "\nVideo codec: %s\n", string(&codec[j][0], 4).c_str());\r
+ ts->printf(ts->LOG, "\nError: cannot read video file.\n");\r
+ ts->set_failed_test_info(ts->FAIL_INVALID_TEST_DATA);\r
+ error = true;\r
+ }\r
+\r
+ cap.set(CV_CAP_PROP_POS_FRAMES, 0);\r
+\r
+ int N = cap.get(CV_CAP_PROP_FRAME_COUNT);\r
+\r
+ if (N != 125)\r
+ {\r
+ if (!error)\r
+ {\r
+ ts->printf(ts->LOG, "\nFile: %s\n", file_path.c_str());\r
+ ts->printf(ts->LOG, "\nVideo codec: %s\n", string(&codec[j][0], 4).c_str());\r
+ error = true;\r
+ }\r
+ ts->printf(ts->LOG, "\nError: returned frame count in clip is incorrect.\n");\r
+ ts->set_failed_test_info(ts->FAIL_INVALID_OUTPUT);\r
+ }\r
+\r
+ vector <int> idx;\r
+\r
+ RNG rng(N);\r
+ idx.clear();\r
+ for( int k = 0; k < N-1; k++ )\r
+ idx.push_back(rng.uniform(0, N));\r
+ idx.push_back(N-1);\r
+ std::swap(idx.at(rng.uniform(0, N-1)), idx.at(N-1));\r
+\r
+ for (int k = 0; k < N; ++k)\r
+ {\r
+ cap.set(CV_CAP_PROP_POS_FRAMES, (double)idx[k]);\r
+\r
+ cv::Mat img; cap.retrieve(img);\r
+\r
+ if (img.empty())\r
+ {\r
+ if (!error)\r
+ {\r
+ ts->printf(ts->LOG, "\nFile: %s\n", file_path.c_str());\r
+ ts->printf(ts->LOG, "\nVideo codec: %s\n", string(&codec[j][0], 4).c_str());\r
+ error = true;\r
+ }\r
+ ts->printf(ts->LOG, "\nError: cannot read a frame in position %d.\n", idx[k]);\r
+ ts->set_failed_test_info(ts->FAIL_EXCEPTION);\r
+ }\r
+\r
+ const double thresh = 100;\r
+\r
+ const size_t n = 32, w = img.rows/n;\r
+\r
+ int index = 0, deg = n-1;\r
+\r
+ for (size_t l = 0; l < n; ++l)\r
+ {\r
+ cv::Mat mat = img.rowRange(w*l, w*(l+1)-1);\r
+\r
+ Scalar mat_mean = cv::mean(mat);\r
+\r
+ if (mat_mean[0] > thresh) index += (int)std::pow(2.0, 1.0*deg);\r
+\r
+ deg--;\r
+ }\r
+\r
+ if (index != idx[k])\r
+ {\r
+ if (!error)\r
+ {\r
+ ts->printf(ts->LOG, "\nFile: %s\n", file_path.c_str());\r
+ ts->printf(ts->LOG, "\nVideo codec: %s\n\n", string(&codec[j][0], 4).c_str());\r
+ error = true;\r
+ }\r
+ ts->printf(ts->LOG, "Required position: %d Returned position: %d FAILED\n", idx[k], index);\r
+ ts->set_failed_test_info(ts->FAIL_INVALID_OUTPUT);\r
+ failed++;\r
+ }\r
+ }\r
+\r
+ if (!error) ts->printf(ts->LOG, "\nFile: %s\n", file_path.c_str());\r
+\r
+ ts->printf(ts->LOG, "\nSuccessfull iterations: %d(%d%%) Failed iterations: %d(%d%%)\n", N-failed, (N-failed)*100/N, failed, failed*100/N);\r
+ ts->printf(ts->LOG, "\n----------\n");\r
}\r
+\r
+#endif\r
+#endif\r
}\r
\r
TEST(Highgui_Positioning, regression) { CV_PositioningTest test; test.safe_run(); }\r