Path: blob/master/modules/video/perf/perf_bgfg_knn.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//////////////////////////// KNN//////////////////////////1213typedef tuple<std::string, int> VideoKNNParamType;14typedef TestBaseWithParam<VideoKNNParamType> KNN_Apply;15typedef TestBaseWithParam<VideoKNNParamType> KNN_GetBackgroundImage;1617PERF_TEST_P(KNN_Apply, KNN, Combine(Values("gpu/video/768x576.avi", "gpu/video/1920x1080.avi"), Values(1,3)))18{19VideoKNNParamType 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::BackgroundSubtractorKNN> knn = createBackgroundSubtractorKNN();37knn->setDetectShadows(false);38foreground.release();39for (int i = 0; i < nFrame; i++)40{41knn->apply(frame_buffer[i], foreground);42}43}44SANITY_CHECK_NOTHING();45}4647PERF_TEST_P(KNN_GetBackgroundImage, KNN, Values(48std::make_pair<string, int>("gpu/video/768x576.avi", 5),49std::make_pair<string, int>("gpu/video/1920x1080.avi", 5)))50{51VideoKNNParamType 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::BackgroundSubtractorKNN> knn = createBackgroundSubtractorKNN();70knn->setDetectShadows(false);71foreground.release();72background.release();73for (int i = 0; i < nFrame; i++)74{75knn->apply(frame_buffer[i], foreground);76}77knn->getBackgroundImage(background);78}79#ifdef DEBUG_BGFG80imwrite(format("fg_%d_%d_knn.png", frame_buffer[0].rows, cn), foreground);81imwrite(format("bg_%d_%d_knn.png", frame_buffer[0].rows, cn), background);82#endif83SANITY_CHECK_NOTHING();84}8586}}// namespace8788#endif899091