Path: blob/master/modules/video/perf/opencl/perf_optflow_farneback.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// Fangfang Bai, [email protected]18// Jin Ma, [email protected]19//20// Redistribution and use in source and binary forms, with or without modification,21// are permitted provided that the following conditions are met:22//23// * Redistribution's of source code must retain the above copyright notice,24// this list of conditions and the following disclaimer.25//26// * Redistribution's in binary form must reproduce the above copyright notice,27// this list of conditions and the following disclaimer in the documentation28// and/or other materials provided with the distribution.29//30// * The name of the copyright holders may not be used to endorse or promote products31// derived from this software without specific prior written permission.32//33// This software is provided by the copyright holders and contributors as is and34// any express or implied warranties, including, but not limited to, the implied35// warranties of merchantability and fitness for a particular purpose are disclaimed.36// In no event shall the Intel Corporation or contributors be liable for any direct,37// indirect, incidental, special, exemplary, or consequential damages38// (including, but not limited to, procurement of substitute goods or services;39// loss of use, data, or profits; or business interruption) however caused40// and on any theory of liability, whether in contract, strict liability,41// or tort (including negligence or otherwise) arising in any way out of42// the use of this software, even if advised of the possibility of such damage.43//44//M*/4546#include "../perf_precomp.hpp"47#include "opencv2/ts/ocl_perf.hpp"4849#ifdef HAVE_OPENCL5051namespace opencv_test {52namespace ocl {5354///////////// FarnebackOpticalFlow ////////////////////////55CV_ENUM(farneFlagType, 0, OPTFLOW_FARNEBACK_GAUSSIAN)5657typedef tuple< tuple<int, double>, farneFlagType, bool > FarnebackOpticalFlowParams;58typedef TestBaseWithParam<FarnebackOpticalFlowParams> FarnebackOpticalFlowFixture;5960OCL_PERF_TEST_P(FarnebackOpticalFlowFixture, FarnebackOpticalFlow,61::testing::Combine(62::testing::Values(63make_tuple<int, double>(5, 1.1),64make_tuple<int, double>(7, 1.5)65),66farneFlagType::all(),67::testing::Bool()68)69)70{71Mat frame0 = imread(getDataPath("gpu/opticalflow/rubberwhale1.png"), cv::IMREAD_GRAYSCALE);72ASSERT_FALSE(frame0.empty()) << "can't load rubberwhale1.png";7374Mat frame1 = imread(getDataPath("gpu/opticalflow/rubberwhale2.png"), cv::IMREAD_GRAYSCALE);75ASSERT_FALSE(frame1.empty()) << "can't load rubberwhale2.png";7677const Size srcSize = frame0.size();7879const int numLevels = 5;80const int winSize = 13;81const int numIters = 10;8283const FarnebackOpticalFlowParams params = GetParam();84const tuple<int, double> polyParams = get<0>(params);85const int polyN = get<0>(polyParams);86const double polySigma = get<1>(polyParams);87const double pyrScale = 0.5;88int flags = get<1>(params);89const bool useInitFlow = get<2>(params);90const double eps = 0.1;9192UMat uFrame0; frame0.copyTo(uFrame0);93UMat uFrame1; frame1.copyTo(uFrame1);94UMat uFlow(srcSize, CV_32FC2);95declare.in(uFrame0, uFrame1, WARMUP_READ).out(uFlow, WARMUP_READ);96if (useInitFlow)97{98cv::calcOpticalFlowFarneback(uFrame0, uFrame1, uFlow, pyrScale, numLevels, winSize, numIters, polyN, polySigma, flags);99flags |= OPTFLOW_USE_INITIAL_FLOW;100}101102OCL_TEST_CYCLE()103cv::calcOpticalFlowFarneback(uFrame0, uFrame1, uFlow, pyrScale, numLevels, winSize, numIters, polyN, polySigma, flags);104105106SANITY_CHECK(uFlow, eps, ERROR_RELATIVE);107}108109} } // namespace opencv_test::ocl110111#endif // HAVE_OPENCL112113