diff --git a/modules/video/perf/opencl/perf_bgfg_mog2.cpp b/modules/video/perf/opencl/perf_bgfg_mog2.cpp index f5ddc43d5e6f0a497e537c794da17db7f61641b9..cb9aa456c4105db7d6c86111c377783ffc9e11b1 100644 --- a/modules/video/perf/opencl/perf_bgfg_mog2.cpp +++ b/modules/video/perf/opencl/perf_bgfg_mog2.cpp @@ -1,8 +1,13 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. + #include "../perf_precomp.hpp" #include "opencv2/ts/ocl_perf.hpp" #ifdef HAVE_OPENCL #ifdef HAVE_VIDEO_INPUT +#include "../perf_bgfg_utils.hpp" namespace cvtest { namespace ocl { @@ -13,31 +18,7 @@ typedef tuple VideoMOG2ParamType; typedef TestBaseWithParam MOG2_Apply; typedef TestBaseWithParam MOG2_GetBackgroundImage; -static void cvtFrameFmt(vector& input, vector& output) -{ - for(int i = 0; i< (int)(input.size()); i++) - { - cvtColor(input[i], output[i], COLOR_RGB2GRAY); - } -} - -static void prepareData(VideoCapture& cap, int cn, vector& frame_buffer) -{ - cv::Mat frame; - std::vector frame_buffer_init; - int nFrame = (int)frame_buffer.size(); - for(int i = 0; i < nFrame; i++) - { - cap >> frame; - ASSERT_FALSE(frame.empty()); - frame_buffer_init.push_back(frame); - } - - if(cn == 1) - cvtFrameFmt(frame_buffer_init, frame_buffer); - else - frame_buffer = frame_buffer_init; -} +using namespace opencv_test; OCL_PERF_TEST_P(MOG2_Apply, Mog2, Combine(Values("gpu/video/768x576.avi", "gpu/video/1920x1080.avi"), Values(1,3))) { @@ -66,23 +47,26 @@ OCL_PERF_TEST_P(MOG2_Apply, Mog2, Combine(Values("gpu/video/768x576.avi", "gpu/v mog2->apply(frame_buffer[i], u_foreground); } } - SANITY_CHECK(u_foreground); + SANITY_CHECK_NOTHING(); } -OCL_PERF_TEST_P(MOG2_GetBackgroundImage, Mog2, Combine(Values("gpu/video/768x576.avi", "gpu/video/1920x1080.avi"), Values(3))) +OCL_PERF_TEST_P(MOG2_GetBackgroundImage, Mog2, Values( + std::make_pair("gpu/video/768x576.avi", 5), + std::make_pair("gpu/video/1920x1080.avi", 5))) { VideoMOG2ParamType params = GetParam(); const string inputFile = getDataPath(get<0>(params)); - const int cn = get<1>(params); - int nFrame = 5; + const int cn = 3; + const int skipFrames = get<1>(params); + int nFrame = 10; vector frame_buffer(nFrame); cv::VideoCapture cap(inputFile); ASSERT_TRUE(cap.isOpened()); - prepareData(cap, cn, frame_buffer); + prepareData(cap, cn, frame_buffer, skipFrames); UMat u_foreground, u_background; @@ -98,6 +82,10 @@ OCL_PERF_TEST_P(MOG2_GetBackgroundImage, Mog2, Combine(Values("gpu/video/768x576 } mog2->getBackgroundImage(u_background); } +#ifdef DEBUG_BGFG + imwrite(format("fg_%d_%d_mog2_ocl.png", frame_buffer[0].rows, cn), u_foreground.getMat(ACCESS_READ)); + imwrite(format("bg_%d_%d_mog2_ocl.png", frame_buffer[0].rows, cn), u_background.getMat(ACCESS_READ)); +#endif SANITY_CHECK_NOTHING(); } diff --git a/modules/video/perf/perf_bgfg_knn.cpp b/modules/video/perf/perf_bgfg_knn.cpp new file mode 100644 index 0000000000000000000000000000000000000000..d9ead09fd93d3a942bb8124b8a2afc457e4f2c3f --- /dev/null +++ b/modules/video/perf/perf_bgfg_knn.cpp @@ -0,0 +1,89 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. + +#include "perf_precomp.hpp" + +#ifdef HAVE_VIDEO_INPUT +#include "perf_bgfg_utils.hpp" + +namespace opencv_test { namespace { + +//////////////////////////// KNN////////////////////////// + +typedef tuple VideoKNNParamType; +typedef TestBaseWithParam KNN_Apply; +typedef TestBaseWithParam KNN_GetBackgroundImage; + +PERF_TEST_P(KNN_Apply, KNN, Combine(Values("gpu/video/768x576.avi", "gpu/video/1920x1080.avi"), Values(1,3))) +{ + VideoKNNParamType params = GetParam(); + + const string inputFile = getDataPath(get<0>(params)); + + const int cn = get<1>(params); + int nFrame = 5; + + vector frame_buffer(nFrame); + + cv::VideoCapture cap(inputFile); + ASSERT_TRUE(cap.isOpened()); + prepareData(cap, cn, frame_buffer); + + Mat foreground; + + TEST_CYCLE() + { + Ptr knn = createBackgroundSubtractorKNN(); + knn->setDetectShadows(false); + foreground.release(); + for (int i = 0; i < nFrame; i++) + { + knn->apply(frame_buffer[i], foreground); + } + } + SANITY_CHECK_NOTHING(); +} + +PERF_TEST_P(KNN_GetBackgroundImage, KNN, Values( + std::make_pair("gpu/video/768x576.avi", 5), + std::make_pair("gpu/video/1920x1080.avi", 5))) +{ + VideoKNNParamType params = GetParam(); + + const string inputFile = getDataPath(get<0>(params)); + + const int cn = 3; + const int skipFrames = get<1>(params); + int nFrame = 10; + + vector frame_buffer(nFrame); + + cv::VideoCapture cap(inputFile); + ASSERT_TRUE(cap.isOpened()); + prepareData(cap, cn, frame_buffer, skipFrames); + + Mat foreground, background; + + TEST_CYCLE() + { + Ptr knn = createBackgroundSubtractorKNN(); + knn->setDetectShadows(false); + foreground.release(); + background.release(); + for (int i = 0; i < nFrame; i++) + { + knn->apply(frame_buffer[i], foreground); + } + knn->getBackgroundImage(background); + } +#ifdef DEBUG_BGFG + imwrite(format("fg_%d_%d_knn.png", frame_buffer[0].rows, cn), foreground); + imwrite(format("bg_%d_%d_knn.png", frame_buffer[0].rows, cn), background); +#endif + SANITY_CHECK_NOTHING(); +} + +}}// namespace + +#endif diff --git a/modules/video/perf/perf_bgfg_mog2.cpp b/modules/video/perf/perf_bgfg_mog2.cpp new file mode 100644 index 0000000000000000000000000000000000000000..92e5d0283fadca2512916826298d5bfab9f6f9d2 --- /dev/null +++ b/modules/video/perf/perf_bgfg_mog2.cpp @@ -0,0 +1,89 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. + +#include "perf_precomp.hpp" + +#ifdef HAVE_VIDEO_INPUT +#include "perf_bgfg_utils.hpp" + +namespace opencv_test { namespace { + +//////////////////////////// Mog2////////////////////////// + +typedef tuple VideoMOG2ParamType; +typedef TestBaseWithParam MOG2_Apply; +typedef TestBaseWithParam MOG2_GetBackgroundImage; + +PERF_TEST_P(MOG2_Apply, Mog2, Combine(Values("gpu/video/768x576.avi", "gpu/video/1920x1080.avi"), Values(1,3))) +{ + VideoMOG2ParamType params = GetParam(); + + const string inputFile = getDataPath(get<0>(params)); + + const int cn = get<1>(params); + int nFrame = 5; + + vector frame_buffer(nFrame); + + cv::VideoCapture cap(inputFile); + ASSERT_TRUE(cap.isOpened()); + prepareData(cap, cn, frame_buffer); + + Mat foreground; + + TEST_CYCLE() + { + Ptr mog2 = createBackgroundSubtractorMOG2(); + mog2->setDetectShadows(false); + foreground.release(); + for (int i = 0; i < nFrame; i++) + { + mog2->apply(frame_buffer[i], foreground); + } + } + SANITY_CHECK_NOTHING(); +} + +PERF_TEST_P(MOG2_GetBackgroundImage, Mog2, Values( + std::make_pair("gpu/video/768x576.avi", 5), + std::make_pair("gpu/video/1920x1080.avi", 5))) +{ + VideoMOG2ParamType params = GetParam(); + + const string inputFile = getDataPath(get<0>(params)); + + const int cn = 3; + const int skipFrames = get<1>(params); + int nFrame = 10; + + vector frame_buffer(nFrame); + + cv::VideoCapture cap(inputFile); + ASSERT_TRUE(cap.isOpened()); + prepareData(cap, cn, frame_buffer, skipFrames); + + Mat foreground, background; + + TEST_CYCLE() + { + Ptr mog2 = createBackgroundSubtractorMOG2(); + mog2->setDetectShadows(false); + foreground.release(); + background.release(); + for (int i = 0; i < nFrame; i++) + { + mog2->apply(frame_buffer[i], foreground); + } + mog2->getBackgroundImage(background); + } +#ifdef DEBUG_BGFG + imwrite(format("fg_%d_%d_mog2.png", frame_buffer[0].rows, cn), foreground); + imwrite(format("bg_%d_%d_mog2.png", frame_buffer[0].rows, cn), background); +#endif + SANITY_CHECK_NOTHING(); +} + +}}// namespace + +#endif diff --git a/modules/video/perf/perf_bgfg_utils.hpp b/modules/video/perf/perf_bgfg_utils.hpp new file mode 100644 index 0000000000000000000000000000000000000000..2c37230a090e647f312cee95fdab5bc4abb55ccd --- /dev/null +++ b/modules/video/perf/perf_bgfg_utils.hpp @@ -0,0 +1,48 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. + +namespace opencv_test { + +//#define DEBUG_BGFG + +using namespace testing; +using namespace cvtest; +using namespace perf; + +namespace { + +using namespace cv; + +static void cvtFrameFmt(std::vector& input, std::vector& output) +{ + for(int i = 0; i< (int)(input.size()); i++) + { + cvtColor(input[i], output[i], COLOR_RGB2GRAY); + } +} + +static void prepareData(VideoCapture& cap, int cn, std::vector& frame_buffer, int skipFrames = 0) +{ + std::vector frame_buffer_init; + int nFrame = (int)frame_buffer.size(); + for (int i = 0; i < skipFrames; i++) + { + cv::Mat frame; + cap >> frame; + } + for (int i = 0; i < nFrame; i++) + { + cv::Mat frame; + cap >> frame; + ASSERT_FALSE(frame.empty()); + frame_buffer_init.push_back(frame); + } + + if (cn == 1) + cvtFrameFmt(frame_buffer_init, frame_buffer); + else + frame_buffer.swap(frame_buffer_init); +} + +}}