~paparazzi-uav/paparazzi/v5.0-manual

« back to all changes in this revision

Viewing changes to sw/ext/opencv_bebop/opencv/modules/cudaimgproc/test/test_mean_shift.cpp

  • Committer: Paparazzi buildbot
  • Date: 2016-05-18 15:00:29 UTC
  • Revision ID: felix.ruess+docbot@gmail.com-20160518150029-e8lgzi5kvb4p7un9
Manual import commit 4b8bbb730080dac23cf816b98908dacfabe2a8ec from v5.0 branch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*M///////////////////////////////////////////////////////////////////////////////////////
 
2
//
 
3
//  IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
 
4
//
 
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.
 
8
//
 
9
//
 
10
//                           License Agreement
 
11
//                For Open Source Computer Vision Library
 
12
//
 
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.
 
16
//
 
17
// Redistribution and use in source and binary forms, with or without modification,
 
18
// are permitted provided that the following conditions are met:
 
19
//
 
20
//   * Redistribution's of source code must retain the above copyright notice,
 
21
//     this list of conditions and the following disclaimer.
 
22
//
 
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.
 
26
//
 
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.
 
29
//
 
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.
 
40
//
 
41
//M*/
 
42
 
 
43
#include "test_precomp.hpp"
 
44
 
 
45
#ifdef HAVE_CUDA
 
46
 
 
47
using namespace cvtest;
 
48
 
 
49
////////////////////////////////////////////////////////////////////////////////
 
50
// MeanShift
 
51
 
 
52
struct MeanShift : testing::TestWithParam<cv::cuda::DeviceInfo>
 
53
{
 
54
    cv::cuda::DeviceInfo devInfo;
 
55
 
 
56
    cv::Mat img;
 
57
 
 
58
    int spatialRad;
 
59
    int colorRad;
 
60
 
 
61
    virtual void SetUp()
 
62
    {
 
63
        devInfo = GetParam();
 
64
 
 
65
        cv::cuda::setDevice(devInfo.deviceID());
 
66
 
 
67
        img = readImageType("meanshift/cones.png", CV_8UC4);
 
68
        ASSERT_FALSE(img.empty());
 
69
 
 
70
        spatialRad = 30;
 
71
        colorRad = 30;
 
72
    }
 
73
};
 
74
 
 
75
CUDA_TEST_P(MeanShift, Filtering)
 
76
{
 
77
    cv::Mat img_template;
 
78
    if (supportFeature(devInfo, cv::cuda::FEATURE_SET_COMPUTE_20))
 
79
        img_template = readImage("meanshift/con_result.png");
 
80
    else
 
81
        img_template = readImage("meanshift/con_result_CC1X.png");
 
82
    ASSERT_FALSE(img_template.empty());
 
83
 
 
84
    cv::cuda::GpuMat d_dst;
 
85
    cv::cuda::meanShiftFiltering(loadMat(img), d_dst, spatialRad, colorRad);
 
86
 
 
87
    ASSERT_EQ(CV_8UC4, d_dst.type());
 
88
 
 
89
    cv::Mat dst(d_dst);
 
90
 
 
91
    cv::Mat result;
 
92
    cv::cvtColor(dst, result, cv::COLOR_BGRA2BGR);
 
93
 
 
94
    EXPECT_MAT_NEAR(img_template, result, 0.0);
 
95
}
 
96
 
 
97
CUDA_TEST_P(MeanShift, Proc)
 
98
{
 
99
    cv::FileStorage fs;
 
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);
 
102
    else
 
103
        fs.open(std::string(cvtest::TS::ptr()->get_data_path()) + "meanshift/spmap_CC1X.yaml", cv::FileStorage::READ);
 
104
    ASSERT_TRUE(fs.isOpened());
 
105
 
 
106
    cv::Mat spmap_template;
 
107
    fs["spmap"] >> spmap_template;
 
108
    ASSERT_FALSE(spmap_template.empty());
 
109
 
 
110
    cv::cuda::GpuMat rmap_filtered;
 
111
    cv::cuda::meanShiftFiltering(loadMat(img), rmap_filtered, spatialRad, colorRad);
 
112
 
 
113
    cv::cuda::GpuMat rmap;
 
114
    cv::cuda::GpuMat spmap;
 
115
    cv::cuda::meanShiftProc(loadMat(img), rmap, spmap, spatialRad, colorRad);
 
116
 
 
117
    ASSERT_EQ(CV_8UC4, rmap.type());
 
118
 
 
119
    EXPECT_MAT_NEAR(rmap_filtered, rmap, 0.0);
 
120
    EXPECT_MAT_NEAR(spmap_template, spmap, 0.0);
 
121
}
 
122
 
 
123
INSTANTIATE_TEST_CASE_P(CUDA_ImgProc, MeanShift, ALL_DEVICES);
 
124
 
 
125
////////////////////////////////////////////////////////////////////////////////
 
126
// MeanShiftSegmentation
 
127
 
 
128
namespace
 
129
{
 
130
    IMPLEMENT_PARAM_CLASS(MinSize, int);
 
131
}
 
132
 
 
133
PARAM_TEST_CASE(MeanShiftSegmentation, cv::cuda::DeviceInfo, MinSize)
 
134
{
 
135
    cv::cuda::DeviceInfo devInfo;
 
136
    int minsize;
 
137
 
 
138
    virtual void SetUp()
 
139
    {
 
140
        devInfo = GET_PARAM(0);
 
141
        minsize = GET_PARAM(1);
 
142
 
 
143
        cv::cuda::setDevice(devInfo.deviceID());
 
144
    }
 
145
};
 
146
 
 
147
CUDA_TEST_P(MeanShiftSegmentation, Regression)
 
148
{
 
149
    cv::Mat img = readImageType("meanshift/cones.png", CV_8UC4);
 
150
    ASSERT_FALSE(img.empty());
 
151
 
 
152
    std::ostringstream path;
 
153
    path << "meanshift/cones_segmented_sp10_sr10_minsize" << minsize;
 
154
    if (supportFeature(devInfo, cv::cuda::FEATURE_SET_COMPUTE_20))
 
155
        path << ".png";
 
156
    else
 
157
        path << "_CC1X.png";
 
158
    cv::Mat dst_gold = readImage(path.str());
 
159
    ASSERT_FALSE(dst_gold.empty());
 
160
 
 
161
    cv::Mat dst;
 
162
    cv::cuda::meanShiftSegmentation(loadMat(img), dst, 10, 10, minsize);
 
163
 
 
164
    cv::Mat dst_rgb;
 
165
    cv::cvtColor(dst, dst_rgb, cv::COLOR_BGRA2BGR);
 
166
 
 
167
    EXPECT_MAT_SIMILAR(dst_gold, dst_rgb, 1e-3);
 
168
}
 
169
 
 
170
INSTANTIATE_TEST_CASE_P(CUDA_ImgProc, MeanShiftSegmentation, testing::Combine(
 
171
    ALL_DEVICES,
 
172
    testing::Values(MinSize(0), MinSize(4), MinSize(20), MinSize(84), MinSize(340), MinSize(1364))));
 
173
 
 
174
#endif // HAVE_CUDA