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);
88 learningRate = GET_PARAM(1);
89 useRoi = GET_PARAM(2);
93 OCL_TEST_P(mog, Update)
95 std::string inputFile = string(cvtest::TS::ptr()->get_data_path()) + "gpu/video/768x576.avi";
96 cv::VideoCapture cap(inputFile);
97 ASSERT_TRUE(cap.isOpened());
101 ASSERT_FALSE(frame.empty());
104 cv::ocl::oclMat foreground = createMat_ocl(rng, frame.size(), CV_8UC1, useRoi);
106 cv::BackgroundSubtractorMOG mog_gold;
107 cv::Mat foreground_gold;
109 for (int i = 0; i < 10; ++i)
112 ASSERT_FALSE(frame.empty());
117 cv::cvtColor(frame, temp, cv::COLOR_BGR2GRAY);
118 cv::swap(temp, frame);
121 mog(loadMat_ocl(rng, frame, useRoi), foreground, (float)learningRate);
123 mog_gold(frame, foreground_gold, learningRate);
125 EXPECT_MAT_NEAR(foreground_gold, foreground, 0.0);
128 INSTANTIATE_TEST_CASE_P(OCL_Video, mog, testing::Combine(
129 testing::Values(UseGray(false), UseGray(true)),
130 testing::Values(LearningRate(0.0), LearningRate(0.01)),
131 Values(true, false)));
133 //////////////////////////////////////////////////////
138 IMPLEMENT_PARAM_CLASS(DetectShadow, bool)
141 PARAM_TEST_CASE(mog2, UseGray, DetectShadow, bool)
148 useGray = GET_PARAM(0);
149 detectShadow = GET_PARAM(1);
150 useRoi = GET_PARAM(2);
154 OCL_TEST_P(mog2, Update)
156 std::string inputFile = string(cvtest::TS::ptr()->get_data_path()) + "gpu/video/768x576.avi";
157 cv::VideoCapture cap(inputFile);
158 ASSERT_TRUE(cap.isOpened());
162 ASSERT_FALSE(frame.empty());
165 mog2.bShadowDetection = detectShadow;
166 cv::ocl::oclMat foreground = createMat_ocl(rng, frame.size(), CV_8UC1, useRoi);
168 cv::BackgroundSubtractorMOG2 mog2_gold;
169 mog2_gold.set("detectShadows", detectShadow);
170 cv::Mat foreground_gold;
172 for (int i = 0; i < 10; ++i)
175 ASSERT_FALSE(frame.empty());
180 cv::cvtColor(frame, temp, cv::COLOR_BGR2GRAY);
181 cv::swap(temp, frame);
184 mog2(loadMat_ocl(rng, frame, useRoi), foreground);
186 mog2_gold(frame, foreground_gold);
189 EXPECT_MAT_SIMILAR(foreground_gold, foreground, 15e-3)
191 EXPECT_MAT_NEAR(foreground_gold, foreground, 0)
195 OCL_TEST_P(mog2, getBackgroundImage)
200 std::string inputFile = string(cvtest::TS::ptr()->get_data_path()) + "gpu/video/768x576.avi";
201 cv::VideoCapture cap(inputFile);
202 ASSERT_TRUE(cap.isOpened());
207 mog2.bShadowDetection = detectShadow;
208 cv::ocl::oclMat foreground;
210 cv::BackgroundSubtractorMOG2 mog2_gold;
211 mog2_gold.set("detectShadows", detectShadow);
212 cv::Mat foreground_gold;
214 for (int i = 0; i < 10; ++i)
217 ASSERT_FALSE(frame.empty());
219 mog2(loadMat_ocl(rng, frame, useRoi), foreground);
221 mog2_gold(frame, foreground_gold);
224 cv::ocl::oclMat background = createMat_ocl(rng, frame.size(), frame.type(), useRoi);
225 mog2.getBackgroundImage(background);
227 cv::Mat background_gold;
228 mog2_gold.getBackgroundImage(background_gold);
230 EXPECT_MAT_NEAR(background_gold, background, 1.0);
233 INSTANTIATE_TEST_CASE_P(OCL_Video, mog2, testing::Combine(
234 testing::Values(UseGray(true), UseGray(false)),
235 testing::Values(DetectShadow(true), DetectShadow(false)),
236 Values(true, false)));