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 TestIntegralImageSquared::TestIntegralImageSquared(std::string testName_, NCVTestSourceProvider<Ncv8u> &src_, 47 Ncv32u width_, Ncv32u height_) 48 : 49 NCVTestProvider(testName_), 50 src(src_), 51 width(width_), 52 height(height_) 53 { 54 } 55 56 57 bool TestIntegralImageSquared::toString(std::ofstream &strOut) 58 { 59 strOut << "width=" << width << std::endl; 60 strOut << "height=" << height << std::endl; 61 return true; 62 } 63 64 65 bool TestIntegralImageSquared::init() 66 { 67 return true; 68 } 69 70 71 bool TestIntegralImageSquared::process() 72 { 73 NCVStatus ncvStat; 74 bool rcode = false; 75 76 Ncv32u widthSII = this->width + 1; 77 Ncv32u heightSII = this->height + 1; 78 79 NCVMatrixAlloc<Ncv8u> d_img(*this->allocatorGPU.get(), this->width, this->height); 80 ncvAssertReturn(d_img.isMemAllocated(), false); 81 NCVMatrixAlloc<Ncv8u> h_img(*this->allocatorCPU.get(), this->width, this->height); 82 ncvAssertReturn(h_img.isMemAllocated(), false); 83 NCVMatrixAlloc<Ncv64u> d_imgSII(*this->allocatorGPU.get(), widthSII, heightSII); 84 ncvAssertReturn(d_imgSII.isMemAllocated(), false); 85 NCVMatrixAlloc<Ncv64u> h_imgSII(*this->allocatorCPU.get(), widthSII, heightSII); 86 ncvAssertReturn(h_imgSII.isMemAllocated(), false); 87 NCVMatrixAlloc<Ncv64u> h_imgSII_d(*this->allocatorCPU.get(), widthSII, heightSII); 88 ncvAssertReturn(h_imgSII_d.isMemAllocated(), false); 89 90 Ncv32u bufSize; 91 ncvStat = nppiStSqrIntegralGetSize_8u64u(NcvSize32u(this->width, this->height), &bufSize, this->devProp); 92 ncvAssertReturn(NPPST_SUCCESS == ncvStat, false); 93 NCVVectorAlloc<Ncv8u> d_tmpBuf(*this->allocatorGPU.get(), bufSize); 94 ncvAssertReturn(d_tmpBuf.isMemAllocated(), false); 95 96 NCV_SET_SKIP_COND(this->allocatorGPU.get()->isCounting()); 97 NCV_SKIP_COND_BEGIN 98 99 ncvAssertReturn(this->src.fill(h_img), false); 100 101 ncvStat = h_img.copySolid(d_img, 0); 102 ncvAssertReturn(ncvStat == NPPST_SUCCESS, false); 103 104 ncvStat = nppiStSqrIntegral_8u64u_C1R(d_img.ptr(), d_img.pitch(), 105 d_imgSII.ptr(), d_imgSII.pitch(), 106 NcvSize32u(this->width, this->height), 107 d_tmpBuf.ptr(), bufSize, this->devProp); 108 ncvAssertReturn(ncvStat == NPPST_SUCCESS, false); 109 110 ncvStat = d_imgSII.copySolid(h_imgSII_d, 0); 111 ncvAssertReturn(ncvStat == NPPST_SUCCESS, false); 112 113 ncvStat = nppiStSqrIntegral_8u64u_C1R_host(h_img.ptr(), h_img.pitch(), 114 h_imgSII.ptr(), h_imgSII.pitch(), 115 NcvSize32u(this->width, this->height)); 116 ncvAssertReturn(ncvStat == NPPST_SUCCESS, false); 117 118 NCV_SKIP_COND_END 119 120 //bit-to-bit check 121 bool bLoopVirgin = true; 122 123 NCV_SKIP_COND_BEGIN 124 for (Ncv32u i=0; bLoopVirgin && i < h_img.height() + 1; i++) 125 { 126 for (Ncv32u j=0; bLoopVirgin && j < h_img.width() + 1; j++) 127 { 128 if (h_imgSII.ptr()[h_imgSII.stride()*i+j] != h_imgSII_d.ptr()[h_imgSII_d.stride()*i+j]) 129 { 130 bLoopVirgin = false; 131 } 132 } 133 } 134 NCV_SKIP_COND_END 135 136 if (bLoopVirgin) 137 { 138 rcode = true; 139 } 140 141 return rcode; 142 } 143 144 145 bool TestIntegralImageSquared::deinit() 146 { 147 return true; 148 } 149