Path: blob/master/modules/video/perf/perf_bgfg_mog2.cpp
16354 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"56#ifdef HAVE_VIDEO_INPUT7#include "perf_bgfg_utils.hpp"89namespace opencv_test { namespace {1011//////////////////////////// Mog2//////////////////////////1213typedef tuple<std::string, int> VideoMOG2ParamType;14typedef TestBaseWithParam<VideoMOG2ParamType> MOG2_Apply;15typedef TestBaseWithParam<VideoMOG2ParamType> MOG2_GetBackgroundImage;1617PERF_TEST_P(MOG2_Apply, Mog2, Combine(Values("gpu/video/768x576.avi", "gpu/video/1920x1080.avi"), Values(1,3)))18{19VideoMOG2ParamType params = GetParam();2021const string inputFile = getDataPath(get<0>(params));2223const int cn = get<1>(params);24int nFrame = 5;2526vector<Mat> frame_buffer(nFrame);2728cv::VideoCapture cap(inputFile);29ASSERT_TRUE(cap.isOpened());30prepareData(cap, cn, frame_buffer);3132Mat foreground;3334TEST_CYCLE()35{36Ptr<cv::BackgroundSubtractorMOG2> mog2 = createBackgroundSubtractorMOG2();37mog2->setDetectShadows(false);38foreground.release();39for (int i = 0; i < nFrame; i++)40{41mog2->apply(frame_buffer[i], foreground);42}43}44SANITY_CHECK_NOTHING();45}4647PERF_TEST_P(MOG2_GetBackgroundImage, Mog2, Values(48std::make_pair<string, int>("gpu/video/768x576.avi", 5),49std::make_pair<string, int>("gpu/video/1920x1080.avi", 5)))50{51VideoMOG2ParamType params = GetParam();5253const string inputFile = getDataPath(get<0>(params));5455const int cn = 3;56const int skipFrames = get<1>(params);57int nFrame = 10;5859vector<Mat> frame_buffer(nFrame);6061cv::VideoCapture cap(inputFile);62ASSERT_TRUE(cap.isOpened());63prepareData(cap, cn, frame_buffer, skipFrames);6465Mat foreground, background;6667TEST_CYCLE()68{69Ptr<cv::BackgroundSubtractorMOG2> mog2 = createBackgroundSubtractorMOG2();70mog2->setDetectShadows(false);71foreground.release();72background.release();73for (int i = 0; i < nFrame; i++)74{75mog2->apply(frame_buffer[i], foreground);76}77mog2->getBackgroundImage(background);78}79#ifdef DEBUG_BGFG80imwrite(format("fg_%d_%d_mog2.png", frame_buffer[0].rows, cn), foreground);81imwrite(format("bg_%d_%d_mog2.png", frame_buffer[0].rows, cn), background);82#endif83SANITY_CHECK_NOTHING();84}8586}}// namespace8788#endif899091