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) 2010-2012, Multicoreware, Inc., all rights reserved.
14 // Copyright (C) 2010-2012, Advanced Micro Devices, Inc., all rights reserved.
15 // Third party copyrights are property of their respective owners.
18 // Fangfang Bai, fangfang@multicorewareinc.com
19 // Jin Ma, jin@multicorewareinc.com
21 // Redistribution and use in source and binary forms, with or without modification,
22 // are permitted provided that the following conditions are met:
24 // * Redistribution's of source code must retain the above copyright notice,
25 // this list of conditions and the following disclaimer.
27 // * Redistribution's in binary form must reproduce the above copyright notice,
28 // this list of conditions and the following disclaimer in the documentation
29 // and/or other materials provided with the distribution.
31 // * The name of the copyright holders may not be used to endorse or promote products
32 // derived from this software without specific prior written permission.
34 // This software is provided by the copyright holders and contributors as is and
35 // any express or implied warranties, including, but not limited to, the implied
36 // warranties of merchantability and fitness for a particular purpose are disclaimed.
37 // In no event shall the Intel Corporation or contributors be liable for any direct,
38 // indirect, incidental, special, exemplary, or consequential damages
39 // (including, but not limited to, procurement of substitute goods or services;
40 // loss of use, data, or profits; or business interruption) however caused
41 // and on any theory of liability, whether in contract, strict liability,
42 // or tort (including negligence or otherwise) arising in any way out of
43 // the use of this software, even if advised of the possibility of such damage.
46 #include "perf_precomp.hpp"
48 ///////////// PyrLKOpticalFlow ////////////////////////
52 using std::tr1::tuple;
53 using std::tr1::make_tuple;
55 CV_ENUM(LoadMode, IMREAD_GRAYSCALE, IMREAD_COLOR)
57 typedef tuple<int, tuple<string, string, LoadMode> > PyrLKOpticalFlowParamType;
58 typedef TestBaseWithParam<PyrLKOpticalFlowParamType> PyrLKOpticalFlowFixture;
60 PERF_TEST_P(PyrLKOpticalFlowFixture,
63 ::testing::Values(1000, 2000, 4000),
65 make_tuple<string, string, LoadMode>
67 string("gpu/opticalflow/rubberwhale1.png"),
68 string("gpu/opticalflow/rubberwhale2.png"),
69 LoadMode(IMREAD_COLOR)
71 make_tuple<string, string, LoadMode>
73 string("gpu/stereobm/aloe-L.png"),
74 string("gpu/stereobm/aloe-R.png"),
75 LoadMode(IMREAD_GRAYSCALE)
81 PyrLKOpticalFlowParamType params = GetParam();
82 tuple<string, string, LoadMode> fileParam = get<1>(params);
83 const int pointsCount = get<0>(params);
84 const int openMode = static_cast<int>(get<2>(fileParam));
85 const string fileName0 = get<0>(fileParam), fileName1 = get<1>(fileParam);
86 Mat frame0 = imread(getDataPath(fileName0), openMode);
87 Mat frame1 = imread(getDataPath(fileName1), openMode);
89 declare.in(frame0, frame1);
91 ASSERT_FALSE(frame0.empty()) << "can't load " << fileName0;
92 ASSERT_FALSE(frame1.empty()) << "can't load " << fileName1;
95 if (openMode == IMREAD_COLOR)
96 cvtColor(frame0, grayFrame, COLOR_BGR2GRAY);
100 vector<Point2f> pts, nextPts;
101 vector<unsigned char> status;
103 goodFeaturesToTrack(grayFrame, pts, pointsCount, 0.01, 0.0);
104 Mat ptsMat(1, static_cast<int>(pts.size()), CV_32FC2, (void *)&pts[0]);
109 cv::calcOpticalFlowPyrLK(frame0, frame1, pts, nextPts, status, err);
111 else if (RUN_OCL_IMPL)
113 ocl::PyrLKOpticalFlow oclPyrLK;
114 ocl::oclMat oclFrame0(frame0), oclFrame1(frame1);
115 ocl::oclMat oclPts(ptsMat);
116 ocl::oclMat oclNextPts, oclStatus, oclErr;
119 oclPyrLK.sparse(oclFrame0, oclFrame1, oclPts, oclNextPts, oclStatus, &oclErr);
128 PERF_TEST(tvl1flowFixture, tvl1flow)
130 Mat frame0 = imread(getDataPath("gpu/opticalflow/rubberwhale1.png"), cv::IMREAD_GRAYSCALE);
131 ASSERT_FALSE(frame0.empty()) << "can't load rubberwhale1.png";
133 Mat frame1 = imread(getDataPath("gpu/opticalflow/rubberwhale2.png"), cv::IMREAD_GRAYSCALE);
134 ASSERT_FALSE(frame1.empty()) << "can't load rubberwhale2.png";
136 const Size srcSize = frame0.size();
137 const double eps = 1.2;
138 Mat flow(srcSize, CV_32FC2), flow1(srcSize, CV_32FC1), flow2(srcSize, CV_32FC1);
139 declare.in(frame0, frame1).out(flow1, flow2).time(159);
143 Ptr<DenseOpticalFlow> alg = createOptFlow_DualTVL1();
145 TEST_CYCLE() alg->calc(frame0, frame1, flow);
147 alg->collectGarbage();
148 Mat flows[2] = { flow1, flow2 };
151 SANITY_CHECK(flow1, eps);
152 SANITY_CHECK(flow2, eps);
154 else if (RUN_OCL_IMPL)
156 ocl::OpticalFlowDual_TVL1_OCL oclAlg;
157 ocl::oclMat oclFrame0(frame0), oclFrame1(frame1), oclFlow1(srcSize, CV_32FC1),
158 oclFlow2(srcSize, CV_32FC1);
160 OCL_TEST_CYCLE() oclAlg(oclFrame0, oclFrame1, oclFlow1, oclFlow2);
162 oclAlg.collectGarbage();
164 oclFlow1.download(flow1);
165 oclFlow2.download(flow2);
167 SANITY_CHECK(flow1, eps);
168 SANITY_CHECK(flow2, eps);
174 ///////////// FarnebackOpticalFlow ////////////////////////
176 CV_ENUM(farneFlagType, 0, OPTFLOW_FARNEBACK_GAUSSIAN)
178 typedef tuple<tuple<int, double>, farneFlagType, bool> FarnebackOpticalFlowParams;
179 typedef TestBaseWithParam<FarnebackOpticalFlowParams> FarnebackOpticalFlowFixture;
181 PERF_TEST_P(FarnebackOpticalFlowFixture, FarnebackOpticalFlow,
183 ::testing::Values(make_tuple<int, double>(5, 1.1),
184 make_tuple<int, double>(7, 1.5)),
185 farneFlagType::all(),
188 Mat frame0 = imread(getDataPath("gpu/opticalflow/rubberwhale1.png"), cv::IMREAD_GRAYSCALE);
189 ASSERT_FALSE(frame0.empty()) << "can't load rubberwhale1.png";
191 Mat frame1 = imread(getDataPath("gpu/opticalflow/rubberwhale2.png"), cv::IMREAD_GRAYSCALE);
192 ASSERT_FALSE(frame1.empty()) << "can't load rubberwhale2.png";
194 const Size srcSize = frame0.size();
196 const FarnebackOpticalFlowParams params = GetParam();
197 const tuple<int, double> polyParams = get<0>(params);
198 const int polyN = get<0>(polyParams), flags = get<1>(params);
199 const double polySigma = get<1>(polyParams), pyrScale = 0.5;
200 const bool useInitFlow = get<2>(params);
201 const double eps = 1.5;
203 Mat flowx(srcSize, CV_32FC1), flowy(srcSize, CV_32FC1), flow(srcSize, CV_32FC2);
204 declare.in(frame0, frame1).out(flowx, flowy);
206 ocl::FarnebackOpticalFlow farn;
207 farn.pyrScale = pyrScale;
209 farn.polySigma = polySigma;
216 calcOpticalFlowFarneback(
217 frame0, frame1, flow, farn.pyrScale, farn.numLevels, farn.winSize,
218 farn.numIters, farn.polyN, farn.polySigma, farn.flags);
219 farn.flags |= OPTFLOW_USE_INITIAL_FLOW;
223 calcOpticalFlowFarneback(
224 frame0, frame1, flow, farn.pyrScale, farn.numLevels, farn.winSize,
225 farn.numIters, farn.polyN, farn.polySigma, farn.flags);
227 Mat flowxy[2] = { flowx, flowy };
230 SANITY_CHECK(flowx, eps);
231 SANITY_CHECK(flowy, eps);
233 else if (RUN_OCL_IMPL)
235 ocl::oclMat oclFrame0(frame0), oclFrame1(frame1),
236 oclFlowx(srcSize, CV_32FC1), oclFlowy(srcSize, CV_32FC1);
240 farn(oclFrame0, oclFrame1, oclFlowx, oclFlowy);
241 farn.flags |= OPTFLOW_USE_INITIAL_FLOW;
245 farn(oclFrame0, oclFrame1, oclFlowx, oclFlowy);
247 oclFlowx.download(flowx);
248 oclFlowy.download(flowy);
250 SANITY_CHECK(flowx, eps);
251 SANITY_CHECK(flowy, eps);