Commit 0aa74f38 authored by Alexander Reshetnikov's avatar Alexander Reshetnikov

Updated new video positioning test

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