Path: blob/master/modules/imgproc/test/ocl/test_canny.cpp
16344 views
/*M///////////////////////////////////////////////////////////////////////////////////////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, Multicoreware, Inc., all rights reserved.13// Copyright (C) 2010-2012, Advanced Micro Devices, Inc., all rights reserved.14// Third party copyrights are property of their respective owners.15//16// @Authors17// Peng Xiao, [email protected]18//19// Redistribution and use in source and binary forms, with or without modification,20// are permitted provided that the following conditions are met:21//22// * Redistribution's of source code must retain the above copyright notice,23// this list of conditions and the following disclaimer.24//25// * Redistribution's in binary form must reproduce the above copyright notice,26// this list of conditions and the following disclaimer in the documentation27// and/or other materials provided with the distribution.28//29// * The name of the copyright holders may not be used to endorse or promote products30// derived from this software without specific prior written permission.31//32// This software is provided by the copyright holders and contributors as is and33// any express or implied warranties, including, but not limited to, the implied34// warranties of merchantability and fitness for a particular purpose are disclaimed.35// In no event shall the Intel Corporation or contributors be liable for any direct,36// indirect, incidental, special, exemplary, or consequential damages37// (including, but not limited to, procurement of substitute goods or services;38// loss of use, data, or profits; or business interruption) however caused39// and on any theory of liability, whether in contract, strict liability,40// or tort (including negligence or otherwise) arising in any way out of41// the use of this software, even if advised of the possibility of such damage.42//43//M*/4445#include "../test_precomp.hpp"46#include "opencv2/ts/ocl_test.hpp"4748#ifdef HAVE_OPENCL4950namespace opencv_test {51namespace ocl {5253////////////////////////////////////////////////////////54// Canny5556IMPLEMENT_PARAM_CLASS(ApertureSize, int)57IMPLEMENT_PARAM_CLASS(L2gradient, bool)58IMPLEMENT_PARAM_CLASS(UseRoi, bool)5960PARAM_TEST_CASE(Canny, Channels, ApertureSize, L2gradient, UseRoi)61{62int cn, aperture_size;63bool useL2gradient, use_roi;6465TEST_DECLARE_INPUT_PARAMETER(src);66TEST_DECLARE_OUTPUT_PARAMETER(dst);6768virtual void SetUp()69{70cn = GET_PARAM(0);71aperture_size = GET_PARAM(1);72useL2gradient = GET_PARAM(2);73use_roi = GET_PARAM(3);74}7576void generateTestData()77{78Mat img = readImageType("shared/fruits.png", CV_8UC(cn));79ASSERT_FALSE(img.empty()) << "cann't load shared/fruits.png";8081Size roiSize = img.size();82int type = img.type();8384Border srcBorder = randomBorder(0, use_roi ? MAX_VALUE : 0);85randomSubMat(src, src_roi, roiSize, srcBorder, type, 2, 100);86img.copyTo(src_roi);8788Border dstBorder = randomBorder(0, use_roi ? MAX_VALUE : 0);89randomSubMat(dst, dst_roi, roiSize, dstBorder, type, 5, 16);9091UMAT_UPLOAD_INPUT_PARAMETER(src);92UMAT_UPLOAD_OUTPUT_PARAMETER(dst);93}94};9596OCL_TEST_P(Canny, Accuracy)97{98generateTestData();99100const double low_thresh = 50.0, high_thresh = 100.0;101double eps = 0.03;102103OCL_OFF(cv::Canny(src_roi, dst_roi, low_thresh, high_thresh, aperture_size, useL2gradient));104OCL_ON(cv::Canny(usrc_roi, udst_roi, low_thresh, high_thresh, aperture_size, useL2gradient));105106EXPECT_MAT_SIMILAR(dst_roi, udst_roi, eps);107EXPECT_MAT_SIMILAR(dst, udst, eps);108}109110OCL_TEST_P(Canny, AccuracyCustomGradient)111{112generateTestData();113114const double low_thresh = 50.0, high_thresh = 100.0;115double eps = 0.03;116117OCL_OFF(cv::Canny(src_roi, dst_roi, low_thresh, high_thresh, aperture_size, useL2gradient));118OCL_ON(119UMat dx, dy;120Sobel(usrc_roi, dx, CV_16S, 1, 0, aperture_size, 1, 0, BORDER_REPLICATE);121Sobel(usrc_roi, dy, CV_16S, 0, 1, aperture_size, 1, 0, BORDER_REPLICATE);122cv::Canny(dx, dy, udst_roi, low_thresh, high_thresh, useL2gradient);123);124125EXPECT_MAT_SIMILAR(dst_roi, udst_roi, eps);126EXPECT_MAT_SIMILAR(dst, udst, eps);127}128129OCL_INSTANTIATE_TEST_CASE_P(ImgProc, Canny, testing::Combine(130testing::Values(1, 3),131testing::Values(ApertureSize(3), ApertureSize(5)),132testing::Values(L2gradient(false), L2gradient(true)),133testing::Values(UseRoi(false), UseRoi(true))));134135} // namespace ocl136137} // namespace opencv_test138139#endif // HAVE_OPENCL140141142