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) 2000-2008, Intel Corporation, all rights reserved.
14
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
15
// Third party copyrights are property of their respective owners.
17
// Redistribution and use in source and binary forms, with or without modification,
18
// are permitted provided that the following conditions are met:
20
// * Redistribution's of source code must retain the above copyright notice,
21
// this list of conditions and the following disclaimer.
23
// * Redistribution's in binary form must reproduce the above copyright notice,
24
// this list of conditions and the following disclaimer in the documentation
25
// and/or other materials provided with the distribution.
27
// * The name of the copyright holders may not be used to endorse or promote products
28
// derived from this software without specific prior written permission.
30
// This software is provided by the copyright holders and contributors "as is" and
31
// any express or implied warranties, including, but not limited to, the implied
32
// warranties of merchantability and fitness for a particular purpose are disclaimed.
33
// In no event shall the Intel Corporation or contributors be liable for any direct,
34
// indirect, incidental, special, exemplary, or consequential damages
35
// (including, but not limited to, procurement of substitute goods or services;
36
// loss of use, data, or profits; or business interruption) however caused
37
// and on any theory of liability, whether in contract, strict liability,
38
// or tort (including negligence or otherwise) arising in any way out of
39
// the use of this software, even if advised of the possibility of such damage.
43
#include "test_precomp.hpp"
47
using namespace cvtest;
49
////////////////////////////////////////////////////////////////////////////////
52
struct MeanShift : testing::TestWithParam<cv::cuda::DeviceInfo>
54
cv::cuda::DeviceInfo devInfo;
65
cv::cuda::setDevice(devInfo.deviceID());
67
img = readImageType("meanshift/cones.png", CV_8UC4);
68
ASSERT_FALSE(img.empty());
75
CUDA_TEST_P(MeanShift, Filtering)
78
if (supportFeature(devInfo, cv::cuda::FEATURE_SET_COMPUTE_20))
79
img_template = readImage("meanshift/con_result.png");
81
img_template = readImage("meanshift/con_result_CC1X.png");
82
ASSERT_FALSE(img_template.empty());
84
cv::cuda::GpuMat d_dst;
85
cv::cuda::meanShiftFiltering(loadMat(img), d_dst, spatialRad, colorRad);
87
ASSERT_EQ(CV_8UC4, d_dst.type());
92
cv::cvtColor(dst, result, cv::COLOR_BGRA2BGR);
94
EXPECT_MAT_NEAR(img_template, result, 0.0);
97
CUDA_TEST_P(MeanShift, Proc)
100
if (supportFeature(devInfo, cv::cuda::FEATURE_SET_COMPUTE_20))
101
fs.open(std::string(cvtest::TS::ptr()->get_data_path()) + "meanshift/spmap.yaml", cv::FileStorage::READ);
103
fs.open(std::string(cvtest::TS::ptr()->get_data_path()) + "meanshift/spmap_CC1X.yaml", cv::FileStorage::READ);
104
ASSERT_TRUE(fs.isOpened());
106
cv::Mat spmap_template;
107
fs["spmap"] >> spmap_template;
108
ASSERT_FALSE(spmap_template.empty());
110
cv::cuda::GpuMat rmap_filtered;
111
cv::cuda::meanShiftFiltering(loadMat(img), rmap_filtered, spatialRad, colorRad);
113
cv::cuda::GpuMat rmap;
114
cv::cuda::GpuMat spmap;
115
cv::cuda::meanShiftProc(loadMat(img), rmap, spmap, spatialRad, colorRad);
117
ASSERT_EQ(CV_8UC4, rmap.type());
119
EXPECT_MAT_NEAR(rmap_filtered, rmap, 0.0);
120
EXPECT_MAT_NEAR(spmap_template, spmap, 0.0);
123
INSTANTIATE_TEST_CASE_P(CUDA_ImgProc, MeanShift, ALL_DEVICES);
125
////////////////////////////////////////////////////////////////////////////////
126
// MeanShiftSegmentation
130
IMPLEMENT_PARAM_CLASS(MinSize, int);
133
PARAM_TEST_CASE(MeanShiftSegmentation, cv::cuda::DeviceInfo, MinSize)
135
cv::cuda::DeviceInfo devInfo;
140
devInfo = GET_PARAM(0);
141
minsize = GET_PARAM(1);
143
cv::cuda::setDevice(devInfo.deviceID());
147
CUDA_TEST_P(MeanShiftSegmentation, Regression)
149
cv::Mat img = readImageType("meanshift/cones.png", CV_8UC4);
150
ASSERT_FALSE(img.empty());
152
std::ostringstream path;
153
path << "meanshift/cones_segmented_sp10_sr10_minsize" << minsize;
154
if (supportFeature(devInfo, cv::cuda::FEATURE_SET_COMPUTE_20))
158
cv::Mat dst_gold = readImage(path.str());
159
ASSERT_FALSE(dst_gold.empty());
162
cv::cuda::meanShiftSegmentation(loadMat(img), dst, 10, 10, minsize);
165
cv::cvtColor(dst, dst_rgb, cv::COLOR_BGRA2BGR);
167
EXPECT_MAT_SIMILAR(dst_gold, dst_rgb, 1e-3);
170
INSTANTIATE_TEST_CASE_P(CUDA_ImgProc, MeanShiftSegmentation, testing::Combine(
172
testing::Values(MinSize(0), MinSize(4), MinSize(20), MinSize(84), MinSize(340), MinSize(1364))));