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
PARAM_TEST_CASE(HistEven, cv::cuda::DeviceInfo, cv::Size)
54
cv::cuda::DeviceInfo devInfo;
59
devInfo = GET_PARAM(0);
62
cv::cuda::setDevice(devInfo.deviceID());
66
CUDA_TEST_P(HistEven, Accuracy)
68
cv::Mat src = randomMat(size, CV_8UC1);
71
float hranges[] = {50.0f, 200.0f};
73
cv::cuda::GpuMat hist;
74
cv::cuda::histEven(loadMat(src), hist, hbins, (int) hranges[0], (int) hranges[1]);
78
int histSize[] = {hbins};
79
const float* ranges[] = {hranges};
81
cv::calcHist(&src, 1, channels, cv::Mat(), hist_gold, 1, histSize, ranges);
83
hist_gold = hist_gold.t();
84
hist_gold.convertTo(hist_gold, CV_32S);
86
EXPECT_MAT_NEAR(hist_gold, hist, 0.0);
89
INSTANTIATE_TEST_CASE_P(CUDA_ImgProc, HistEven, testing::Combine(
93
///////////////////////////////////////////////////////////////////////////////////////////////////////
96
PARAM_TEST_CASE(CalcHist, cv::cuda::DeviceInfo, cv::Size)
98
cv::cuda::DeviceInfo devInfo;
104
devInfo = GET_PARAM(0);
107
cv::cuda::setDevice(devInfo.deviceID());
111
CUDA_TEST_P(CalcHist, Accuracy)
113
cv::Mat src = randomMat(size, CV_8UC1);
115
cv::cuda::GpuMat hist;
116
cv::cuda::calcHist(loadMat(src), hist);
120
const int hbins = 256;
121
const float hranges[] = {0.0f, 256.0f};
122
const int histSize[] = {hbins};
123
const float* ranges[] = {hranges};
124
const int channels[] = {0};
126
cv::calcHist(&src, 1, channels, cv::Mat(), hist_gold, 1, histSize, ranges);
127
hist_gold = hist_gold.reshape(1, 1);
128
hist_gold.convertTo(hist_gold, CV_32S);
130
EXPECT_MAT_NEAR(hist_gold, hist, 0.0);
133
INSTANTIATE_TEST_CASE_P(CUDA_ImgProc, CalcHist, testing::Combine(
137
///////////////////////////////////////////////////////////////////////////////////////////////////////
140
PARAM_TEST_CASE(EqualizeHist, cv::cuda::DeviceInfo, cv::Size)
142
cv::cuda::DeviceInfo devInfo;
147
devInfo = GET_PARAM(0);
150
cv::cuda::setDevice(devInfo.deviceID());
154
CUDA_TEST_P(EqualizeHist, Accuracy)
156
cv::Mat src = randomMat(size, CV_8UC1);
158
cv::cuda::GpuMat dst;
159
cv::cuda::equalizeHist(loadMat(src), dst);
162
cv::equalizeHist(src, dst_gold);
164
EXPECT_MAT_NEAR(dst_gold, dst, 3.0);
167
INSTANTIATE_TEST_CASE_P(CUDA_ImgProc, EqualizeHist, testing::Combine(
171
///////////////////////////////////////////////////////////////////////////////////////////////////////
176
IMPLEMENT_PARAM_CLASS(ClipLimit, double)
179
PARAM_TEST_CASE(CLAHE, cv::cuda::DeviceInfo, cv::Size, ClipLimit)
181
cv::cuda::DeviceInfo devInfo;
187
devInfo = GET_PARAM(0);
189
clipLimit = GET_PARAM(2);
191
cv::cuda::setDevice(devInfo.deviceID());
195
CUDA_TEST_P(CLAHE, Accuracy)
197
cv::Mat src = randomMat(size, CV_8UC1);
199
cv::Ptr<cv::cuda::CLAHE> clahe = cv::cuda::createCLAHE(clipLimit);
200
cv::cuda::GpuMat dst;
201
clahe->apply(loadMat(src), dst);
203
cv::Ptr<cv::CLAHE> clahe_gold = cv::createCLAHE(clipLimit);
205
clahe_gold->apply(src, dst_gold);
207
ASSERT_MAT_NEAR(dst_gold, dst, 1.0);
210
INSTANTIATE_TEST_CASE_P(CUDA_ImgProc, CLAHE, testing::Combine(
213
testing::Values(0.0, 40.0)));