Path: blob/master/modules/video/test/ocl/test_optflow_tvl1flow.cpp
16350 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// Optical_flow_tvl153namespace54{55IMPLEMENT_PARAM_CLASS(UseInitFlow, bool)56IMPLEMENT_PARAM_CLASS(MedianFiltering, int)57IMPLEMENT_PARAM_CLASS(ScaleStep, double)58}5960PARAM_TEST_CASE(OpticalFlowTVL1, UseInitFlow, MedianFiltering, ScaleStep)61{62bool useInitFlow;63int medianFiltering;64double scaleStep;65virtual void SetUp()66{67useInitFlow = GET_PARAM(0);68medianFiltering = GET_PARAM(1);69scaleStep = GET_PARAM(2);70}71};7273OCL_TEST_P(OpticalFlowTVL1, Mat)74{75cv::Mat frame0 = readImage("optflow/RubberWhale1.png", cv::IMREAD_GRAYSCALE);76ASSERT_FALSE(frame0.empty());7778cv::Mat frame1 = readImage("optflow/RubberWhale2.png", cv::IMREAD_GRAYSCALE);79ASSERT_FALSE(frame1.empty());8081cv::Mat flow; cv::UMat uflow;8283//create algorithm84cv::Ptr<cv::DualTVL1OpticalFlow> alg = cv::createOptFlow_DualTVL1();8586//set parameters87alg->setScaleStep(scaleStep);88alg->setMedianFiltering(medianFiltering);8990//create initial flow as result of algorithm calculation91if (useInitFlow)92{93OCL_ON(alg->calc(frame0, frame1, uflow));94uflow.copyTo(flow);95}9697//set flag to use initial flow as it is ready to use98alg->setUseInitialFlow(useInitFlow);99100OCL_OFF(alg->calc(frame0, frame1, flow));101OCL_ON(alg->calc(frame0, frame1, uflow));102103EXPECT_MAT_SIMILAR(flow, uflow, 1e-2);104}105106OCL_INSTANTIATE_TEST_CASE_P(Video, OpticalFlowTVL1,107Combine(108Values(UseInitFlow(false), UseInitFlow(true)),109Values(MedianFiltering(3), MedianFiltering(-1)),110Values(ScaleStep(0.3),ScaleStep(0.5))111)112);113114} } // namespace opencv_test::ocl115116#endif // HAVE_OPENCL117118119