test_histogram.cpp 6.01 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
/*M///////////////////////////////////////////////////////////////////////////////////////
//
//  IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
//
//  By downloading, copying, installing or using the software you agree to this license.
//  If you do not agree to this license, do not download, install,
//  copy or use the software.
//
//
//                           License Agreement
//                For Open Source Computer Vision Library
//
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
// Third party copyrights are property of their respective owners.
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
//   * Redistribution's of source code must retain the above copyright notice,
//     this list of conditions and the following disclaimer.
//
//   * Redistribution's in binary form must reproduce the above copyright notice,
//     this list of conditions and the following disclaimer in the documentation
//     and/or other materials provided with the distribution.
//
//   * The name of the copyright holders may not be used to endorse or promote products
//     derived from this software without specific prior written permission.
//
// This software is provided by the copyright holders and contributors "as is" and
// any express or implied warranties, including, but not limited to, the implied
// warranties of merchantability and fitness for a particular purpose are disclaimed.
// In no event shall the Intel Corporation or contributors be liable for any direct,
// indirect, incidental, special, exemplary, or consequential damages
// (including, but not limited to, procurement of substitute goods or services;
// loss of use, data, or profits; or business interruption) however caused
// and on any theory of liability, whether in contract, strict liability,
// or tort (including negligence or otherwise) arising in any way out of
// the use of this software, even if advised of the possibility of such damage.
//
//M*/

#include "test_precomp.hpp"

#ifdef HAVE_CUDA

using namespace cvtest;

///////////////////////////////////////////////////////////////////////////////////////////////////////
// HistEven

52
PARAM_TEST_CASE(HistEven, cv::cuda::DeviceInfo, cv::Size)
53
{
54
    cv::cuda::DeviceInfo devInfo;
Vladislav Vinogradov's avatar
Vladislav Vinogradov committed
55
    cv::Size size;
56 57 58

    virtual void SetUp()
    {
59 60
        devInfo = GET_PARAM(0);
        size = GET_PARAM(1);
61

62
        cv::cuda::setDevice(devInfo.deviceID());
63 64 65
    }
};

66
CUDA_TEST_P(HistEven, Accuracy)
67
{
68
    cv::Mat src = randomMat(size, CV_8UC1);
69 70

    int hbins = 30;
71
    float hranges[] = {50.0f, 200.0f};
72

73 74
    cv::cuda::GpuMat hist;
    cv::cuda::histEven(loadMat(src), hist, hbins, (int) hranges[0], (int) hranges[1]);
75 76

    cv::Mat hist_gold;
77 78 79 80

    int histSize[] = {hbins};
    const float* ranges[] = {hranges};
    int channels[] = {0};
81
    cv::calcHist(&src, 1, channels, cv::Mat(), hist_gold, 1, histSize, ranges);
82 83 84 85 86 87 88

    hist_gold = hist_gold.t();
    hist_gold.convertTo(hist_gold, CV_32S);

    EXPECT_MAT_NEAR(hist_gold, hist, 0.0);
}

89
INSTANTIATE_TEST_CASE_P(CUDA_ImgProc, HistEven, testing::Combine(
90 91
    ALL_DEVICES,
    DIFFERENT_SIZES));
92 93 94 95

///////////////////////////////////////////////////////////////////////////////////////////////////////
// CalcHist

96
PARAM_TEST_CASE(CalcHist, cv::cuda::DeviceInfo, cv::Size)
97
{
98
    cv::cuda::DeviceInfo devInfo;
99 100 101 102 103 104 105 106

    cv::Size size;

    virtual void SetUp()
    {
        devInfo = GET_PARAM(0);
        size = GET_PARAM(1);

107
        cv::cuda::setDevice(devInfo.deviceID());
108 109 110
    }
};

111
CUDA_TEST_P(CalcHist, Accuracy)
112 113 114
{
    cv::Mat src = randomMat(size, CV_8UC1);

115 116
    cv::cuda::GpuMat hist;
    cv::cuda::calcHist(loadMat(src), hist);
117 118

    cv::Mat hist_gold;
119 120 121 122 123 124 125 126 127 128

    const int hbins = 256;
    const float hranges[] = {0.0f, 256.0f};
    const int histSize[] = {hbins};
    const float* ranges[] = {hranges};
    const int channels[] = {0};

    cv::calcHist(&src, 1, channels, cv::Mat(), hist_gold, 1, histSize, ranges);
    hist_gold = hist_gold.reshape(1, 1);
    hist_gold.convertTo(hist_gold, CV_32S);
129 130 131 132

    EXPECT_MAT_NEAR(hist_gold, hist, 0.0);
}

133
INSTANTIATE_TEST_CASE_P(CUDA_ImgProc, CalcHist, testing::Combine(
134 135 136 137 138 139
    ALL_DEVICES,
    DIFFERENT_SIZES));

///////////////////////////////////////////////////////////////////////////////////////////////////////
// EqualizeHist

140
PARAM_TEST_CASE(EqualizeHist, cv::cuda::DeviceInfo, cv::Size)
141
{
142
    cv::cuda::DeviceInfo devInfo;
143 144 145 146 147 148 149
    cv::Size size;

    virtual void SetUp()
    {
        devInfo = GET_PARAM(0);
        size = GET_PARAM(1);

150
        cv::cuda::setDevice(devInfo.deviceID());
151 152 153
    }
};

154
CUDA_TEST_P(EqualizeHist, Accuracy)
155 156 157
{
    cv::Mat src = randomMat(size, CV_8UC1);

158 159
    cv::cuda::GpuMat dst;
    cv::cuda::equalizeHist(loadMat(src), dst);
160 161 162 163 164 165 166

    cv::Mat dst_gold;
    cv::equalizeHist(src, dst_gold);

    EXPECT_MAT_NEAR(dst_gold, dst, 3.0);
}

167
INSTANTIATE_TEST_CASE_P(CUDA_ImgProc, EqualizeHist, testing::Combine(
168 169 170 171 172 173 174 175 176 177 178
    ALL_DEVICES,
    DIFFERENT_SIZES));

///////////////////////////////////////////////////////////////////////////////////////////////////////
// CLAHE

namespace
{
    IMPLEMENT_PARAM_CLASS(ClipLimit, double)
}

179
PARAM_TEST_CASE(CLAHE, cv::cuda::DeviceInfo, cv::Size, ClipLimit)
180
{
181
    cv::cuda::DeviceInfo devInfo;
182 183 184 185 186 187 188 189 190
    cv::Size size;
    double clipLimit;

    virtual void SetUp()
    {
        devInfo = GET_PARAM(0);
        size = GET_PARAM(1);
        clipLimit = GET_PARAM(2);

191
        cv::cuda::setDevice(devInfo.deviceID());
192 193 194
    }
};

195
CUDA_TEST_P(CLAHE, Accuracy)
196 197 198
{
    cv::Mat src = randomMat(size, CV_8UC1);

199 200
    cv::Ptr<cv::cuda::CLAHE> clahe = cv::cuda::createCLAHE(clipLimit);
    cv::cuda::GpuMat dst;
201 202 203 204 205 206 207 208 209
    clahe->apply(loadMat(src), dst);

    cv::Ptr<cv::CLAHE> clahe_gold = cv::createCLAHE(clipLimit);
    cv::Mat dst_gold;
    clahe_gold->apply(src, dst_gold);

    ASSERT_MAT_NEAR(dst_gold, dst, 1.0);
}

210
INSTANTIATE_TEST_CASE_P(CUDA_ImgProc, CLAHE, testing::Combine(
211 212 213 214 215
    ALL_DEVICES,
    DIFFERENT_SIZES,
    testing::Values(0.0, 40.0)));

#endif // HAVE_CUDA