Path: blob/master/modules/objdetect/test/opencl/test_hogdetector.cpp
16337 views
///////////////////////////////////////////////////////////////////////////////////////1//2// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.3//4// By downloading, copying, installing or using the software you agree to this license.5// If you do not agree to this license, do not download, install,6// copy or use the software.7//8//9// License Agreement10// For Open Source Computer Vision Library11//12// Copyright (C) 2010-2012, Institute Of Software Chinese Academy Of Science, all rights reserved.13// Copyright (C) 2010-2012, Advanced Micro Devices, Inc., all rights reserved.14// Copyright (C) 2010-2012, Multicoreware, Inc., all rights reserved.15// Third party copyrights are property of their respective owners.16//17// @Authors18// Niko Li, [email protected]19// Jia Haipeng, [email protected]20// Shengen Yan, [email protected]21// Jiang Liyuan,[email protected]22// Rock Li, [email protected]23// Zailong Wu, [email protected]24// Yao Wang, [email protected]25//26// Redistribution and use in source and binary forms, with or without modification,27// are permitted provided that the following conditions are met:28//29// * Redistribution's of source code must retain the above copyright notice,30// this list of conditions and the following disclaimer.31//32// * Redistribution's in binary form must reproduce the above copyright notice,33// this list of conditions and the following disclaimer in the documentation34// and/or other materials provided with the distribution.35//36// * The name of the copyright holders may not be used to endorse or promote products37// derived from this software without specific prior written permission.38//39// This software is provided by the copyright holders and contributors "as is" and40// any express or implied warranties, including, but not limited to, the implied41// warranties of merchantability and fitness for a particular purpose are disclaimed.42// In no event shall the Intel Corporation or contributors be liable for any direct,43// indirect, incidental, special, exemplary, or consequential damages44// (including, but not limited to, procurement of substitute goods or services;45// loss of use, data, or profits; or business interruption) however caused46// and on any theory of liability, whether in contract, strict liability,47// or tort (including negligence or otherwise) arising in any way out of48// the use of this software, even if advised of the possibility of such damage.49//50//M*/5152#include "../test_precomp.hpp"53#include "opencv2/ts/ocl_test.hpp"5455#ifdef HAVE_OPENCL5657namespace opencv_test {58namespace ocl {5960///////////////////// HOG /////////////////////////////61PARAM_TEST_CASE(HOG, Size, MatType)62{63Size winSize;64int type;65Mat img;66UMat uimg;67virtual void SetUp()68{69winSize = GET_PARAM(0);70type = GET_PARAM(1);71img = readImage("cascadeandhog/images/image_00000000_0.png", IMREAD_GRAYSCALE);72ASSERT_FALSE(img.empty());73img.copyTo(uimg);74}75};7677OCL_TEST_P(HOG, GetDescriptors)78{79HOGDescriptor hog;80hog.gammaCorrection = true;8182hog.setSVMDetector(hog.getDefaultPeopleDetector());8384std::vector<float> cpu_descriptors;85std::vector<float> gpu_descriptors;8687OCL_OFF(hog.compute(img, cpu_descriptors, hog.winSize));88OCL_ON(hog.compute(uimg, gpu_descriptors, hog.winSize));8990Mat cpu_desc(cpu_descriptors), gpu_desc(gpu_descriptors);9192EXPECT_MAT_SIMILAR(cpu_desc, gpu_desc, 1e-1);93}9495OCL_TEST_P(HOG, Detect)96{97HOGDescriptor hog;98hog.winSize = winSize;99hog.gammaCorrection = true;100101if (winSize.width == 48 && winSize.height == 96)102hog.setSVMDetector(hog.getDaimlerPeopleDetector());103else104hog.setSVMDetector(hog.getDefaultPeopleDetector());105106std::vector<Rect> cpu_found;107std::vector<Rect> gpu_found;108109OCL_OFF(hog.detectMultiScale(img, cpu_found, 0, Size(8, 8), Size(0, 0), 1.05, 6));110OCL_ON(hog.detectMultiScale(uimg, gpu_found, 0, Size(8, 8), Size(0, 0), 1.05, 6));111112EXPECT_LT(checkRectSimilarity(img.size(), cpu_found, gpu_found), 0.05);113}114115INSTANTIATE_TEST_CASE_P(OCL_ObjDetect, HOG, testing::Combine(116testing::Values(Size(64, 128), Size(48, 96)),117testing::Values( MatType(CV_8UC1) ) ) );118119}} // namespace120#endif121122123