From 7c43daccbaad9fa533ec3b4aa3b725991a95c551 Mon Sep 17 00:00:00 2001 From: Vladislav Vinogradov Date: Wed, 27 Nov 2013 17:32:00 +0400 Subject: [PATCH] fixed perf tests for bgfg segmentation --- modules/gpu/perf/perf_video.cpp | 248 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 232 insertions(+), 16 deletions(-) diff --git a/modules/gpu/perf/perf_video.cpp b/modules/gpu/perf/perf_video.cpp index 9894f7f..85a8257 100644 --- a/modules/gpu/perf/perf_video.cpp +++ b/modules/gpu/perf/perf_video.cpp @@ -544,6 +544,8 @@ DEF_PARAM_TEST_1(Video, string); PERF_TEST_P(Video, Video_FGDStatModel, Values(string("gpu/video/768x576.avi"))) { + const int numIters = 10; + declare.time(60); const string inputFile = perf::TestBase::getDataPath(GetParam()); @@ -562,18 +564,36 @@ PERF_TEST_P(Video, Video_FGDStatModel, cv::gpu::FGDStatModel d_model(4); d_model.create(d_frame); - for (int i = 0; i < 10; ++i) + int i = 0; + + // collect performance data + for (; i < numIters; ++i) { cap >> frame; ASSERT_FALSE(frame.empty()); d_frame.upload(frame); - startTimer(); next(); + startTimer(); + if(!next()) + break; + d_model.update(d_frame); + stopTimer(); } + // process last frame in sequence to get data for sanity test + for (; i < numIters; ++i) + { + cap >> frame; + ASSERT_FALSE(frame.empty()); + + d_frame.upload(frame); + + d_model.update(d_frame); + } + const cv::gpu::GpuMat background = d_model.background; const cv::gpu::GpuMat foreground = d_model.foreground; @@ -585,18 +605,36 @@ PERF_TEST_P(Video, Video_FGDStatModel, IplImage ipl_frame = frame; cv::Ptr model(cvCreateFGDStatModel(&ipl_frame)); - for (int i = 0; i < 10; ++i) + int i = 0; + + // collect performance data + for (; i < numIters; ++i) { cap >> frame; ASSERT_FALSE(frame.empty()); ipl_frame = frame; - startTimer(); next(); + startTimer(); + if(!next()) + break; + cvUpdateBGStatModel(&ipl_frame, model); + stopTimer(); } + // process last frame in sequence to get data for sanity test + for (; i < numIters; ++i) + { + cap >> frame; + ASSERT_FALSE(frame.empty()); + + ipl_frame = frame; + + cvUpdateBGStatModel(&ipl_frame, model); + } + const cv::Mat background = model->background; const cv::Mat foreground = model->foreground; @@ -619,6 +657,8 @@ PERF_TEST_P(Video_Cn_LearningRate, Video_MOG, GPU_CHANNELS_1_3_4, Values(0.0, 0.01))) { + const int numIters = 10; + const string inputFile = perf::TestBase::getDataPath(GET_PARAM(0)); const int cn = GET_PARAM(1); const float learningRate = static_cast(GET_PARAM(2)); @@ -649,7 +689,10 @@ PERF_TEST_P(Video_Cn_LearningRate, Video_MOG, d_mog(d_frame, foreground, learningRate); - for (int i = 0; i < 10; ++i) + int i = 0; + + // collect performance data + for (; i < numIters; ++i) { cap >> frame; ASSERT_FALSE(frame.empty()); @@ -666,11 +709,36 @@ PERF_TEST_P(Video_Cn_LearningRate, Video_MOG, d_frame.upload(frame); - startTimer(); next(); + startTimer(); + if(!next()) + break; + d_mog(d_frame, foreground, learningRate); + stopTimer(); } + // process last frame in sequence to get data for sanity test + for (; i < numIters; ++i) + { + cap >> frame; + ASSERT_FALSE(frame.empty()); + + if (cn != 3) + { + cv::Mat temp; + if (cn == 1) + cv::cvtColor(frame, temp, cv::COLOR_BGR2GRAY); + else + cv::cvtColor(frame, temp, cv::COLOR_BGR2BGRA); + cv::swap(temp, frame); + } + + d_frame.upload(frame); + + d_mog(d_frame, foreground, learningRate); + } + GPU_SANITY_CHECK(foreground); } else @@ -680,7 +748,10 @@ PERF_TEST_P(Video_Cn_LearningRate, Video_MOG, mog(frame, foreground, learningRate); - for (int i = 0; i < 10; ++i) + int i = 0; + + // collect performance data + for (; i < numIters; ++i) { cap >> frame; ASSERT_FALSE(frame.empty()); @@ -695,11 +766,34 @@ PERF_TEST_P(Video_Cn_LearningRate, Video_MOG, cv::swap(temp, frame); } - startTimer(); next(); + startTimer(); + if(!next()) + break; + mog(frame, foreground, learningRate); + stopTimer(); } + // process last frame in sequence to get data for sanity test + for (; i < numIters; ++i) + { + cap >> frame; + ASSERT_FALSE(frame.empty()); + + if (cn != 3) + { + cv::Mat temp; + if (cn == 1) + cv::cvtColor(frame, temp, cv::COLOR_BGR2GRAY); + else + cv::cvtColor(frame, temp, cv::COLOR_BGR2BGRA); + cv::swap(temp, frame); + } + + mog(frame, foreground, learningRate); + } + CPU_SANITY_CHECK(foreground); } } @@ -717,6 +811,8 @@ PERF_TEST_P(Video_Cn, Video_MOG2, Combine(Values("gpu/video/768x576.avi", "gpu/video/1920x1080.avi"), GPU_CHANNELS_1_3_4)) { + const int numIters = 10; + const string inputFile = perf::TestBase::getDataPath(GET_PARAM(0)); const int cn = GET_PARAM(1); @@ -748,7 +844,10 @@ PERF_TEST_P(Video_Cn, Video_MOG2, d_mog2(d_frame, foreground); - for (int i = 0; i < 10; ++i) + int i = 0; + + // collect performance data + for (; i < numIters; ++i) { cap >> frame; ASSERT_FALSE(frame.empty()); @@ -765,11 +864,36 @@ PERF_TEST_P(Video_Cn, Video_MOG2, d_frame.upload(frame); - startTimer(); next(); + startTimer(); + if(!next()) + break; + d_mog2(d_frame, foreground); + stopTimer(); } + // process last frame in sequence to get data for sanity test + for (; i < numIters; ++i) + { + cap >> frame; + ASSERT_FALSE(frame.empty()); + + if (cn != 3) + { + cv::Mat temp; + if (cn == 1) + cv::cvtColor(frame, temp, cv::COLOR_BGR2GRAY); + else + cv::cvtColor(frame, temp, cv::COLOR_BGR2BGRA); + cv::swap(temp, frame); + } + + d_frame.upload(frame); + + d_mog2(d_frame, foreground); + } + GPU_SANITY_CHECK(foreground); } else @@ -781,7 +905,10 @@ PERF_TEST_P(Video_Cn, Video_MOG2, mog2(frame, foreground); - for (int i = 0; i < 10; ++i) + int i = 0; + + // collect performance data + for (; i < numIters; ++i) { cap >> frame; ASSERT_FALSE(frame.empty()); @@ -796,11 +923,34 @@ PERF_TEST_P(Video_Cn, Video_MOG2, cv::swap(temp, frame); } - startTimer(); next(); + startTimer(); + if(!next()) + break; + mog2(frame, foreground); + stopTimer(); } + // process last frame in sequence to get data for sanity test + for (; i < numIters; ++i) + { + cap >> frame; + ASSERT_FALSE(frame.empty()); + + if (cn != 3) + { + cv::Mat temp; + if (cn == 1) + cv::cvtColor(frame, temp, cv::COLOR_BGR2GRAY); + else + cv::cvtColor(frame, temp, cv::COLOR_BGR2BGRA); + cv::swap(temp, frame); + } + + mog2(frame, foreground); + } + CPU_SANITY_CHECK(foreground); } } @@ -901,6 +1051,8 @@ PERF_TEST_P(Video_Cn_MaxFeatures, Video_GMG, GPU_CHANNELS_1_3_4, Values(20, 40, 60))) { + const int numIters = 150; + const std::string inputFile = perf::TestBase::getDataPath(GET_PARAM(0)); const int cn = GET_PARAM(1); const int maxFeatures = GET_PARAM(2); @@ -932,7 +1084,10 @@ PERF_TEST_P(Video_Cn_MaxFeatures, Video_GMG, d_gmg(d_frame, foreground); - for (int i = 0; i < 150; ++i) + int i = 0; + + // collect performance data + for (; i < numIters; ++i) { cap >> frame; if (frame.empty()) @@ -954,11 +1109,41 @@ PERF_TEST_P(Video_Cn_MaxFeatures, Video_GMG, d_frame.upload(frame); - startTimer(); next(); + startTimer(); + if(!next()) + break; + d_gmg(d_frame, foreground); + stopTimer(); } + // process last frame in sequence to get data for sanity test + for (; i < numIters; ++i) + { + cap >> frame; + if (frame.empty()) + { + cap.release(); + cap.open(inputFile); + cap >> frame; + } + + if (cn != 3) + { + cv::Mat temp; + if (cn == 1) + cv::cvtColor(frame, temp, cv::COLOR_BGR2GRAY); + else + cv::cvtColor(frame, temp, cv::COLOR_BGR2BGRA); + cv::swap(temp, frame); + } + + d_frame.upload(frame); + + d_gmg(d_frame, foreground); + } + GPU_SANITY_CHECK(foreground); } else @@ -972,7 +1157,10 @@ PERF_TEST_P(Video_Cn_MaxFeatures, Video_GMG, gmg(frame, foreground); - for (int i = 0; i < 150; ++i) + int i = 0; + + // collect performance data + for (; i < numIters; ++i) { cap >> frame; if (frame.empty()) @@ -992,11 +1180,39 @@ PERF_TEST_P(Video_Cn_MaxFeatures, Video_GMG, cv::swap(temp, frame); } - startTimer(); next(); + startTimer(); + if(!next()) + break; + gmg(frame, foreground); + stopTimer(); } + // process last frame in sequence to get data for sanity test + for (; i < numIters; ++i) + { + cap >> frame; + if (frame.empty()) + { + cap.release(); + cap.open(inputFile); + cap >> frame; + } + + if (cn != 3) + { + cv::Mat temp; + if (cn == 1) + cv::cvtColor(frame, temp, cv::COLOR_BGR2GRAY); + else + cv::cvtColor(frame, temp, cv::COLOR_BGR2BGRA); + cv::swap(temp, frame); + } + + gmg(frame, foreground); + } + CPU_SANITY_CHECK(foreground); } } -- 2.7.4