1 #include "../perf_precomp.hpp" 2 #include "opencv2/ts/ocl_perf.hpp" 3 4 #ifdef HAVE_OPENCL 5 6 #if defined(HAVE_XINE) || \ 7 defined(HAVE_GSTREAMER) || \ 8 defined(HAVE_QUICKTIME) || \ 9 defined(HAVE_AVFOUNDATION) || \ 10 defined(HAVE_FFMPEG) || \ 11 defined(WIN32) 12 13 # define BUILD_WITH_VIDEO_INPUT_SUPPORT 1 14 #else 15 # define BUILD_WITH_VIDEO_INPUT_SUPPORT 0 16 #endif 17 18 #if BUILD_WITH_VIDEO_INPUT_SUPPORT 19 20 namespace cvtest { 21 namespace ocl { 22 23 //////////////////////////// Mog2////////////////////////// 24 25 typedef tuple<string, int> VideoMOG2ParamType; 26 typedef TestBaseWithParam<VideoMOG2ParamType> MOG2_Apply; 27 typedef TestBaseWithParam<VideoMOG2ParamType> MOG2_GetBackgroundImage; 28 29 static void cvtFrameFmt(vector<Mat>& input, vector<Mat>& output) 30 { 31 for(int i = 0; i< (int)(input.size()); i++) 32 { 33 cvtColor(input[i], output[i], COLOR_RGB2GRAY); 34 } 35 } 36 37 static void prepareData(VideoCapture& cap, int cn, vector<Mat>& frame_buffer) 38 { 39 cv::Mat frame; 40 std::vector<Mat> frame_buffer_init; 41 int nFrame = (int)frame_buffer.size(); 42 for(int i = 0; i < nFrame; i++) 43 { 44 cap >> frame; 45 ASSERT_FALSE(frame.empty()); 46 frame_buffer_init.push_back(frame); 47 } 48 49 if(cn == 1) 50 cvtFrameFmt(frame_buffer_init, frame_buffer); 51 else 52 frame_buffer = frame_buffer_init; 53 } 54 55 OCL_PERF_TEST_P(MOG2_Apply, Mog2, Combine(Values("gpu/video/768x576.avi", "gpu/video/1920x1080.avi"), Values(1,3))) 56 { 57 VideoMOG2ParamType params = GetParam(); 58 59 const string inputFile = getDataPath(get<0>(params)); 60 61 const int cn = get<1>(params); 62 int nFrame = 5; 63 64 vector<Mat> frame_buffer(nFrame); 65 66 cv::VideoCapture cap(inputFile); 67 ASSERT_TRUE(cap.isOpened()); 68 prepareData(cap, cn, frame_buffer); 69 70 UMat u_foreground; 71 72 OCL_TEST_CYCLE() 73 { 74 Ptr<cv::BackgroundSubtractorMOG2> mog2 = createBackgroundSubtractorMOG2(); 75 mog2->setDetectShadows(false); 76 u_foreground.release(); 77 for (int i = 0; i < nFrame; i++) 78 { 79 mog2->apply(frame_buffer[i], u_foreground); 80 } 81 } 82 SANITY_CHECK(u_foreground); 83 } 84 85 OCL_PERF_TEST_P(MOG2_GetBackgroundImage, Mog2, Combine(Values("gpu/video/768x576.avi", "gpu/video/1920x1080.avi"), Values(3))) 86 { 87 VideoMOG2ParamType params = GetParam(); 88 89 const string inputFile = getDataPath(get<0>(params)); 90 91 const int cn = get<1>(params); 92 int nFrame = 5; 93 94 vector<Mat> frame_buffer(nFrame); 95 96 cv::VideoCapture cap(inputFile); 97 ASSERT_TRUE(cap.isOpened()); 98 prepareData(cap, cn, frame_buffer); 99 100 UMat u_foreground, u_background; 101 102 OCL_TEST_CYCLE() 103 { 104 Ptr<cv::BackgroundSubtractorMOG2> mog2 = createBackgroundSubtractorMOG2(); 105 mog2->setDetectShadows(false); 106 u_foreground.release(); 107 u_background.release(); 108 for (int i = 0; i < nFrame; i++) 109 { 110 mog2->apply(frame_buffer[i], u_foreground); 111 } 112 mog2->getBackgroundImage(u_background); 113 } 114 SANITY_CHECK(u_background); 115 } 116 117 }}// namespace cvtest::ocl 118 119 #endif 120 #endif