|
| 1 | +// This file is part of OpenCV project. |
| 2 | +// It is subject to the license terms in the LICENSE file found in the top-level directory |
| 3 | +// of this distribution and at http://opencv.org/license.html. |
| 4 | + |
| 5 | +#include "../perf_precomp.hpp" |
| 6 | +#include "opencv2/ts/ocl_perf.hpp" |
| 7 | + |
| 8 | +#ifdef HAVE_OPENCL |
| 9 | +#ifdef HAVE_VIDEO_INPUT |
| 10 | +#include "../perf_bgfg_utils.hpp" |
| 11 | + |
| 12 | +namespace cvtest { |
| 13 | +namespace ocl { |
| 14 | + |
| 15 | +//////////////////////////// KNN////////////////////////// |
| 16 | + |
| 17 | +typedef tuple<string, int> VideoKNNParamType; |
| 18 | +typedef TestBaseWithParam<VideoKNNParamType> KNN_Apply; |
| 19 | +typedef TestBaseWithParam<VideoKNNParamType> KNN_GetBackgroundImage; |
| 20 | + |
| 21 | +using namespace opencv_test; |
| 22 | + |
| 23 | +OCL_PERF_TEST_P(KNN_Apply, KNN, Combine(Values("gpu/video/768x576.avi", "gpu/video/1920x1080.avi"), Values(1,3))) |
| 24 | +{ |
| 25 | + VideoKNNParamType params = GetParam(); |
| 26 | + |
| 27 | + const string inputFile = getDataPath(get<0>(params)); |
| 28 | + |
| 29 | + const int cn = get<1>(params); |
| 30 | + int nFrame = 5; |
| 31 | + |
| 32 | + vector<Mat> frame_buffer(nFrame); |
| 33 | + |
| 34 | + cv::VideoCapture cap(inputFile); |
| 35 | + ASSERT_TRUE(cap.isOpened()); |
| 36 | + prepareData(cap, cn, frame_buffer); |
| 37 | + |
| 38 | + UMat u_foreground; |
| 39 | + |
| 40 | + OCL_TEST_CYCLE() |
| 41 | + { |
| 42 | + Ptr<cv::BackgroundSubtractorKNN> knn = createBackgroundSubtractorKNN(); |
| 43 | + knn->setDetectShadows(false); |
| 44 | + u_foreground.release(); |
| 45 | + for (int i = 0; i < nFrame; i++) |
| 46 | + { |
| 47 | + knn->apply(frame_buffer[i], u_foreground); |
| 48 | + } |
| 49 | + } |
| 50 | + SANITY_CHECK_NOTHING(); |
| 51 | +} |
| 52 | + |
| 53 | +OCL_PERF_TEST_P(KNN_GetBackgroundImage, KNN, Values( |
| 54 | + std::make_pair<string, int>("gpu/video/768x576.avi", 5), |
| 55 | + std::make_pair<string, int>("gpu/video/1920x1080.avi", 5))) |
| 56 | +{ |
| 57 | + VideoKNNParamType params = GetParam(); |
| 58 | + |
| 59 | + const string inputFile = getDataPath(get<0>(params)); |
| 60 | + |
| 61 | + const int cn = 3; |
| 62 | + const int skipFrames = get<1>(params); |
| 63 | + int nFrame = 10; |
| 64 | + |
| 65 | + vector<Mat> frame_buffer(nFrame); |
| 66 | + |
| 67 | + cv::VideoCapture cap(inputFile); |
| 68 | + ASSERT_TRUE(cap.isOpened()); |
| 69 | + prepareData(cap, cn, frame_buffer, skipFrames); |
| 70 | + |
| 71 | + UMat u_foreground, u_background; |
| 72 | + |
| 73 | + OCL_TEST_CYCLE() |
| 74 | + { |
| 75 | + Ptr<cv::BackgroundSubtractorKNN> knn = createBackgroundSubtractorKNN(); |
| 76 | + knn->setDetectShadows(false); |
| 77 | + u_foreground.release(); |
| 78 | + u_background.release(); |
| 79 | + for (int i = 0; i < nFrame; i++) |
| 80 | + { |
| 81 | + knn->apply(frame_buffer[i], u_foreground); |
| 82 | + } |
| 83 | + knn->getBackgroundImage(u_background); |
| 84 | + } |
| 85 | +#ifdef DEBUG_BGFG |
| 86 | + imwrite(format("fg_%d_%d_knn_ocl.png", frame_buffer[0].rows, cn), u_foreground.getMat(ACCESS_READ)); |
| 87 | + imwrite(format("bg_%d_%d_knn_ocl.png", frame_buffer[0].rows, cn), u_background.getMat(ACCESS_READ)); |
| 88 | +#endif |
| 89 | + SANITY_CHECK_NOTHING(); |
| 90 | +} |
| 91 | + |
| 92 | +}}// namespace cvtest::ocl |
| 93 | + |
| 94 | +#endif |
| 95 | +#endif |
0 commit comments