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