1 /*M///////////////////////////////////////////////////////////////////////////////////////
3 // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
5 // By downloading, copying, installing or using the software you agree to this license.
6 // If you do not agree to this license, do not download, install,
7 // copy or use the software.
11 // For Open Source Computer Vision Library
13 // Copyright (C) 2010-2013, Multicoreware, Inc., all rights reserved.
14 // Copyright (C) 2010-2013, Advanced Micro Devices, Inc., all rights reserved.
15 // Third party copyrights are property of their respective owners.
18 // Jin Ma, jin@multicorewareinc.com
20 // Redistribution and use in source and binary forms, with or without modification,
21 // are permitted provided that the following conditions are met:
23 // * Redistribution's of source code must retain the above copyright notice,
24 // this list of conditions and the following disclaimer.
26 // * Redistribution's in binary form must reproduce the above copyright notice,
27 // this list of conditions and the following disclaimer in the documentation
28 // and/or other oclMaterials provided with the distribution.
30 // * The name of the copyright holders may not be used to endorse or promote products
31 // derived from this software without specific prior written permission.
33 // This software is provided by the copyright holders and contributors "as is" and
34 // any express or implied warranties, including, but not limited to, the implied
35 // warranties of merchantability and fitness for a particular purpose are disclaimed.
36 // In no event shall the Intel Corporation or contributors be liable for any direct,
37 // indirect, incidental, special, exemplary, or consequential damages
38 // (including, but not limited to, procurement of substitute goods or services;
39 // loss of use, data, or profits; or business interruption) however caused
40 // and on any theory of liability, whether in contract, strict liability,
41 // or tort (including negligence or otherwise) arising in any way out of
42 // the use of this software, even if advised of the possibility of such damage.
46 #include "precomp.hpp"
51 using namespace cv::ocl;
52 using namespace cvtest;
53 using namespace testing;
56 extern string workdir;
57 //////////////////////////////////////////////////////
62 IMPLEMENT_PARAM_CLASS(UseGray, bool)
63 IMPLEMENT_PARAM_CLASS(LearningRate, double)
66 PARAM_TEST_CASE(mog, UseGray, LearningRate, bool)
74 useGray = GET_PARAM(0);
76 learningRate = GET_PARAM(1);
78 useRoi = GET_PARAM(2);
84 std::string inputFile = string(cvtest::TS::ptr()->get_data_path()) + "gpu/768x576.avi";
85 cv::VideoCapture cap(inputFile);
86 ASSERT_TRUE(cap.isOpened());
90 ASSERT_FALSE(frame.empty());
93 cv::ocl::oclMat foreground = createMat_ocl(frame.size(), CV_8UC1, useRoi);
95 cv::BackgroundSubtractorMOG mog_gold;
96 cv::Mat foreground_gold;
98 for (int i = 0; i < 10; ++i)
101 ASSERT_FALSE(frame.empty());
106 cv::cvtColor(frame, temp, cv::COLOR_BGR2GRAY);
107 cv::swap(temp, frame);
110 mog(loadMat_ocl(frame, useRoi), foreground, (float)learningRate);
112 mog_gold(frame, foreground_gold, learningRate);
114 EXPECT_MAT_NEAR(foreground_gold, foreground, 0.0);
117 INSTANTIATE_TEST_CASE_P(OCL_Video, mog, testing::Combine(
118 testing::Values(UseGray(false), UseGray(true)),
119 testing::Values(LearningRate(0.0), LearningRate(0.01)),
120 Values(true, false)));
122 //////////////////////////////////////////////////////
127 IMPLEMENT_PARAM_CLASS(DetectShadow, bool)
130 PARAM_TEST_CASE(mog2, UseGray, DetectShadow, bool)
137 useGray = GET_PARAM(0);
138 detectShadow = GET_PARAM(1);
139 useRoi = GET_PARAM(2);
145 std::string inputFile = string(cvtest::TS::ptr()->get_data_path()) + "gpu/768x576.avi";
146 cv::VideoCapture cap(inputFile);
147 ASSERT_TRUE(cap.isOpened());
151 ASSERT_FALSE(frame.empty());
154 mog2.bShadowDetection = detectShadow;
155 cv::ocl::oclMat foreground = createMat_ocl(frame.size(), CV_8UC1, useRoi);
157 cv::BackgroundSubtractorMOG2 mog2_gold;
158 mog2_gold.set("detectShadows", detectShadow);
159 cv::Mat foreground_gold;
161 for (int i = 0; i < 10; ++i)
164 ASSERT_FALSE(frame.empty());
169 cv::cvtColor(frame, temp, cv::COLOR_BGR2GRAY);
170 cv::swap(temp, frame);
173 mog2(loadMat_ocl(frame, useRoi), foreground);
175 mog2_gold(frame, foreground_gold);
180 EXPECT_MAT_SIMILAR(foreground_gold, foreground, 1e-2);
184 EXPECT_MAT_NEAR(foreground_gold, foreground, 0);
189 TEST_P(mog2, getBackgroundImage)
194 std::string inputFile = string(cvtest::TS::ptr()->get_data_path()) + "gpu/768x576.avi";
195 cv::VideoCapture cap(inputFile);
196 ASSERT_TRUE(cap.isOpened());
201 mog2.bShadowDetection = detectShadow;
202 cv::ocl::oclMat foreground;
204 cv::BackgroundSubtractorMOG2 mog2_gold;
205 mog2_gold.set("detectShadows", detectShadow);
206 cv::Mat foreground_gold;
208 for (int i = 0; i < 10; ++i)
211 ASSERT_FALSE(frame.empty());
213 mog2(loadMat_ocl(frame, useRoi), foreground);
215 mog2_gold(frame, foreground_gold);
218 cv::ocl::oclMat background = createMat_ocl(frame.size(), frame.type(), useRoi);
219 mog2.getBackgroundImage(background);
221 cv::Mat background_gold;
222 mog2_gold.getBackgroundImage(background_gold);
224 EXPECT_MAT_NEAR(background_gold, background, 1.0);
227 INSTANTIATE_TEST_CASE_P(OCL_Video, mog2, testing::Combine(
228 testing::Values(UseGray(true), UseGray(false)),
229 testing::Values(DetectShadow(true), DetectShadow(false)),
230 Values(true, false)));