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

« back to all changes in this revision

Viewing changes to sw/ext/opencv_bebop/opencv/modules/cudalegacy/test/TestResize.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
 
 
46
template <class T>
 
47
TestResize<T>::TestResize(std::string testName_, NCVTestSourceProvider<T> &src_,
 
48
                          Ncv32u width_, Ncv32u height_, Ncv32u scaleFactor_, NcvBool bTextureCache_)
 
49
    :
 
50
    NCVTestProvider(testName_),
 
51
    src(src_),
 
52
    width(width_),
 
53
    height(height_),
 
54
    scaleFactor(scaleFactor_),
 
55
    bTextureCache(bTextureCache_)
 
56
{
 
57
}
 
58
 
 
59
 
 
60
template <class T>
 
61
bool TestResize<T>::toString(std::ofstream &strOut)
 
62
{
 
63
    strOut << "sizeof(T)=" << sizeof(T) << std::endl;
 
64
    strOut << "width=" << width << std::endl;
 
65
    strOut << "scaleFactor=" << scaleFactor << std::endl;
 
66
    strOut << "bTextureCache=" << bTextureCache << std::endl;
 
67
    return true;
 
68
}
 
69
 
 
70
 
 
71
template <class T>
 
72
bool TestResize<T>::init()
 
73
{
 
74
    return true;
 
75
}
 
76
 
 
77
 
 
78
template <class T>
 
79
bool TestResize<T>::process()
 
80
{
 
81
    NCVStatus ncvStat;
 
82
    bool rcode = false;
 
83
 
 
84
    Ncv32s smallWidth = this->width / this->scaleFactor;
 
85
    Ncv32s smallHeight = this->height / this->scaleFactor;
 
86
    if (smallWidth == 0 || smallHeight == 0)
 
87
    {
 
88
        return true;
 
89
    }
 
90
 
 
91
    NcvSize32u srcSize(this->width, this->height);
 
92
 
 
93
    NCVMatrixAlloc<T> d_img(*this->allocatorGPU.get(), this->width, this->height);
 
94
    ncvAssertReturn(d_img.isMemAllocated(), false);
 
95
    NCVMatrixAlloc<T> h_img(*this->allocatorCPU.get(), this->width, this->height);
 
96
    ncvAssertReturn(h_img.isMemAllocated(), false);
 
97
 
 
98
    NCVMatrixAlloc<T> d_small(*this->allocatorGPU.get(), smallWidth, smallHeight);
 
99
    ncvAssertReturn(d_small.isMemAllocated(), false);
 
100
    NCVMatrixAlloc<T> h_small(*this->allocatorCPU.get(), smallWidth, smallHeight);
 
101
    ncvAssertReturn(h_small.isMemAllocated(), false);
 
102
    NCVMatrixAlloc<T> h_small_d(*this->allocatorCPU.get(), smallWidth, smallHeight);
 
103
    ncvAssertReturn(h_small_d.isMemAllocated(), false);
 
104
 
 
105
    NCV_SET_SKIP_COND(this->allocatorGPU.get()->isCounting());
 
106
    NCV_SKIP_COND_BEGIN
 
107
    ncvAssertReturn(this->src.fill(h_img), false);
 
108
    NCV_SKIP_COND_END
 
109
 
 
110
    ncvStat = h_img.copySolid(d_img, 0);
 
111
    ncvAssertReturn(ncvStat == NPPST_SUCCESS, false);
 
112
    NCV_SKIP_COND_BEGIN
 
113
    if (sizeof(T) == sizeof(Ncv32u))
 
114
    {
 
115
        ncvStat = nppiStDecimate_32u_C1R((Ncv32u *)d_img.ptr(), d_img.pitch(),
 
116
                                         (Ncv32u *)d_small.ptr(), d_small.pitch(),
 
117
                                         srcSize, this->scaleFactor,
 
118
                                         this->bTextureCache);
 
119
    }
 
120
    else if (sizeof(T) == sizeof(Ncv64u))
 
121
    {
 
122
        ncvStat = nppiStDecimate_64u_C1R((Ncv64u *)d_img.ptr(), d_img.pitch(),
 
123
                                         (Ncv64u *)d_small.ptr(), d_small.pitch(),
 
124
                                         srcSize, this->scaleFactor,
 
125
                                         this->bTextureCache);
 
126
    }
 
127
    else
 
128
    {
 
129
        ncvAssertPrintReturn(false, "Incorrect downsample test instance", false);
 
130
    }
 
131
    ncvAssertReturn(ncvStat == NPPST_SUCCESS, false);
 
132
    NCV_SKIP_COND_END
 
133
    ncvStat = d_small.copySolid(h_small_d, 0);
 
134
    ncvAssertReturn(ncvStat == NPPST_SUCCESS, false);
 
135
 
 
136
    NCV_SKIP_COND_BEGIN
 
137
    if (sizeof(T) == sizeof(Ncv32u))
 
138
    {
 
139
        ncvStat = nppiStDecimate_32u_C1R_host((Ncv32u *)h_img.ptr(), h_img.pitch(),
 
140
                                              (Ncv32u *)h_small.ptr(), h_small.pitch(),
 
141
                                              srcSize, this->scaleFactor);
 
142
    }
 
143
    else if (sizeof(T) == sizeof(Ncv64u))
 
144
    {
 
145
        ncvStat = nppiStDecimate_64u_C1R_host((Ncv64u *)h_img.ptr(), h_img.pitch(),
 
146
                                              (Ncv64u *)h_small.ptr(), h_small.pitch(),
 
147
                                              srcSize, this->scaleFactor);
 
148
    }
 
149
    else
 
150
    {
 
151
        ncvAssertPrintReturn(false, "Incorrect downsample test instance", false);
 
152
    }
 
153
    ncvAssertReturn(ncvStat == NPPST_SUCCESS, false);
 
154
    NCV_SKIP_COND_END
 
155
 
 
156
    //bit-to-bit check
 
157
    bool bLoopVirgin = true;
 
158
 
 
159
    NCV_SKIP_COND_BEGIN
 
160
    //const Ncv64f relEPS = 0.005;
 
161
    for (Ncv32u i=0; bLoopVirgin && i < h_small.height(); i++)
 
162
    {
 
163
        for (Ncv32u j=0; bLoopVirgin && j < h_small.width(); j++)
 
164
        {
 
165
            if (h_small.ptr()[h_small.stride()*i+j] != h_small_d.ptr()[h_small_d.stride()*i+j])
 
166
            {
 
167
                bLoopVirgin = false;
 
168
            }
 
169
        }
 
170
    }
 
171
    NCV_SKIP_COND_END
 
172
 
 
173
    if (bLoopVirgin)
 
174
    {
 
175
        rcode = true;
 
176
    }
 
177
 
 
178
    return rcode;
 
179
}
 
180
 
 
181
 
 
182
template <class T>
 
183
bool TestResize<T>::deinit()
 
184
{
 
185
    return true;
 
186
}
 
187
 
 
188
 
 
189
template class TestResize<Ncv32u>;
 
190
template class TestResize<Ncv64u>;