Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Tetragramm
GitHub Repository: Tetragramm/opencv
Path: blob/master/modules/video/test/ocl/test_bgfg_mog2.cpp
16350 views
1
#include "../test_precomp.hpp"
2
#include "opencv2/ts/ocl_test.hpp"
3
4
#ifdef HAVE_OPENCL
5
#ifdef HAVE_VIDEO_INPUT
6
7
namespace opencv_test {
8
namespace ocl {
9
10
//////////////////////////Mog2_Update///////////////////////////////////
11
12
namespace
13
{
14
IMPLEMENT_PARAM_CLASS(UseGray, bool)
15
IMPLEMENT_PARAM_CLASS(DetectShadow, bool)
16
IMPLEMENT_PARAM_CLASS(UseFloat, bool)
17
}
18
19
PARAM_TEST_CASE(Mog2_Update, UseGray, DetectShadow,UseFloat)
20
{
21
bool useGray;
22
bool detectShadow;
23
bool useFloat;
24
virtual void SetUp()
25
{
26
useGray = GET_PARAM(0);
27
detectShadow = GET_PARAM(1);
28
useFloat = GET_PARAM(2);
29
}
30
};
31
32
OCL_TEST_P(Mog2_Update, Accuracy)
33
{
34
string inputFile = string(TS::ptr()->get_data_path()) + "video/768x576.avi";
35
VideoCapture cap(inputFile);
36
ASSERT_TRUE(cap.isOpened());
37
38
Ptr<BackgroundSubtractorMOG2> mog2_cpu = createBackgroundSubtractorMOG2();
39
Ptr<BackgroundSubtractorMOG2> mog2_ocl = createBackgroundSubtractorMOG2();
40
41
mog2_cpu->setDetectShadows(detectShadow);
42
mog2_ocl->setDetectShadows(detectShadow);
43
44
Mat frame, foreground;
45
UMat u_foreground;
46
47
for (int i = 0; i < 10; ++i)
48
{
49
cap >> frame;
50
ASSERT_FALSE(frame.empty());
51
52
if (useGray)
53
{
54
Mat temp;
55
cvtColor(frame, temp, COLOR_BGR2GRAY);
56
swap(temp, frame);
57
}
58
59
if(useFloat)
60
{
61
Mat temp;
62
frame.convertTo(temp,CV_32F);
63
swap(temp,frame);
64
}
65
66
OCL_OFF(mog2_cpu->apply(frame, foreground));
67
OCL_ON (mog2_ocl->apply(frame, u_foreground));
68
69
if (detectShadow)
70
EXPECT_MAT_SIMILAR(foreground, u_foreground, 15e-3);
71
else
72
EXPECT_MAT_NEAR(foreground, u_foreground, 0);
73
}
74
}
75
76
//////////////////////////Mog2_getBackgroundImage///////////////////////////////////
77
78
PARAM_TEST_CASE(Mog2_getBackgroundImage, DetectShadow, UseFloat)
79
{
80
bool detectShadow;
81
bool useFloat;
82
virtual void SetUp()
83
{
84
detectShadow = GET_PARAM(0);
85
useFloat = GET_PARAM(1);
86
}
87
};
88
89
OCL_TEST_P(Mog2_getBackgroundImage, Accuracy)
90
{
91
string inputFile = string(TS::ptr()->get_data_path()) + "video/768x576.avi";
92
VideoCapture cap(inputFile);
93
ASSERT_TRUE(cap.isOpened());
94
95
Ptr<BackgroundSubtractorMOG2> mog2_cpu = createBackgroundSubtractorMOG2();
96
Ptr<BackgroundSubtractorMOG2> mog2_ocl = createBackgroundSubtractorMOG2();
97
98
mog2_cpu->setDetectShadows(detectShadow);
99
mog2_ocl->setDetectShadows(detectShadow);
100
101
Mat frame, foreground;
102
UMat u_foreground;
103
104
for (int i = 0; i < 10; ++i)
105
{
106
cap >> frame;
107
ASSERT_FALSE(frame.empty());
108
109
if(useFloat)
110
{
111
Mat temp;
112
frame.convertTo(temp,CV_32F);
113
swap(temp,frame);
114
}
115
116
OCL_OFF(mog2_cpu->apply(frame, foreground));
117
OCL_ON (mog2_ocl->apply(frame, u_foreground));
118
}
119
120
Mat background;
121
OCL_OFF(mog2_cpu->getBackgroundImage(background));
122
123
UMat u_background;
124
OCL_ON (mog2_ocl->getBackgroundImage(u_background));
125
126
EXPECT_MAT_NEAR(background, u_background, 1.0);
127
}
128
129
///////////////////////////////////////////////////////////////////////////////////////////
130
131
OCL_INSTANTIATE_TEST_CASE_P(OCL_Video, Mog2_Update, Combine(
132
Values(UseGray(true),UseGray(false)),
133
Values(DetectShadow(true), DetectShadow(false)),
134
Values(UseFloat(false),UseFloat(true)))
135
);
136
137
OCL_INSTANTIATE_TEST_CASE_P(OCL_Video, Mog2_getBackgroundImage, Combine(
138
Values(DetectShadow(true), DetectShadow(false)),
139
Values(UseFloat(false),UseFloat(true)))
140
);
141
142
}}// namespace opencv_test::ocl
143
144
#endif
145
#endif
146
147