1
/*M///////////////////////////////////////////////////////////////////////////////////////
3
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
5
// By downloading, copying, installing or using the software you agree to this license.
6
// If you do not agree to this license, do not download, install,
7
// copy or use the software.
11
// For Open Source Computer Vision Library
13
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
14
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
15
// Third party copyrights are property of their respective owners.
17
// Redistribution and use in source and binary forms, with or without modification,
18
// are permitted provided that the following conditions are met:
20
// * Redistribution's of source code must retain the above copyright notice,
21
// this list of conditions and the following disclaimer.
23
// * Redistribution's in binary form must reproduce the above copyright notice,
24
// this list of conditions and the following disclaimer in the documentation
25
// and/or other materials provided with the distribution.
27
// * The name of the copyright holders may not be used to endorse or promote products
28
// derived from this software without specific prior written permission.
30
// This software is provided by the copyright holders and contributors "as is" and
31
// any express or implied warranties, including, but not limited to, the implied
32
// 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 damages
35
// (including, but not limited to, procurement of substitute goods or services;
36
// loss of use, data, or profits; or business interruption) however caused
37
// and on any theory of liability, whether in contract, strict liability,
38
// or tort (including negligence or otherwise) arising in any way out of
39
// the use of this software, even if advised of the possibility of such damage.
43
#include "perf_precomp.hpp"
46
using namespace testing;
49
typedef pair<string, string> pair_string;
51
DEF_PARAM_TEST_1(ImagePair, pair_string);
53
//////////////////////////////////////////////////////
56
PERF_TEST_P(ImagePair, BroxOpticalFlow,
57
Values<pair_string>(make_pair("gpu/opticalflow/frame0.png", "gpu/opticalflow/frame1.png")))
61
cv::Mat frame0 = readImage(GetParam().first, cv::IMREAD_GRAYSCALE);
62
ASSERT_FALSE(frame0.empty());
64
cv::Mat frame1 = readImage(GetParam().second, cv::IMREAD_GRAYSCALE);
65
ASSERT_FALSE(frame1.empty());
67
frame0.convertTo(frame0, CV_32FC1, 1.0 / 255.0);
68
frame1.convertTo(frame1, CV_32FC1, 1.0 / 255.0);
72
const cv::cuda::GpuMat d_frame0(frame0);
73
const cv::cuda::GpuMat d_frame1(frame1);
74
cv::cuda::GpuMat flow;
76
cv::Ptr<cv::cuda::BroxOpticalFlow> d_alg =
77
cv::cuda::BroxOpticalFlow::create(0.197 /*alpha*/, 50.0 /*gamma*/, 0.8 /*scale_factor*/,
78
10 /*inner_iterations*/, 77 /*outer_iterations*/, 10 /*solver_iterations*/);
80
TEST_CYCLE() d_alg->calc(d_frame0, d_frame1, flow);
82
cv::cuda::GpuMat flows[2];
83
cv::cuda::split(flow, flows);
85
cv::cuda::GpuMat u = flows[0];
86
cv::cuda::GpuMat v = flows[1];
88
CUDA_SANITY_CHECK(u, 1e-1);
89
CUDA_SANITY_CHECK(v, 1e-1);
97
//////////////////////////////////////////////////////
98
// PyrLKOpticalFlowSparse
100
DEF_PARAM_TEST(ImagePair_Gray_NPts_WinSz_Levels_Iters, pair_string, bool, int, int, int, int);
102
PERF_TEST_P(ImagePair_Gray_NPts_WinSz_Levels_Iters, PyrLKOpticalFlowSparse,
103
Combine(Values<pair_string>(make_pair("gpu/opticalflow/frame0.png", "gpu/opticalflow/frame1.png")),
112
const pair_string imagePair = GET_PARAM(0);
113
const bool useGray = GET_PARAM(1);
114
const int points = GET_PARAM(2);
115
const int winSize = GET_PARAM(3);
116
const int levels = GET_PARAM(4);
117
const int iters = GET_PARAM(5);
119
const cv::Mat frame0 = readImage(imagePair.first, useGray ? cv::IMREAD_GRAYSCALE : cv::IMREAD_COLOR);
120
ASSERT_FALSE(frame0.empty());
122
const cv::Mat frame1 = readImage(imagePair.second, useGray ? cv::IMREAD_GRAYSCALE : cv::IMREAD_COLOR);
123
ASSERT_FALSE(frame1.empty());
129
cv::cvtColor(frame0, gray_frame, cv::COLOR_BGR2GRAY);
132
cv::goodFeaturesToTrack(gray_frame, pts, points, 0.01, 0.0);
136
const cv::cuda::GpuMat d_pts(pts.reshape(2, 1));
138
cv::Ptr<cv::cuda::SparsePyrLKOpticalFlow> d_pyrLK =
139
cv::cuda::SparsePyrLKOpticalFlow::create(cv::Size(winSize, winSize),
143
const cv::cuda::GpuMat d_frame0(frame0);
144
const cv::cuda::GpuMat d_frame1(frame1);
145
cv::cuda::GpuMat nextPts;
146
cv::cuda::GpuMat status;
148
TEST_CYCLE() d_pyrLK->calc(d_frame0, d_frame1, d_pts, nextPts, status);
150
CUDA_SANITY_CHECK(nextPts);
151
CUDA_SANITY_CHECK(status);
160
cv::calcOpticalFlowPyrLK(frame0, frame1, pts, nextPts, status, cv::noArray(),
161
cv::Size(winSize, winSize), levels - 1,
162
cv::TermCriteria(cv::TermCriteria::COUNT + cv::TermCriteria::EPS, iters, 0.01));
165
CPU_SANITY_CHECK(nextPts);
166
CPU_SANITY_CHECK(status);
170
//////////////////////////////////////////////////////
171
// PyrLKOpticalFlowDense
173
DEF_PARAM_TEST(ImagePair_WinSz_Levels_Iters, pair_string, int, int, int);
175
PERF_TEST_P(ImagePair_WinSz_Levels_Iters, PyrLKOpticalFlowDense,
176
Combine(Values<pair_string>(make_pair("gpu/opticalflow/frame0.png", "gpu/opticalflow/frame1.png")),
177
Values(3, 5, 7, 9, 13, 17, 21),
183
const pair_string imagePair = GET_PARAM(0);
184
const int winSize = GET_PARAM(1);
185
const int levels = GET_PARAM(2);
186
const int iters = GET_PARAM(3);
188
const cv::Mat frame0 = readImage(imagePair.first, cv::IMREAD_GRAYSCALE);
189
ASSERT_FALSE(frame0.empty());
191
const cv::Mat frame1 = readImage(imagePair.second, cv::IMREAD_GRAYSCALE);
192
ASSERT_FALSE(frame1.empty());
196
const cv::cuda::GpuMat d_frame0(frame0);
197
const cv::cuda::GpuMat d_frame1(frame1);
198
cv::cuda::GpuMat flow;
200
cv::Ptr<cv::cuda::DensePyrLKOpticalFlow> d_pyrLK =
201
cv::cuda::DensePyrLKOpticalFlow::create(cv::Size(winSize, winSize),
205
TEST_CYCLE() d_pyrLK->calc(d_frame0, d_frame1, flow);
207
cv::cuda::GpuMat flows[2];
208
cv::cuda::split(flow, flows);
210
cv::cuda::GpuMat u = flows[0];
211
cv::cuda::GpuMat v = flows[1];
213
// Sanity test fails on Maxwell and CUDA 7.0
214
SANITY_CHECK_NOTHING();
222
//////////////////////////////////////////////////////
223
// FarnebackOpticalFlow
225
PERF_TEST_P(ImagePair, FarnebackOpticalFlow,
226
Values<pair_string>(make_pair("gpu/opticalflow/frame0.png", "gpu/opticalflow/frame1.png")))
230
const cv::Mat frame0 = readImage(GetParam().first, cv::IMREAD_GRAYSCALE);
231
ASSERT_FALSE(frame0.empty());
233
const cv::Mat frame1 = readImage(GetParam().second, cv::IMREAD_GRAYSCALE);
234
ASSERT_FALSE(frame1.empty());
236
const int numLevels = 5;
237
const double pyrScale = 0.5;
238
const int winSize = 13;
239
const int numIters = 10;
241
const double polySigma = 1.1;
246
const cv::cuda::GpuMat d_frame0(frame0);
247
const cv::cuda::GpuMat d_frame1(frame1);
248
cv::cuda::GpuMat flow;
250
cv::Ptr<cv::cuda::FarnebackOpticalFlow> d_farneback =
251
cv::cuda::FarnebackOpticalFlow::create(numLevels, pyrScale, false, winSize,
252
numIters, polyN, polySigma, flags);
254
TEST_CYCLE() d_farneback->calc(d_frame0, d_frame1, flow);
256
cv::cuda::GpuMat flows[2];
257
cv::cuda::split(flow, flows);
259
cv::cuda::GpuMat u = flows[0];
260
cv::cuda::GpuMat v = flows[1];
262
CUDA_SANITY_CHECK(u, 1e-4);
263
CUDA_SANITY_CHECK(v, 1e-4);
269
TEST_CYCLE() cv::calcOpticalFlowFarneback(frame0, frame1, flow, pyrScale, numLevels, winSize, numIters, polyN, polySigma, flags);
271
CPU_SANITY_CHECK(flow);
275
//////////////////////////////////////////////////////
276
// OpticalFlowDual_TVL1
278
PERF_TEST_P(ImagePair, OpticalFlowDual_TVL1,
279
Values<pair_string>(make_pair("gpu/opticalflow/frame0.png", "gpu/opticalflow/frame1.png")))
283
const cv::Mat frame0 = readImage(GetParam().first, cv::IMREAD_GRAYSCALE);
284
ASSERT_FALSE(frame0.empty());
286
const cv::Mat frame1 = readImage(GetParam().second, cv::IMREAD_GRAYSCALE);
287
ASSERT_FALSE(frame1.empty());
291
const cv::cuda::GpuMat d_frame0(frame0);
292
const cv::cuda::GpuMat d_frame1(frame1);
293
cv::cuda::GpuMat flow;
295
cv::Ptr<cv::cuda::OpticalFlowDual_TVL1> d_alg =
296
cv::cuda::OpticalFlowDual_TVL1::create();
298
TEST_CYCLE() d_alg->calc(d_frame0, d_frame1, flow);
300
cv::cuda::GpuMat flows[2];
301
cv::cuda::split(flow, flows);
303
cv::cuda::GpuMat u = flows[0];
304
cv::cuda::GpuMat v = flows[1];
306
CUDA_SANITY_CHECK(u, 1e-1);
307
CUDA_SANITY_CHECK(v, 1e-1);
313
cv::Ptr<cv::DualTVL1OpticalFlow> alg = cv::createOptFlow_DualTVL1();
314
alg->setMedianFiltering(1);
315
alg->setInnerIterations(1);
316
alg->setOuterIterations(300);
317
TEST_CYCLE() alg->calc(frame0, frame1, flow);
319
CPU_SANITY_CHECK(flow);