test_hogdetector.cpp 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. ///////////////////////////////////////////////////////////////////////////////////////
  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) 2010-2012, Institute Of Software Chinese Academy Of Science, all rights reserved.
  14. // Copyright (C) 2010-2012, Advanced Micro Devices, Inc., all rights reserved.
  15. // Copyright (C) 2010-2012, Multicoreware, Inc., all rights reserved.
  16. // Third party copyrights are property of their respective owners.
  17. //
  18. // @Authors
  19. // Niko Li, newlife20080214@gmail.com
  20. // Jia Haipeng, jiahaipeng95@gmail.com
  21. // Shengen Yan, yanshengen@gmail.com
  22. // Jiang Liyuan,jlyuan001.good@163.com
  23. // Rock Li, Rock.Li@amd.com
  24. // Zailong Wu, bullet@yeah.net
  25. // Yao Wang, bitwangyaoyao@gmail.com
  26. //
  27. // Redistribution and use in source and binary forms, with or without modification,
  28. // are permitted provided that the following conditions are met:
  29. //
  30. // * Redistribution's of source code must retain the above copyright notice,
  31. // this list of conditions and the following disclaimer.
  32. //
  33. // * Redistribution's in binary form must reproduce the above copyright notice,
  34. // this list of conditions and the following disclaimer in the documentation
  35. // and/or other materials provided with the distribution.
  36. //
  37. // * The name of the copyright holders may not be used to endorse or promote products
  38. // derived from this software without specific prior written permission.
  39. //
  40. // This software is provided by the copyright holders and contributors "as is" and
  41. // any express or implied warranties, including, but not limited to, the implied
  42. // warranties of merchantability and fitness for a particular purpose are disclaimed.
  43. // In no event shall the Intel Corporation or contributors be liable for any direct,
  44. // indirect, incidental, special, exemplary, or consequential damages
  45. // (including, but not limited to, procurement of substitute goods or services;
  46. // loss of use, data, or profits; or business interruption) however caused
  47. // and on any theory of liability, whether in contract, strict liability,
  48. // or tort (including negligence or otherwise) arising in any way out of
  49. // the use of this software, even if advised of the possibility of such damage.
  50. //
  51. //M*/
  52. #include "../test_precomp.hpp"
  53. #include "opencv2/ts/ocl_test.hpp"
  54. #ifdef HAVE_OPENCL
  55. namespace opencv_test {
  56. namespace ocl {
  57. ///////////////////// HOG /////////////////////////////
  58. PARAM_TEST_CASE(HOG, Size, MatType)
  59. {
  60. Size winSize;
  61. int type;
  62. Mat img;
  63. UMat uimg;
  64. virtual void SetUp()
  65. {
  66. winSize = GET_PARAM(0);
  67. type = GET_PARAM(1);
  68. img = readImage("cascadeandhog/images/image_00000000_0.png", IMREAD_GRAYSCALE);
  69. ASSERT_FALSE(img.empty());
  70. img.copyTo(uimg);
  71. }
  72. };
  73. OCL_TEST_P(HOG, GetDescriptors)
  74. {
  75. HOGDescriptor hog;
  76. hog.gammaCorrection = true;
  77. hog.setSVMDetector(hog.getDefaultPeopleDetector());
  78. std::vector<float> cpu_descriptors;
  79. std::vector<float> gpu_descriptors;
  80. OCL_OFF(hog.compute(img, cpu_descriptors, hog.winSize));
  81. OCL_ON(hog.compute(uimg, gpu_descriptors, hog.winSize));
  82. Mat cpu_desc(cpu_descriptors), gpu_desc(gpu_descriptors);
  83. EXPECT_MAT_SIMILAR(cpu_desc, gpu_desc, 1e-1);
  84. }
  85. OCL_TEST_P(HOG, SVMDetector)
  86. {
  87. HOGDescriptor hog_first, hog_second;
  88. // empty -> empty
  89. hog_first.copyTo(hog_second);
  90. // first -> both
  91. hog_first.setSVMDetector(hog_first.getDefaultPeopleDetector());
  92. hog_first.copyTo(hog_second);
  93. // both -> both
  94. hog_first.copyTo(hog_second);
  95. // second -> empty
  96. hog_first.setSVMDetector(cv::noArray());
  97. hog_first.copyTo(hog_second);
  98. }
  99. OCL_TEST_P(HOG, Detect)
  100. {
  101. HOGDescriptor hog;
  102. hog.winSize = winSize;
  103. hog.gammaCorrection = true;
  104. if (winSize.width == 48 && winSize.height == 96)
  105. hog.setSVMDetector(hog.getDaimlerPeopleDetector());
  106. else
  107. hog.setSVMDetector(hog.getDefaultPeopleDetector());
  108. std::vector<Rect> cpu_found;
  109. std::vector<Rect> gpu_found;
  110. OCL_OFF(hog.detectMultiScale(img, cpu_found, 0, Size(8, 8), Size(0, 0), 1.05, 6));
  111. OCL_ON(hog.detectMultiScale(uimg, gpu_found, 0, Size(8, 8), Size(0, 0), 1.05, 6));
  112. EXPECT_LT(checkRectSimilarity(img.size(), cpu_found, gpu_found), 0.05);
  113. }
  114. INSTANTIATE_TEST_CASE_P(OCL_ObjDetect, HOG, testing::Combine(
  115. testing::Values(Size(64, 128), Size(48, 96)),
  116. testing::Values( MatType(CV_8UC1) ) ) );
  117. }} // namespace
  118. #endif