2014-08-01 22:11:20 +08:00
|
|
|
#include "../test_precomp.hpp"
|
2014-01-27 21:32:51 +08:00
|
|
|
#include "opencv2/ts/ocl_test.hpp"
|
|
|
|
|
|
|
|
#ifdef HAVE_OPENCL
|
2017-06-07 01:22:30 +08:00
|
|
|
#ifdef HAVE_VIDEO_INPUT
|
2014-01-27 21:32:51 +08:00
|
|
|
|
2017-11-05 21:48:40 +08:00
|
|
|
namespace opencv_test {
|
2014-01-27 21:32:51 +08:00
|
|
|
namespace ocl {
|
|
|
|
|
2014-01-31 14:46:29 +08:00
|
|
|
//////////////////////////Mog2_Update///////////////////////////////////
|
2014-01-27 21:32:51 +08:00
|
|
|
|
|
|
|
namespace
|
|
|
|
{
|
|
|
|
IMPLEMENT_PARAM_CLASS(UseGray, bool)
|
|
|
|
IMPLEMENT_PARAM_CLASS(DetectShadow, bool)
|
2016-02-01 23:24:28 +08:00
|
|
|
IMPLEMENT_PARAM_CLASS(UseFloat, bool)
|
2014-01-27 21:32:51 +08:00
|
|
|
}
|
|
|
|
|
2016-02-01 23:24:28 +08:00
|
|
|
PARAM_TEST_CASE(Mog2_Update, UseGray, DetectShadow,UseFloat)
|
2014-01-27 21:32:51 +08:00
|
|
|
{
|
|
|
|
bool useGray;
|
|
|
|
bool detectShadow;
|
2016-02-01 23:24:28 +08:00
|
|
|
bool useFloat;
|
2014-01-27 21:32:51 +08:00
|
|
|
virtual void SetUp()
|
|
|
|
{
|
|
|
|
useGray = GET_PARAM(0);
|
|
|
|
detectShadow = GET_PARAM(1);
|
2016-02-01 23:24:28 +08:00
|
|
|
useFloat = GET_PARAM(2);
|
2014-01-27 21:32:51 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-01-31 14:46:29 +08:00
|
|
|
OCL_TEST_P(Mog2_Update, Accuracy)
|
2014-01-27 21:32:51 +08:00
|
|
|
{
|
|
|
|
string inputFile = string(TS::ptr()->get_data_path()) + "video/768x576.avi";
|
|
|
|
VideoCapture cap(inputFile);
|
|
|
|
ASSERT_TRUE(cap.isOpened());
|
|
|
|
|
|
|
|
Ptr<BackgroundSubtractorMOG2> mog2_cpu = createBackgroundSubtractorMOG2();
|
|
|
|
Ptr<BackgroundSubtractorMOG2> mog2_ocl = createBackgroundSubtractorMOG2();
|
|
|
|
|
|
|
|
mog2_cpu->setDetectShadows(detectShadow);
|
|
|
|
mog2_ocl->setDetectShadows(detectShadow);
|
|
|
|
|
|
|
|
Mat frame, foreground;
|
|
|
|
UMat u_foreground;
|
|
|
|
|
|
|
|
for (int i = 0; i < 10; ++i)
|
|
|
|
{
|
|
|
|
cap >> frame;
|
|
|
|
ASSERT_FALSE(frame.empty());
|
|
|
|
|
|
|
|
if (useGray)
|
|
|
|
{
|
|
|
|
Mat temp;
|
|
|
|
cvtColor(frame, temp, COLOR_BGR2GRAY);
|
|
|
|
swap(temp, frame);
|
|
|
|
}
|
|
|
|
|
2016-02-01 23:24:28 +08:00
|
|
|
if(useFloat)
|
|
|
|
{
|
|
|
|
Mat temp;
|
|
|
|
frame.convertTo(temp,CV_32F);
|
|
|
|
swap(temp,frame);
|
|
|
|
}
|
|
|
|
|
2014-01-27 21:32:51 +08:00
|
|
|
OCL_OFF(mog2_cpu->apply(frame, foreground));
|
|
|
|
OCL_ON (mog2_ocl->apply(frame, u_foreground));
|
|
|
|
|
|
|
|
if (detectShadow)
|
2014-03-18 20:02:25 +08:00
|
|
|
EXPECT_MAT_SIMILAR(foreground, u_foreground, 15e-3);
|
2014-01-27 21:32:51 +08:00
|
|
|
else
|
|
|
|
EXPECT_MAT_NEAR(foreground, u_foreground, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-31 14:46:29 +08:00
|
|
|
//////////////////////////Mog2_getBackgroundImage///////////////////////////////////
|
|
|
|
|
2016-02-01 23:24:28 +08:00
|
|
|
PARAM_TEST_CASE(Mog2_getBackgroundImage, DetectShadow, UseFloat)
|
2014-01-27 21:32:51 +08:00
|
|
|
{
|
2014-01-31 14:46:29 +08:00
|
|
|
bool detectShadow;
|
2016-02-01 23:24:28 +08:00
|
|
|
bool useFloat;
|
2014-01-31 14:46:29 +08:00
|
|
|
virtual void SetUp()
|
|
|
|
{
|
|
|
|
detectShadow = GET_PARAM(0);
|
2016-02-01 23:24:28 +08:00
|
|
|
useFloat = GET_PARAM(1);
|
2014-01-31 14:46:29 +08:00
|
|
|
}
|
|
|
|
};
|
2014-01-27 21:32:51 +08:00
|
|
|
|
2014-01-31 14:46:29 +08:00
|
|
|
OCL_TEST_P(Mog2_getBackgroundImage, Accuracy)
|
|
|
|
{
|
2014-01-27 21:32:51 +08:00
|
|
|
string inputFile = string(TS::ptr()->get_data_path()) + "video/768x576.avi";
|
|
|
|
VideoCapture cap(inputFile);
|
|
|
|
ASSERT_TRUE(cap.isOpened());
|
|
|
|
|
|
|
|
Ptr<BackgroundSubtractorMOG2> mog2_cpu = createBackgroundSubtractorMOG2();
|
|
|
|
Ptr<BackgroundSubtractorMOG2> mog2_ocl = createBackgroundSubtractorMOG2();
|
|
|
|
|
|
|
|
mog2_cpu->setDetectShadows(detectShadow);
|
|
|
|
mog2_ocl->setDetectShadows(detectShadow);
|
|
|
|
|
|
|
|
Mat frame, foreground;
|
|
|
|
UMat u_foreground;
|
|
|
|
|
|
|
|
for (int i = 0; i < 10; ++i)
|
|
|
|
{
|
|
|
|
cap >> frame;
|
|
|
|
ASSERT_FALSE(frame.empty());
|
|
|
|
|
2016-02-01 23:24:28 +08:00
|
|
|
if(useFloat)
|
|
|
|
{
|
|
|
|
Mat temp;
|
|
|
|
frame.convertTo(temp,CV_32F);
|
|
|
|
swap(temp,frame);
|
|
|
|
}
|
|
|
|
|
2014-01-27 21:32:51 +08:00
|
|
|
OCL_OFF(mog2_cpu->apply(frame, foreground));
|
|
|
|
OCL_ON (mog2_ocl->apply(frame, u_foreground));
|
|
|
|
}
|
|
|
|
|
|
|
|
Mat background;
|
|
|
|
OCL_OFF(mog2_cpu->getBackgroundImage(background));
|
|
|
|
|
|
|
|
UMat u_background;
|
|
|
|
OCL_ON (mog2_ocl->getBackgroundImage(u_background));
|
|
|
|
|
|
|
|
EXPECT_MAT_NEAR(background, u_background, 1.0);
|
|
|
|
}
|
|
|
|
|
2014-01-31 14:46:29 +08:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
OCL_INSTANTIATE_TEST_CASE_P(OCL_Video, Mog2_Update, Combine(
|
2016-02-01 23:24:28 +08:00
|
|
|
Values(UseGray(true),UseGray(false)),
|
|
|
|
Values(DetectShadow(true), DetectShadow(false)),
|
|
|
|
Values(UseFloat(false),UseFloat(true)))
|
2014-01-27 21:32:51 +08:00
|
|
|
);
|
2014-01-31 14:46:29 +08:00
|
|
|
|
2016-02-01 23:24:28 +08:00
|
|
|
OCL_INSTANTIATE_TEST_CASE_P(OCL_Video, Mog2_getBackgroundImage, Combine(
|
|
|
|
Values(DetectShadow(true), DetectShadow(false)),
|
|
|
|
Values(UseFloat(false),UseFloat(true)))
|
2014-01-31 14:46:29 +08:00
|
|
|
);
|
|
|
|
|
2017-11-05 21:48:40 +08:00
|
|
|
}}// namespace opencv_test::ocl
|
2014-01-27 21:32:51 +08:00
|
|
|
|
2017-06-07 01:22:30 +08:00
|
|
|
#endif
|
2014-03-18 20:02:25 +08:00
|
|
|
#endif
|