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 template <class T_in, class T_out>
     47 TestIntegralImage<T_in, T_out>::TestIntegralImage(std::string testName_, NCVTestSourceProvider<T_in> &src_,
     48                                                   Ncv32u width_, Ncv32u height_)
     49     :
     50     NCVTestProvider(testName_),
     51     src(src_),
     52     width(width_),
     53     height(height_)
     54 {
     55 }
     56 
     57 
     58 template <class T_in, class T_out>
     59 bool TestIntegralImage<T_in, T_out>::toString(std::ofstream &strOut)
     60 {
     61     strOut << "sizeof(T_in)=" << sizeof(T_in) << std::endl;
     62     strOut << "sizeof(T_out)=" << sizeof(T_out) << std::endl;
     63     strOut << "width=" << width << std::endl;
     64     strOut << "height=" << height << std::endl;
     65     return true;
     66 }
     67 
     68 
     69 template <class T_in, class T_out>
     70 bool TestIntegralImage<T_in, T_out>::init()
     71 {
     72     return true;
     73 }
     74 
     75 
     76 template <class T_in, class T_out>
     77 bool TestIntegralImage<T_in, T_out>::process()
     78 {
     79     NCVStatus ncvStat;
     80     bool rcode = false;
     81 
     82     Ncv32u widthII = this->width + 1;
     83     Ncv32u heightII = this->height + 1;
     84 
     85     NCVMatrixAlloc<T_in> d_img(*this->allocatorGPU.get(), this->width, this->height);
     86     ncvAssertReturn(d_img.isMemAllocated(), false);
     87     NCVMatrixAlloc<T_in> h_img(*this->allocatorCPU.get(), this->width, this->height);
     88     ncvAssertReturn(h_img.isMemAllocated(), false);
     89     NCVMatrixAlloc<T_out> d_imgII(*this->allocatorGPU.get(), widthII, heightII);
     90     ncvAssertReturn(d_imgII.isMemAllocated(), false);
     91     NCVMatrixAlloc<T_out> h_imgII(*this->allocatorCPU.get(), widthII, heightII);
     92     ncvAssertReturn(h_imgII.isMemAllocated(), false);
     93     NCVMatrixAlloc<T_out> h_imgII_d(*this->allocatorCPU.get(), widthII, heightII);
     94     ncvAssertReturn(h_imgII_d.isMemAllocated(), false);
     95 
     96     Ncv32u bufSize;
     97     if (sizeof(T_in) == sizeof(Ncv8u))
     98     {
     99         ncvStat = nppiStIntegralGetSize_8u32u(NcvSize32u(this->width, this->height), &bufSize, this->devProp);
    100         ncvAssertReturn(NPPST_SUCCESS == ncvStat, false);
    101     }
    102     else if (sizeof(T_in) == sizeof(Ncv32f))
    103     {
    104         ncvStat = nppiStIntegralGetSize_32f32f(NcvSize32u(this->width, this->height), &bufSize, this->devProp);
    105         ncvAssertReturn(NPPST_SUCCESS == ncvStat, false);
    106     }
    107     else
    108     {
    109         ncvAssertPrintReturn(false, "Incorrect integral image test instance", false);
    110     }
    111 
    112     NCVVectorAlloc<Ncv8u> d_tmpBuf(*this->allocatorGPU.get(), bufSize);
    113     ncvAssertReturn(d_tmpBuf.isMemAllocated(), false);
    114 
    115     NCV_SET_SKIP_COND(this->allocatorGPU.get()->isCounting());
    116     NCV_SKIP_COND_BEGIN
    117 
    118     ncvAssertReturn(this->src.fill(h_img), false);
    119 
    120     ncvStat = h_img.copySolid(d_img, 0);
    121     ncvAssertReturn(ncvStat == NPPST_SUCCESS, false);
    122 
    123     if (sizeof(T_in) == sizeof(Ncv8u))
    124     {
    125         ncvStat = nppiStIntegral_8u32u_C1R((Ncv8u *)d_img.ptr(), d_img.pitch(),
    126                                            (Ncv32u *)d_imgII.ptr(), d_imgII.pitch(),
    127                                            NcvSize32u(this->width, this->height),
    128                                            d_tmpBuf.ptr(), bufSize, this->devProp);
    129         ncvAssertReturn(ncvStat == NPPST_SUCCESS, false);
    130     }
    131     else if (sizeof(T_in) == sizeof(Ncv32f))
    132     {
    133         ncvStat = nppiStIntegral_32f32f_C1R((Ncv32f *)d_img.ptr(), d_img.pitch(),
    134                                             (Ncv32f *)d_imgII.ptr(), d_imgII.pitch(),
    135                                             NcvSize32u(this->width, this->height),
    136                                             d_tmpBuf.ptr(), bufSize, this->devProp);
    137         ncvAssertReturn(ncvStat == NPPST_SUCCESS, false);
    138     }
    139     else
    140     {
    141         ncvAssertPrintReturn(false, "Incorrect integral image test instance", false);
    142     }
    143 
    144     ncvStat = d_imgII.copySolid(h_imgII_d, 0);
    145     ncvAssertReturn(ncvStat == NPPST_SUCCESS, false);
    146 
    147     if (sizeof(T_in) == sizeof(Ncv8u))
    148     {
    149         ncvStat = nppiStIntegral_8u32u_C1R_host((Ncv8u *)h_img.ptr(), h_img.pitch(),
    150                                                 (Ncv32u *)h_imgII.ptr(), h_imgII.pitch(),
    151                                                 NcvSize32u(this->width, this->height));
    152         ncvAssertReturn(ncvStat == NPPST_SUCCESS, false);
    153     }
    154     else if (sizeof(T_in) == sizeof(Ncv32f))
    155     {
    156         ncvStat = nppiStIntegral_32f32f_C1R_host((Ncv32f *)h_img.ptr(), h_img.pitch(),
    157                                                  (Ncv32f *)h_imgII.ptr(), h_imgII.pitch(),
    158                                                  NcvSize32u(this->width, this->height));
    159         ncvAssertReturn(ncvStat == NPPST_SUCCESS, false);
    160     }
    161     else
    162     {
    163         ncvAssertPrintReturn(false, "Incorrect integral image test instance", false);
    164     }
    165 
    166     NCV_SKIP_COND_END
    167 
    168     //bit-to-bit check
    169     bool bLoopVirgin = true;
    170 
    171     NCV_SKIP_COND_BEGIN
    172     for (Ncv32u i=0; bLoopVirgin && i < h_img.height() + 1; i++)
    173     {
    174         for (Ncv32u j=0; bLoopVirgin && j < h_img.width() + 1; j++)
    175         {
    176             if (sizeof(T_in) == sizeof(Ncv8u))
    177             {
    178                 if (h_imgII.ptr()[h_imgII.stride()*i+j] != h_imgII_d.ptr()[h_imgII_d.stride()*i+j])
    179                 {
    180                     bLoopVirgin = false;
    181                 }
    182             }
    183             else if (sizeof(T_in) == sizeof(Ncv32f))
    184             {
    185                 if (fabsf((float)h_imgII.ptr()[h_imgII.stride()*i+j] - (float)h_imgII_d.ptr()[h_imgII_d.stride()*i+j]) > 0.01f)
    186                 {
    187                     bLoopVirgin = false;
    188                 }
    189             }
    190             else
    191             {
    192                 ncvAssertPrintReturn(false, "Incorrect integral image test instance", false);
    193             }
    194         }
    195     }
    196     NCV_SKIP_COND_END
    197 
    198     if (bLoopVirgin)
    199     {
    200         rcode = true;
    201     }
    202 
    203     return rcode;
    204 }
    205 
    206 
    207 template <class T_in, class T_out>
    208 bool TestIntegralImage<T_in, T_out>::deinit()
    209 {
    210     return true;
    211 }
    212 
    213 
    214 template class TestIntegralImage<Ncv8u, Ncv32u>;
    215 template class TestIntegralImage<Ncv32f, Ncv32f>;
    216