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 "test_precomp.hpp"
51 using namespace cv::ocl;
52 using namespace cvtest;
53 using namespace testing;
56 #if defined(HAVE_XINE) || \
57 defined(HAVE_GSTREAMER) || \
58 defined(HAVE_QUICKTIME) || \
59 defined(HAVE_AVFOUNDATION) || \
60 defined(HAVE_FFMPEG) || \
63 # define BUILD_WITH_VIDEO_INPUT_SUPPORT 1
65 # define BUILD_WITH_VIDEO_INPUT_SUPPORT 0
68 #if BUILD_WITH_VIDEO_INPUT_SUPPORT
70 //////////////////////////////////////////////////////
75 IMPLEMENT_PARAM_CLASS(UseGray, bool)
76 IMPLEMENT_PARAM_CLASS(LearningRate, double)
79 PARAM_TEST_CASE(mog, UseGray, LearningRate, bool)
87 useGray = GET_PARAM(0);
89 learningRate = GET_PARAM(1);
91 useRoi = GET_PARAM(2);
97 std::string inputFile = string(cvtest::TS::ptr()->get_data_path()) + "gpu/video/768x576.avi";
98 cv::VideoCapture cap(inputFile);
99 ASSERT_TRUE(cap.isOpened());
103 ASSERT_FALSE(frame.empty());
106 cv::ocl::oclMat foreground = createMat_ocl(frame.size(), CV_8UC1, useRoi);
108 cv::BackgroundSubtractorMOG mog_gold;
109 cv::Mat foreground_gold;
111 for (int i = 0; i < 10; ++i)
114 ASSERT_FALSE(frame.empty());
119 cv::cvtColor(frame, temp, cv::COLOR_BGR2GRAY);
120 cv::swap(temp, frame);
123 mog(loadMat_ocl(frame, useRoi), foreground, (float)learningRate);
125 mog_gold(frame, foreground_gold, learningRate);
127 EXPECT_MAT_NEAR(foreground_gold, foreground, 0.0);
130 INSTANTIATE_TEST_CASE_P(OCL_Video, mog, testing::Combine(
131 testing::Values(UseGray(false), UseGray(true)),
132 testing::Values(LearningRate(0.0), LearningRate(0.01)),
133 Values(true, false)));
135 //////////////////////////////////////////////////////
140 IMPLEMENT_PARAM_CLASS(DetectShadow, bool)
143 PARAM_TEST_CASE(mog2, UseGray, DetectShadow, bool)
150 useGray = GET_PARAM(0);
151 detectShadow = GET_PARAM(1);
152 useRoi = GET_PARAM(2);
158 std::string inputFile = string(cvtest::TS::ptr()->get_data_path()) + "gpu/video/768x576.avi";
159 cv::VideoCapture cap(inputFile);
160 ASSERT_TRUE(cap.isOpened());
164 ASSERT_FALSE(frame.empty());
167 mog2.bShadowDetection = detectShadow;
168 cv::ocl::oclMat foreground = createMat_ocl(frame.size(), CV_8UC1, useRoi);
170 cv::BackgroundSubtractorMOG2 mog2_gold;
171 mog2_gold.set("detectShadows", detectShadow);
172 cv::Mat foreground_gold;
174 for (int i = 0; i < 10; ++i)
177 ASSERT_FALSE(frame.empty());
182 cv::cvtColor(frame, temp, cv::COLOR_BGR2GRAY);
183 cv::swap(temp, frame);
186 mog2(loadMat_ocl(frame, useRoi), foreground);
188 mog2_gold(frame, foreground_gold);
191 EXPECT_MAT_SIMILAR(foreground_gold, foreground, 15e-3)
193 EXPECT_MAT_NEAR(foreground_gold, foreground, 0)
197 TEST_P(mog2, getBackgroundImage)
202 std::string inputFile = string(cvtest::TS::ptr()->get_data_path()) + "gpu/video/768x576.avi";
203 cv::VideoCapture cap(inputFile);
204 ASSERT_TRUE(cap.isOpened());
209 mog2.bShadowDetection = detectShadow;
210 cv::ocl::oclMat foreground;
212 cv::BackgroundSubtractorMOG2 mog2_gold;
213 mog2_gold.set("detectShadows", detectShadow);
214 cv::Mat foreground_gold;
216 for (int i = 0; i < 10; ++i)
219 ASSERT_FALSE(frame.empty());
221 mog2(loadMat_ocl(frame, useRoi), foreground);
223 mog2_gold(frame, foreground_gold);
226 cv::ocl::oclMat background = createMat_ocl(frame.size(), frame.type(), useRoi);
227 mog2.getBackgroundImage(background);
229 cv::Mat background_gold;
230 mog2_gold.getBackgroundImage(background_gold);
232 EXPECT_MAT_NEAR(background_gold, background, 1.0);
235 INSTANTIATE_TEST_CASE_P(OCL_Video, mog2, testing::Combine(
236 testing::Values(UseGray(true), UseGray(false)),
237 testing::Values(DetectShadow(true), DetectShadow(false)),
238 Values(true, false)));