Path: blob/master/modules/imgproc/test/ocl/test_gftt.cpp
16344 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// Copyright (C) 2010-2012, Multicoreware, Inc., all rights reserved.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// Third party copyrights are property of their respective owners.15//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 documentation25// and/or other materials provided with the distribution.26//27// * The name of the copyright holders may not be used to endorse or promote products28// derived from this software without specific prior written permission.29//30// This software is provided by the copyright holders and contributors "as is" and31// any express or implied warranties, including, but not limited to, the implied32// 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 damages35// (including, but not limited to, procurement of substitute goods or services;36// loss of use, data, or profits; or business interruption) however caused37// and on any theory of liability, whether in contract, strict liability,38// or tort (including negligence or otherwise) arising in any way out of39// the use of this software, even if advised of the possibility of such damage.40//41//M*/4243#include "../test_precomp.hpp"44#include "opencv2/ts/ocl_test.hpp"4546#ifdef HAVE_OPENCL4748namespace opencv_test {49namespace ocl {5051//////////////////////////// GoodFeaturesToTrack //////////////////////////525354PARAM_TEST_CASE(GoodFeaturesToTrack, double, bool)55{56double minDistance;57bool useRoi;5859static const int maxCorners;60static const double qualityLevel;6162TEST_DECLARE_INPUT_PARAMETER(src);63UMat points, upoints;6465virtual void SetUp()66{67minDistance = GET_PARAM(0);68useRoi = GET_PARAM(1);69}7071void generateTestData()72{73Mat frame = readImage("../gpu/opticalflow/rubberwhale1.png", IMREAD_GRAYSCALE);74ASSERT_FALSE(frame.empty()) << "could not load gpu/opticalflow/rubberwhale1.png";7576Size roiSize = frame.size();77Border srcBorder = randomBorder(0, useRoi ? 2 : 0);78randomSubMat(src, src_roi, roiSize, srcBorder, frame.type(), 5, 256);79src_roi.copyTo(frame);8081UMAT_UPLOAD_INPUT_PARAMETER(src);82}8384void UMatToVector(const UMat & um, std::vector<Point2f> & v) const85{86v.resize(um.size().area());87um.copyTo(Mat(um.size(), CV_32FC2, &v[0]));88}89};9091const int GoodFeaturesToTrack::maxCorners = 1000;92const double GoodFeaturesToTrack::qualityLevel = 0.01;9394OCL_TEST_P(GoodFeaturesToTrack, Accuracy)95{96for (int j = 0; j < test_loop_times; ++j)97{98generateTestData();99100std::vector<Point2f> upts, pts;101102OCL_OFF(cv::goodFeaturesToTrack(src_roi, points, maxCorners, qualityLevel, minDistance, noArray()));103ASSERT_FALSE(points.empty());104UMatToVector(points, pts);105106OCL_ON(cv::goodFeaturesToTrack(usrc_roi, upoints, maxCorners, qualityLevel, minDistance));107ASSERT_FALSE(upoints.empty());108UMatToVector(upoints, upts);109110ASSERT_EQ(upts.size(), pts.size());111112int mistmatch = 0;113for (size_t i = 0; i < pts.size(); ++i)114{115Point2i a = upts[i], b = pts[i];116117bool eq = std::abs(a.x - b.x) < 1 && std::abs(a.y - b.y) < 1;118119if (!eq)120++mistmatch;121}122123double bad_ratio = static_cast<double>(mistmatch) / pts.size();124ASSERT_GE(1e-2, bad_ratio);125}126}127128OCL_TEST_P(GoodFeaturesToTrack, EmptyCorners)129{130generateTestData();131usrc_roi.setTo(Scalar::all(0));132133OCL_ON(cv::goodFeaturesToTrack(usrc_roi, upoints, maxCorners, qualityLevel, minDistance));134135ASSERT_TRUE(upoints.empty());136}137138OCL_INSTANTIATE_TEST_CASE_P(Imgproc, GoodFeaturesToTrack,139::testing::Combine(testing::Values(0.0, 3.0), Bool()));140141} } // namespace opencv_test::ocl142143#endif144145146