Path: blob/master/modules/video/test/ocl/test_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, 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// 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/////////////////////////////////////////////////////////////////////////////////////////////////52// FarnebackOpticalFlow53namespace54{55IMPLEMENT_PARAM_CLASS(PyrScale, double)56IMPLEMENT_PARAM_CLASS(PolyN, int)57CV_FLAGS(FarnebackOptFlowFlags, 0, OPTFLOW_FARNEBACK_GAUSSIAN)58IMPLEMENT_PARAM_CLASS(UseInitFlow, bool)59}6061PARAM_TEST_CASE(FarnebackOpticalFlow, PyrScale, PolyN, FarnebackOptFlowFlags, UseInitFlow)62{63int numLevels;64int winSize;65int numIters;66double pyrScale;67int polyN;68int flags;69bool useInitFlow;7071virtual void SetUp()72{73numLevels = 5;74winSize = 13;75numIters = 10;76pyrScale = GET_PARAM(0);77polyN = GET_PARAM(1);78flags = GET_PARAM(2);79useInitFlow = GET_PARAM(3);80}81};8283OCL_TEST_P(FarnebackOpticalFlow, Mat)84{85cv::Mat frame0 = readImage("optflow/RubberWhale1.png", cv::IMREAD_GRAYSCALE);86ASSERT_FALSE(frame0.empty());8788cv::Mat frame1 = readImage("optflow/RubberWhale2.png", cv::IMREAD_GRAYSCALE);89ASSERT_FALSE(frame1.empty());9091double polySigma = polyN <= 5 ? 1.1 : 1.5;9293cv::Mat flow; cv::UMat uflow;94if (useInitFlow)95{96OCL_ON(cv::calcOpticalFlowFarneback(frame0, frame1, uflow, pyrScale, numLevels, winSize, numIters, polyN, polySigma, flags));97uflow.copyTo(flow);98flags |= cv::OPTFLOW_USE_INITIAL_FLOW;99}100OCL_OFF(cv::calcOpticalFlowFarneback(frame0, frame1, flow, pyrScale, numLevels, winSize, numIters, polyN, polySigma, flags));101OCL_ON(cv::calcOpticalFlowFarneback(frame0, frame1, uflow, pyrScale, numLevels, winSize, numIters, polyN, polySigma, flags));102103EXPECT_MAT_SIMILAR(flow, uflow, 0.1);104}105106107OCL_INSTANTIATE_TEST_CASE_P(Video, FarnebackOpticalFlow,108Combine(109Values(PyrScale(0.3), PyrScale(0.5), PyrScale(0.8)),110Values(PolyN(5), PolyN(7)),111Values(FarnebackOptFlowFlags(0), FarnebackOptFlowFlags(cv::OPTFLOW_FARNEBACK_GAUSSIAN)),112Values(UseInitFlow(false), UseInitFlow(true))113)114);115116117} } // namespace opencv_test::ocl118119#endif // HAVE_OPENCL120121122