Home | History | Annotate | Download | only in test
      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 TestRectStdDev::TestRectStdDev(std::string testName_, NCVTestSourceProvider<Ncv8u> &src_,
     47                                Ncv32u width_, Ncv32u height_, NcvRect32u rect_, Ncv32f scaleFactor_,
     48                                NcvBool bTextureCache_)
     49     :
     50     NCVTestProvider(testName_),
     51     src(src_),
     52     width(width_),
     53     height(height_),
     54     rect(rect_),
     55     scaleFactor(scaleFactor_),
     56     bTextureCache(bTextureCache_)
     57 {
     58 }
     59 
     60 
     61 bool TestRectStdDev::toString(std::ofstream &strOut)
     62 {
     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;
     68     return true;
     69 }
     70 
     71 
     72 bool TestRectStdDev::init()
     73 {
     74     return true;
     75 }
     76 
     77 
     78 bool TestRectStdDev::process()
     79 {
     80     NCVStatus ncvStat;
     81     bool rcode = false;
     82 
     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)
     86     {
     87         return true;
     88     }
     89     Ncv32u normWidth = (Ncv32u)_normWidth;
     90     Ncv32u normHeight = (Ncv32u)_normHeight;
     91     NcvSize32u szNormRoi(normWidth, normHeight);
     92 
     93     Ncv32u widthII = this->width + 1;
     94     Ncv32u heightII = this->height + 1;
     95     Ncv32u widthSII = this->width + 1;
     96     Ncv32u heightSII = this->height + 1;
     97 
     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);
    102 
    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);
    107 
    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);
    112 
    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);
    119 
    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);
    128 
    129     NCV_SET_SKIP_COND(this->allocatorGPU.get()->isCounting());
    130     NCV_SKIP_COND_BEGIN
    131     ncvAssertReturn(this->src.fill(h_img), false);
    132 
    133     ncvStat = h_img.copySolid(d_img, 0);
    134     ncvAssertReturn(ncvStat == NPPST_SUCCESS, false);
    135 
    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);
    141 
    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);
    147 
    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,
    152                                        this->scaleFactor,
    153                                        this->bTextureCache);
    154     ncvAssertReturn(ncvStat == NPPST_SUCCESS, false);
    155 
    156     ncvStat = d_norm.copySolid(h_norm_d, 0);
    157     ncvAssertReturn(ncvStat == NPPST_SUCCESS, false);
    158 
    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);
    163 
    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);
    168 
    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,
    173                                           this->scaleFactor);
    174     ncvAssertReturn(ncvStat == NPPST_SUCCESS, false);
    175     NCV_SKIP_COND_END
    176 
    177     //bit-to-bit check
    178     bool bLoopVirgin = true;
    179 
    180     NCV_SKIP_COND_BEGIN
    181     const Ncv64f relEPS = 0.005;
    182     for (Ncv32u i=0; bLoopVirgin && i < h_norm.height(); i++)
    183     {
    184         for (Ncv32u j=0; bLoopVirgin && j < h_norm.width(); j++)
    185         {
    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];
    188 
    189             if (relErr > relEPS)
    190             {
    191                 bLoopVirgin = false;
    192             }
    193         }
    194     }
    195     NCV_SKIP_COND_END
    196 
    197     if (bLoopVirgin)
    198     {
    199         rcode = true;
    200     }
    201 
    202     return rcode;
    203 }
    204 
    205 
    206 bool TestRectStdDev::deinit()
    207 {
    208     return true;
    209 }
    210