TestIntegralImageSquared.cpp 5.4 KB

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