perf_objdetect.cpp 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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 "perf_precomp.hpp"
  43. namespace opencv_test { namespace {
  44. ///////////////////////////////////////////////////////////////
  45. // HOG
  46. DEF_PARAM_TEST_1(Image, string);
  47. PERF_TEST_P(Image, ObjDetect_HOG,
  48. Values<string>("gpu/hog/road.png",
  49. "gpu/caltech/image_00000009_0.png",
  50. "gpu/caltech/image_00000032_0.png",
  51. "gpu/caltech/image_00000165_0.png",
  52. "gpu/caltech/image_00000261_0.png",
  53. "gpu/caltech/image_00000469_0.png",
  54. "gpu/caltech/image_00000527_0.png",
  55. "gpu/caltech/image_00000574_0.png"))
  56. {
  57. declare.time(300.0);
  58. const cv::Mat img = readImage(GetParam(), cv::IMREAD_GRAYSCALE);
  59. ASSERT_FALSE(img.empty());
  60. if (PERF_RUN_CUDA())
  61. {
  62. const cv::cuda::GpuMat d_img(img);
  63. std::vector<cv::Rect> gpu_found_locations;
  64. cv::Ptr<cv::cuda::HOG> d_hog = cv::cuda::HOG::create();
  65. d_hog->setSVMDetector(d_hog->getDefaultPeopleDetector());
  66. TEST_CYCLE() d_hog->detectMultiScale(d_img, gpu_found_locations);
  67. SANITY_CHECK(gpu_found_locations);
  68. }
  69. else
  70. {
  71. std::vector<cv::Rect> cpu_found_locations;
  72. cv::Ptr<cv::cuda::HOG> d_hog = cv::cuda::HOG::create();
  73. cv::HOGDescriptor hog;
  74. hog.setSVMDetector(d_hog->getDefaultPeopleDetector());
  75. TEST_CYCLE() hog.detectMultiScale(img, cpu_found_locations);
  76. SANITY_CHECK(cpu_found_locations);
  77. }
  78. }
  79. ///////////////////////////////////////////////////////////////
  80. // HaarClassifier
  81. typedef pair<string, string> pair_string;
  82. DEF_PARAM_TEST_1(ImageAndCascade, pair_string);
  83. PERF_TEST_P(ImageAndCascade, ObjDetect_HaarClassifier,
  84. Values<pair_string>(make_pair("gpu/haarcascade/group_1_640x480_VGA.pgm", "gpu/perf/haarcascade_frontalface_alt.xml")))
  85. {
  86. const cv::Mat img = readImage(GetParam().first, cv::IMREAD_GRAYSCALE);
  87. ASSERT_FALSE(img.empty());
  88. if (PERF_RUN_CUDA())
  89. {
  90. cv::Ptr<cv::cuda::CascadeClassifier> d_cascade =
  91. cv::cuda::CascadeClassifier::create(perf::TestBase::getDataPath(GetParam().second));
  92. const cv::cuda::GpuMat d_img(img);
  93. cv::cuda::GpuMat objects_buffer;
  94. TEST_CYCLE() d_cascade->detectMultiScale(d_img, objects_buffer);
  95. std::vector<cv::Rect> gpu_rects;
  96. d_cascade->convert(objects_buffer, gpu_rects);
  97. cv::groupRectangles(gpu_rects, 3, 0.2);
  98. SANITY_CHECK(gpu_rects);
  99. }
  100. else
  101. {
  102. cv::CascadeClassifier cascade;
  103. ASSERT_TRUE(cascade.load(perf::TestBase::getDataPath("gpu/perf/haarcascade_frontalface_alt.xml")));
  104. std::vector<cv::Rect> cpu_rects;
  105. TEST_CYCLE() cascade.detectMultiScale(img, cpu_rects);
  106. SANITY_CHECK(cpu_rects);
  107. }
  108. }
  109. ///////////////////////////////////////////////////////////////
  110. // LBP cascade
  111. PERF_TEST_P(ImageAndCascade, ObjDetect_LBPClassifier,
  112. Values<pair_string>(make_pair("gpu/haarcascade/group_1_640x480_VGA.pgm", "gpu/lbpcascade/lbpcascade_frontalface.xml")))
  113. {
  114. const cv::Mat img = readImage(GetParam().first, cv::IMREAD_GRAYSCALE);
  115. ASSERT_FALSE(img.empty());
  116. if (PERF_RUN_CUDA())
  117. {
  118. cv::Ptr<cv::cuda::CascadeClassifier> d_cascade =
  119. cv::cuda::CascadeClassifier::create(perf::TestBase::getDataPath(GetParam().second));
  120. const cv::cuda::GpuMat d_img(img);
  121. cv::cuda::GpuMat objects_buffer;
  122. TEST_CYCLE() d_cascade->detectMultiScale(d_img, objects_buffer);
  123. std::vector<cv::Rect> gpu_rects;
  124. d_cascade->convert(objects_buffer, gpu_rects);
  125. cv::groupRectangles(gpu_rects, 3, 0.2);
  126. SANITY_CHECK(gpu_rects);
  127. }
  128. else
  129. {
  130. cv::CascadeClassifier cascade;
  131. ASSERT_TRUE(cascade.load(perf::TestBase::getDataPath("gpu/lbpcascade/lbpcascade_frontalface.xml")));
  132. std::vector<cv::Rect> cpu_rects;
  133. TEST_CYCLE() cascade.detectMultiScale(img, cpu_rects);
  134. SANITY_CHECK(cpu_rects);
  135. }
  136. }
  137. }} // namespace