Path: blob/master/modules/video/test/ocl/test_bgfg_mog2.cpp
16350 views
#include "../test_precomp.hpp"1#include "opencv2/ts/ocl_test.hpp"23#ifdef HAVE_OPENCL4#ifdef HAVE_VIDEO_INPUT56namespace opencv_test {7namespace ocl {89//////////////////////////Mog2_Update///////////////////////////////////1011namespace12{13IMPLEMENT_PARAM_CLASS(UseGray, bool)14IMPLEMENT_PARAM_CLASS(DetectShadow, bool)15IMPLEMENT_PARAM_CLASS(UseFloat, bool)16}1718PARAM_TEST_CASE(Mog2_Update, UseGray, DetectShadow,UseFloat)19{20bool useGray;21bool detectShadow;22bool useFloat;23virtual void SetUp()24{25useGray = GET_PARAM(0);26detectShadow = GET_PARAM(1);27useFloat = GET_PARAM(2);28}29};3031OCL_TEST_P(Mog2_Update, Accuracy)32{33string inputFile = string(TS::ptr()->get_data_path()) + "video/768x576.avi";34VideoCapture cap(inputFile);35ASSERT_TRUE(cap.isOpened());3637Ptr<BackgroundSubtractorMOG2> mog2_cpu = createBackgroundSubtractorMOG2();38Ptr<BackgroundSubtractorMOG2> mog2_ocl = createBackgroundSubtractorMOG2();3940mog2_cpu->setDetectShadows(detectShadow);41mog2_ocl->setDetectShadows(detectShadow);4243Mat frame, foreground;44UMat u_foreground;4546for (int i = 0; i < 10; ++i)47{48cap >> frame;49ASSERT_FALSE(frame.empty());5051if (useGray)52{53Mat temp;54cvtColor(frame, temp, COLOR_BGR2GRAY);55swap(temp, frame);56}5758if(useFloat)59{60Mat temp;61frame.convertTo(temp,CV_32F);62swap(temp,frame);63}6465OCL_OFF(mog2_cpu->apply(frame, foreground));66OCL_ON (mog2_ocl->apply(frame, u_foreground));6768if (detectShadow)69EXPECT_MAT_SIMILAR(foreground, u_foreground, 15e-3);70else71EXPECT_MAT_NEAR(foreground, u_foreground, 0);72}73}7475//////////////////////////Mog2_getBackgroundImage///////////////////////////////////7677PARAM_TEST_CASE(Mog2_getBackgroundImage, DetectShadow, UseFloat)78{79bool detectShadow;80bool useFloat;81virtual void SetUp()82{83detectShadow = GET_PARAM(0);84useFloat = GET_PARAM(1);85}86};8788OCL_TEST_P(Mog2_getBackgroundImage, Accuracy)89{90string inputFile = string(TS::ptr()->get_data_path()) + "video/768x576.avi";91VideoCapture cap(inputFile);92ASSERT_TRUE(cap.isOpened());9394Ptr<BackgroundSubtractorMOG2> mog2_cpu = createBackgroundSubtractorMOG2();95Ptr<BackgroundSubtractorMOG2> mog2_ocl = createBackgroundSubtractorMOG2();9697mog2_cpu->setDetectShadows(detectShadow);98mog2_ocl->setDetectShadows(detectShadow);99100Mat frame, foreground;101UMat u_foreground;102103for (int i = 0; i < 10; ++i)104{105cap >> frame;106ASSERT_FALSE(frame.empty());107108if(useFloat)109{110Mat temp;111frame.convertTo(temp,CV_32F);112swap(temp,frame);113}114115OCL_OFF(mog2_cpu->apply(frame, foreground));116OCL_ON (mog2_ocl->apply(frame, u_foreground));117}118119Mat background;120OCL_OFF(mog2_cpu->getBackgroundImage(background));121122UMat u_background;123OCL_ON (mog2_ocl->getBackgroundImage(u_background));124125EXPECT_MAT_NEAR(background, u_background, 1.0);126}127128///////////////////////////////////////////////////////////////////////////////////////////129130OCL_INSTANTIATE_TEST_CASE_P(OCL_Video, Mog2_Update, Combine(131Values(UseGray(true),UseGray(false)),132Values(DetectShadow(true), DetectShadow(false)),133Values(UseFloat(false),UseFloat(true)))134);135136OCL_INSTANTIATE_TEST_CASE_P(OCL_Video, Mog2_getBackgroundImage, Combine(137Values(DetectShadow(true), DetectShadow(false)),138Values(UseFloat(false),UseFloat(true)))139);140141}}// namespace opencv_test::ocl142143#endif144#endif145146147