1 /*M///////////////////////////////////////////////////////////////////////////////////////
3 // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
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.
11 // For Open Source Computer Vision Library
13 // Copyright (C) 2010-2012, Multicoreware, Inc., all rights reserved.
14 // Copyright (C) 2010-2012, Advanced Micro Devices, Inc., all rights reserved.
15 // Third party copyrights are property of their respective owners.
18 // Fangfang Bai, fangfang@multicorewareinc.com
19 // Jin Ma, jin@multicorewareinc.com
21 // Redistribution and use in source and binary forms, with or without modification,
22 // are permitted provided that the following conditions are met:
24 // * Redistribution's of source code must retain the above copyright notice,
25 // this list of conditions and the following disclaimer.
27 // * Redistribution's in binary form must reproduce the above copyright notice,
28 // this list of conditions and the following disclaimer in the documentation
29 // and/or other oclMaterials provided with the distribution.
31 // * The name of the copyright holders may not be used to endorse or promote products
32 // derived from this software without specific prior written permission.
34 // This software is provided by the copyright holders and contributors as is and
35 // any express or implied warranties, including, but not limited to, the implied
36 // warranties of merchantability and fitness for a particular purpose are disclaimed.
37 // In no event shall the Intel Corporation or contributors be liable for any direct,
38 // indirect, incidental, special, exemplary, or consequential damages
39 // (including, but not limited to, procurement of substitute goods or services;
40 // loss of use, data, or profits; or business interruption) however caused
41 // and on any theory of liability, whether in contract, strict liability,
42 // or tort (including negligence or otherwise) arising in any way out of
43 // the use of this software, even if advised of the possibility of such damage.
46 #include "precomp.hpp"
48 ///////////// HOG////////////////////////
49 bool match_rect(cv::Rect r1, cv::Rect r2, int threshold)
51 return ((abs(r1.x - r2.x) < threshold) && (abs(r1.y - r2.y) < threshold) &&
52 (abs(r1.width - r2.width) < threshold) && (abs(r1.height - r2.height) < threshold));
57 Mat src = imread(abspath("road.png"), cv::IMREAD_GRAYSCALE);
61 throw runtime_error("can't open road.png");
65 cv::HOGDescriptor hog;
66 hog.setSVMDetector(hog.getDefaultPeopleDetector());
67 std::vector<cv::Rect> found_locations;
68 std::vector<cv::Rect> d_found_locations;
70 SUBTEST << 768 << 'x' << 576 << "; road.png";
72 hog.detectMultiScale(src, found_locations);
75 hog.detectMultiScale(src, found_locations);
78 cv::ocl::HOGDescriptor ocl_hog;
79 ocl_hog.setSVMDetector(ocl_hog.getDefaultPeopleDetector());
84 ocl_hog.detectMultiScale(d_src, d_found_locations);
87 // Ground-truth rectangular people window
88 cv::Rect win1_64x128(231, 190, 72, 144);
89 cv::Rect win2_64x128(621, 156, 97, 194);
90 cv::Rect win1_48x96(238, 198, 63, 126);
91 cv::Rect win2_48x96(619, 161, 92, 185);
92 cv::Rect win3_48x96(488, 136, 56, 112);
94 // Compare whether ground-truth windows are detected and compare the number of windows detected.
95 std::vector<int> d_comp(4);
96 std::vector<int> comp(4);
97 for(int i = 0; i < (int)d_comp.size(); i++)
105 d_comp[0] = (int)d_found_locations.size();
106 comp[0] = (int)found_locations.size();
108 cv::Size winSize = hog.winSize;
110 if (winSize == cv::Size(48, 96))
112 for(int i = 0; i < (int)d_found_locations.size(); i++)
114 if (match_rect(d_found_locations[i], win1_48x96, threshold))
116 if (match_rect(d_found_locations[i], win2_48x96, threshold))
118 if (match_rect(d_found_locations[i], win3_48x96, threshold))
121 for(int i = 0; i < (int)found_locations.size(); i++)
123 if (match_rect(found_locations[i], win1_48x96, threshold))
125 if (match_rect(found_locations[i], win2_48x96, threshold))
127 if (match_rect(found_locations[i], win3_48x96, threshold))
131 else if (winSize == cv::Size(64, 128))
133 for(int i = 0; i < (int)d_found_locations.size(); i++)
135 if (match_rect(d_found_locations[i], win1_64x128, threshold))
137 if (match_rect(d_found_locations[i], win2_64x128, threshold))
140 for(int i = 0; i < (int)found_locations.size(); i++)
142 if (match_rect(found_locations[i], win1_64x128, threshold))
144 if (match_rect(found_locations[i], win2_64x128, threshold))
149 cv::Mat gpu_rst(d_comp), cpu_rst(comp);
150 TestSystem::instance().ExpectedMatNear(gpu_rst, cpu_rst, 3);
153 ocl_hog.detectMultiScale(d_src, found_locations);
158 ocl_hog.detectMultiScale(d_src, found_locations);