TestHaarCascadeLoader.cpp 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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. TestHaarCascadeLoader::TestHaarCascadeLoader(std::string testName_, std::string cascadeName_)
  44. :
  45. NCVTestProvider(testName_),
  46. cascadeName(cascadeName_)
  47. {
  48. }
  49. bool TestHaarCascadeLoader::toString(std::ofstream &strOut)
  50. {
  51. strOut << "cascadeName=" << cascadeName << std::endl;
  52. return true;
  53. }
  54. bool TestHaarCascadeLoader::init()
  55. {
  56. return true;
  57. }
  58. bool TestHaarCascadeLoader::process()
  59. {
  60. NCVStatus ncvStat;
  61. bool rcode = false;
  62. Ncv32u numStages, numNodes, numFeatures;
  63. Ncv32u numStages_2 = 0, numNodes_2 = 0, numFeatures_2 = 0;
  64. ncvStat = ncvHaarGetClassifierSize(this->cascadeName, numStages, numNodes, numFeatures);
  65. ncvAssertReturn(ncvStat == NCV_SUCCESS, false);
  66. NCVVectorAlloc<HaarStage64> h_HaarStages(*this->allocatorCPU.get(), numStages);
  67. ncvAssertReturn(h_HaarStages.isMemAllocated(), false);
  68. NCVVectorAlloc<HaarClassifierNode128> h_HaarNodes(*this->allocatorCPU.get(), numNodes);
  69. ncvAssertReturn(h_HaarNodes.isMemAllocated(), false);
  70. NCVVectorAlloc<HaarFeature64> h_HaarFeatures(*this->allocatorCPU.get(), numFeatures);
  71. ncvAssertReturn(h_HaarFeatures.isMemAllocated(), false);
  72. NCVVectorAlloc<HaarStage64> h_HaarStages_2(*this->allocatorCPU.get(), numStages);
  73. ncvAssertReturn(h_HaarStages_2.isMemAllocated(), false);
  74. NCVVectorAlloc<HaarClassifierNode128> h_HaarNodes_2(*this->allocatorCPU.get(), numNodes);
  75. ncvAssertReturn(h_HaarNodes_2.isMemAllocated(), false);
  76. NCVVectorAlloc<HaarFeature64> h_HaarFeatures_2(*this->allocatorCPU.get(), numFeatures);
  77. ncvAssertReturn(h_HaarFeatures_2.isMemAllocated(), false);
  78. HaarClassifierCascadeDescriptor haar;
  79. HaarClassifierCascadeDescriptor haar_2;
  80. NCV_SET_SKIP_COND(this->allocatorGPU.get()->isCounting());
  81. NCV_SKIP_COND_BEGIN
  82. const std::string testNvbinName = cv::tempfile("test.nvbin");
  83. ncvStat = ncvHaarLoadFromFile_host(this->cascadeName, haar, h_HaarStages, h_HaarNodes, h_HaarFeatures);
  84. ncvAssertReturn(ncvStat == NCV_SUCCESS, false);
  85. ncvStat = ncvHaarStoreNVBIN_host(testNvbinName, haar, h_HaarStages, h_HaarNodes, h_HaarFeatures);
  86. ncvAssertReturn(ncvStat == NCV_SUCCESS, false);
  87. ncvStat = ncvHaarGetClassifierSize(testNvbinName, numStages_2, numNodes_2, numFeatures_2);
  88. ncvAssertReturn(ncvStat == NCV_SUCCESS, false);
  89. ncvStat = ncvHaarLoadFromFile_host(testNvbinName, haar_2, h_HaarStages_2, h_HaarNodes_2, h_HaarFeatures_2);
  90. ncvAssertReturn(ncvStat == NCV_SUCCESS, false);
  91. NCV_SKIP_COND_END
  92. //bit-to-bit check
  93. bool bLoopVirgin = true;
  94. NCV_SKIP_COND_BEGIN
  95. if (
  96. numStages_2 != numStages ||
  97. numNodes_2 != numNodes ||
  98. numFeatures_2 != numFeatures ||
  99. haar.NumStages != haar_2.NumStages ||
  100. haar.NumClassifierRootNodes != haar_2.NumClassifierRootNodes ||
  101. haar.NumClassifierTotalNodes != haar_2.NumClassifierTotalNodes ||
  102. haar.NumFeatures != haar_2.NumFeatures ||
  103. haar.ClassifierSize.width != haar_2.ClassifierSize.width ||
  104. haar.ClassifierSize.height != haar_2.ClassifierSize.height ||
  105. haar.bNeedsTiltedII != haar_2.bNeedsTiltedII ||
  106. haar.bHasStumpsOnly != haar_2.bHasStumpsOnly )
  107. {
  108. bLoopVirgin = false;
  109. }
  110. if (memcmp(h_HaarStages.ptr(), h_HaarStages_2.ptr(), haar.NumStages * sizeof(HaarStage64)) ||
  111. memcmp(h_HaarNodes.ptr(), h_HaarNodes_2.ptr(), haar.NumClassifierTotalNodes * sizeof(HaarClassifierNode128)) ||
  112. memcmp(h_HaarFeatures.ptr(), h_HaarFeatures_2.ptr(), haar.NumFeatures * sizeof(HaarFeature64)) )
  113. {
  114. bLoopVirgin = false;
  115. }
  116. NCV_SKIP_COND_END
  117. if (bLoopVirgin)
  118. {
  119. rcode = true;
  120. }
  121. return rcode;
  122. }
  123. bool TestHaarCascadeLoader::deinit()
  124. {
  125. return true;
  126. }