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"
46
TestRectStdDev::TestRectStdDev(std::string testName_, NCVTestSourceProvider<Ncv8u> &src_,
47
Ncv32u width_, Ncv32u height_, NcvRect32u rect_, Ncv32f scaleFactor_,
48
NcvBool bTextureCache_)
50
NCVTestProvider(testName_),
55
scaleFactor(scaleFactor_),
56
bTextureCache(bTextureCache_)
61
bool TestRectStdDev::toString(std::ofstream &strOut)
63
strOut << "width=" << width << std::endl;
64
strOut << "height=" << height << std::endl;
65
strOut << "rect=[" << rect.x << ", " << rect.y << ", " << rect.width << ", " << rect.height << "]\n";
66
strOut << "scaleFactor=" << scaleFactor << std::endl;
67
strOut << "bTextureCache=" << bTextureCache << std::endl;
72
bool TestRectStdDev::init()
78
bool TestRectStdDev::process()
83
Ncv32s _normWidth = (Ncv32s)this->width - this->rect.x - this->rect.width + 1;
84
Ncv32s _normHeight = (Ncv32s)this->height - this->rect.y - this->rect.height + 1;
85
if (_normWidth <= 0 || _normHeight <= 0)
89
Ncv32u normWidth = (Ncv32u)_normWidth;
90
Ncv32u normHeight = (Ncv32u)_normHeight;
91
NcvSize32u szNormRoi(normWidth, normHeight);
93
Ncv32u widthII = this->width + 1;
94
Ncv32u heightII = this->height + 1;
95
Ncv32u widthSII = this->width + 1;
96
Ncv32u heightSII = this->height + 1;
98
NCVMatrixAlloc<Ncv8u> d_img(*this->allocatorGPU.get(), this->width, this->height);
99
ncvAssertReturn(d_img.isMemAllocated(), false);
100
NCVMatrixAlloc<Ncv8u> h_img(*this->allocatorCPU.get(), this->width, this->height);
101
ncvAssertReturn(h_img.isMemAllocated(), false);
103
NCVMatrixAlloc<Ncv32u> d_imgII(*this->allocatorGPU.get(), widthII, heightII);
104
ncvAssertReturn(d_imgII.isMemAllocated(), false);
105
NCVMatrixAlloc<Ncv32u> h_imgII(*this->allocatorCPU.get(), widthII, heightII);
106
ncvAssertReturn(h_imgII.isMemAllocated(), false);
108
NCVMatrixAlloc<Ncv64u> d_imgSII(*this->allocatorGPU.get(), widthSII, heightSII);
109
ncvAssertReturn(d_imgSII.isMemAllocated(), false);
110
NCVMatrixAlloc<Ncv64u> h_imgSII(*this->allocatorCPU.get(), widthSII, heightSII);
111
ncvAssertReturn(h_imgSII.isMemAllocated(), false);
113
NCVMatrixAlloc<Ncv32f> d_norm(*this->allocatorGPU.get(), normWidth, normHeight);
114
ncvAssertReturn(d_norm.isMemAllocated(), false);
115
NCVMatrixAlloc<Ncv32f> h_norm(*this->allocatorCPU.get(), normWidth, normHeight);
116
ncvAssertReturn(h_norm.isMemAllocated(), false);
117
NCVMatrixAlloc<Ncv32f> h_norm_d(*this->allocatorCPU.get(), normWidth, normHeight);
118
ncvAssertReturn(h_norm_d.isMemAllocated(), false);
120
Ncv32u bufSizeII, bufSizeSII;
121
ncvStat = nppiStIntegralGetSize_8u32u(NcvSize32u(this->width, this->height), &bufSizeII, this->devProp);
122
ncvAssertReturn(NPPST_SUCCESS == ncvStat, false);
123
ncvStat = nppiStSqrIntegralGetSize_8u64u(NcvSize32u(this->width, this->height), &bufSizeSII, this->devProp);
124
ncvAssertReturn(NPPST_SUCCESS == ncvStat, false);
125
Ncv32u bufSize = bufSizeII > bufSizeSII ? bufSizeII : bufSizeSII;
126
NCVVectorAlloc<Ncv8u> d_tmpBuf(*this->allocatorGPU.get(), bufSize);
127
ncvAssertReturn(d_tmpBuf.isMemAllocated(), false);
129
NCV_SET_SKIP_COND(this->allocatorGPU.get()->isCounting());
131
ncvAssertReturn(this->src.fill(h_img), false);
133
ncvStat = h_img.copySolid(d_img, 0);
134
ncvAssertReturn(ncvStat == NPPST_SUCCESS, false);
136
ncvStat = nppiStIntegral_8u32u_C1R(d_img.ptr(), d_img.pitch(),
137
d_imgII.ptr(), d_imgII.pitch(),
138
NcvSize32u(this->width, this->height),
139
d_tmpBuf.ptr(), bufSize, this->devProp);
140
ncvAssertReturn(ncvStat == NPPST_SUCCESS, false);
142
ncvStat = nppiStSqrIntegral_8u64u_C1R(d_img.ptr(), d_img.pitch(),
143
d_imgSII.ptr(), d_imgSII.pitch(),
144
NcvSize32u(this->width, this->height),
145
d_tmpBuf.ptr(), bufSize, this->devProp);
146
ncvAssertReturn(ncvStat == NPPST_SUCCESS, false);
148
ncvStat = nppiStRectStdDev_32f_C1R(d_imgII.ptr(), d_imgII.pitch(),
149
d_imgSII.ptr(), d_imgSII.pitch(),
150
d_norm.ptr(), d_norm.pitch(),
151
szNormRoi, this->rect,
153
this->bTextureCache);
154
ncvAssertReturn(ncvStat == NPPST_SUCCESS, false);
156
ncvStat = d_norm.copySolid(h_norm_d, 0);
157
ncvAssertReturn(ncvStat == NPPST_SUCCESS, false);
159
ncvStat = nppiStIntegral_8u32u_C1R_host(h_img.ptr(), h_img.pitch(),
160
h_imgII.ptr(), h_imgII.pitch(),
161
NcvSize32u(this->width, this->height));
162
ncvAssertReturn(ncvStat == NPPST_SUCCESS, false);
164
ncvStat = nppiStSqrIntegral_8u64u_C1R_host(h_img.ptr(), h_img.pitch(),
165
h_imgSII.ptr(), h_imgSII.pitch(),
166
NcvSize32u(this->width, this->height));
167
ncvAssertReturn(ncvStat == NPPST_SUCCESS, false);
169
ncvStat = nppiStRectStdDev_32f_C1R_host(h_imgII.ptr(), h_imgII.pitch(),
170
h_imgSII.ptr(), h_imgSII.pitch(),
171
h_norm.ptr(), h_norm.pitch(),
172
szNormRoi, this->rect,
174
ncvAssertReturn(ncvStat == NPPST_SUCCESS, false);
178
bool bLoopVirgin = true;
181
const Ncv64f relEPS = 0.005;
182
for (Ncv32u i=0; bLoopVirgin && i < h_norm.height(); i++)
184
for (Ncv32u j=0; bLoopVirgin && j < h_norm.width(); j++)
186
Ncv64f absErr = fabs(h_norm.ptr()[h_norm.stride()*i+j] - h_norm_d.ptr()[h_norm_d.stride()*i+j]);
187
Ncv64f relErr = absErr / h_norm.ptr()[h_norm.stride()*i+j];
206
bool TestRectStdDev::deinit()