Path: blob/master/modules/video/perf/opencl/perf_bgfg_mog2.cpp
16345 views
// This file is part of OpenCV project.1// It is subject to the license terms in the LICENSE file found in the top-level directory2// of this distribution and at http://opencv.org/license.html.34#include "../perf_precomp.hpp"5#include "opencv2/ts/ocl_perf.hpp"67#ifdef HAVE_OPENCL8#ifdef HAVE_VIDEO_INPUT9#include "../perf_bgfg_utils.hpp"1011namespace opencv_test {12namespace ocl {1314//////////////////////////// Mog2//////////////////////////1516typedef tuple<string, int> VideoMOG2ParamType;17typedef TestBaseWithParam<VideoMOG2ParamType> MOG2_Apply;18typedef TestBaseWithParam<VideoMOG2ParamType> MOG2_GetBackgroundImage;1920using namespace opencv_test;2122OCL_PERF_TEST_P(MOG2_Apply, Mog2, Combine(Values("gpu/video/768x576.avi", "gpu/video/1920x1080.avi"), Values(1,3)))23{24VideoMOG2ParamType params = GetParam();2526const string inputFile = getDataPath(get<0>(params));2728const int cn = get<1>(params);29int nFrame = 5;3031vector<Mat> frame_buffer(nFrame);3233cv::VideoCapture cap(inputFile);34ASSERT_TRUE(cap.isOpened());35prepareData(cap, cn, frame_buffer);3637UMat u_foreground;3839OCL_TEST_CYCLE()40{41Ptr<cv::BackgroundSubtractorMOG2> mog2 = createBackgroundSubtractorMOG2();42mog2->setDetectShadows(false);43u_foreground.release();44for (int i = 0; i < nFrame; i++)45{46mog2->apply(frame_buffer[i], u_foreground);47}48}49SANITY_CHECK_NOTHING();50}5152OCL_PERF_TEST_P(MOG2_GetBackgroundImage, Mog2, Values(53std::make_pair<string, int>("gpu/video/768x576.avi", 5),54std::make_pair<string, int>("gpu/video/1920x1080.avi", 5)))55{56VideoMOG2ParamType params = GetParam();5758const string inputFile = getDataPath(get<0>(params));5960const int cn = 3;61const int skipFrames = get<1>(params);62int nFrame = 10;6364vector<Mat> frame_buffer(nFrame);6566cv::VideoCapture cap(inputFile);67ASSERT_TRUE(cap.isOpened());68prepareData(cap, cn, frame_buffer, skipFrames);6970UMat u_foreground, u_background;7172OCL_TEST_CYCLE()73{74Ptr<cv::BackgroundSubtractorMOG2> mog2 = createBackgroundSubtractorMOG2();75mog2->setDetectShadows(false);76u_foreground.release();77u_background.release();78for (int i = 0; i < nFrame; i++)79{80mog2->apply(frame_buffer[i], u_foreground);81}82mog2->getBackgroundImage(u_background);83}84#ifdef DEBUG_BGFG85imwrite(format("fg_%d_%d_mog2_ocl.png", frame_buffer[0].rows, cn), u_foreground.getMat(ACCESS_READ));86imwrite(format("bg_%d_%d_mog2_ocl.png", frame_buffer[0].rows, cn), u_background.getMat(ACCESS_READ));87#endif88SANITY_CHECK_NOTHING();89}9091}}// namespace opencv_test::ocl9293#endif94#endif959697