1
#include "perf_precomp.hpp"
6
using std::tr1::make_tuple;
9
typedef tr1::tuple<std::string, int, int, tr1::tuple<int,int>, int> Path_Idx_Cn_NPoints_WSize_t;
10
typedef TestBaseWithParam<Path_Idx_Cn_NPoints_WSize_t> Path_Idx_Cn_NPoints_WSize;
12
void FormTrackingPointsArray(vector<Point2f>& points, int width, int height, int nPointsX, int nPointsY)
14
int stepX = width / nPointsX;
15
int stepY = height / nPointsY;
16
if (stepX < 1 || stepY < 1) FAIL() << "Specified points number is too big";
19
points.reserve(nPointsX * nPointsY);
21
for( int x = stepX / 2; x < width; x += stepX )
23
for( int y = stepY / 2; y < height; y += stepY )
25
Point2f pt(static_cast<float>(x), static_cast<float>(y));
31
PERF_TEST_P(Path_Idx_Cn_NPoints_WSize, OpticalFlowPyrLK_full, testing::Combine(
32
testing::Values<std::string>("cv/optflow/frames/VGA_%02d.png", "cv/optflow/frames/720p_%02d.png"),
34
testing::Values(1, 3, 4),
35
testing::Values(make_tuple(9, 9), make_tuple(15, 15)),
36
testing::Values(7, 11)
40
string filename1 = getDataPath(cv::format(get<0>(GetParam()).c_str(), get<1>(GetParam())));
41
string filename2 = getDataPath(cv::format(get<0>(GetParam()).c_str(), get<1>(GetParam()) + 1));
42
Mat img1 = imread(filename1);
43
Mat img2 = imread(filename2);
44
if (img1.empty()) FAIL() << "Unable to load source image " << filename1;
45
if (img2.empty()) FAIL() << "Unable to load source image " << filename2;
47
int cn = get<2>(GetParam());
48
int nPointsX = min(get<0>(get<3>(GetParam())), img1.cols);
49
int nPointsY = min(get<1>(get<3>(GetParam())), img1.rows);
50
int winSize = get<4>(GetParam());
53
TermCriteria criteria(TermCriteria::COUNT|TermCriteria::EPS, 7, 0.001);
55
double minEigThreshold = 1e-4;
61
cvtColor(img1, frame1, COLOR_BGR2GRAY, cn);
62
cvtColor(img2, frame2, COLOR_BGR2GRAY, cn);
69
cvtColor(img1, frame1, COLOR_BGR2BGRA, cn);
70
cvtColor(img2, frame2, COLOR_BGR2BGRA, cn);
73
FAIL() << "Unexpected number of channels: " << cn;
76
vector<Point2f> inPoints;
77
vector<Point2f> outPoints;
81
FormTrackingPointsArray(inPoints, frame1.cols, frame1.rows, nPointsX, nPointsY);
82
outPoints.resize(inPoints.size());
83
status.resize(inPoints.size());
84
err.resize(inPoints.size());
86
declare.in(frame1, frame2, inPoints).out(outPoints);
90
calcOpticalFlowPyrLK(frame1, frame2, inPoints, outPoints, status, err,
91
Size(winSize, winSize), maxLevel, criteria,
92
flags, minEigThreshold);
95
SANITY_CHECK(outPoints, 0.3);
100
typedef tr1::tuple<std::string, int, int, tr1::tuple<int,int>, int, bool> Path_Idx_Cn_NPoints_WSize_Deriv_t;
101
typedef TestBaseWithParam<Path_Idx_Cn_NPoints_WSize_Deriv_t> Path_Idx_Cn_NPoints_WSize_Deriv;
103
PERF_TEST_P(Path_Idx_Cn_NPoints_WSize_Deriv, OpticalFlowPyrLK_self, testing::Combine(
104
testing::Values<std::string>("cv/optflow/frames/VGA_%02d.png", "cv/optflow/frames/720p_%02d.png"),
105
testing::Range(1, 3),
106
testing::Values(1, 3, 4),
107
testing::Values(make_tuple(9, 9), make_tuple(15, 15)),
108
testing::Values(7, 11),
113
string filename1 = getDataPath(cv::format(get<0>(GetParam()).c_str(), get<1>(GetParam())));
114
string filename2 = getDataPath(cv::format(get<0>(GetParam()).c_str(), get<1>(GetParam()) + 1));
115
Mat img1 = imread(filename1);
116
Mat img2 = imread(filename2);
117
if (img1.empty()) FAIL() << "Unable to load source image " << filename1;
118
if (img2.empty()) FAIL() << "Unable to load source image " << filename2;
120
int cn = get<2>(GetParam());
121
int nPointsX = min(get<0>(get<3>(GetParam())), img1.cols);
122
int nPointsY = min(get<1>(get<3>(GetParam())), img1.rows);
123
int winSize = get<4>(GetParam());
124
bool withDerivatives = get<5>(GetParam());
127
TermCriteria criteria(TermCriteria::COUNT|TermCriteria::EPS, 7, 0.001);
129
double minEigThreshold = 1e-4;
135
cvtColor(img1, frame1, COLOR_BGR2GRAY, cn);
136
cvtColor(img2, frame2, COLOR_BGR2GRAY, cn);
143
cvtColor(img1, frame1, COLOR_BGR2BGRA, cn);
144
cvtColor(img2, frame2, COLOR_BGR2BGRA, cn);
147
FAIL() << "Unexpected number of channels: " << cn;
150
vector<Point2f> inPoints;
151
vector<Point2f> outPoints;
152
vector<uchar> status;
155
FormTrackingPointsArray(inPoints, frame1.cols, frame1.rows, nPointsX, nPointsY);
156
outPoints.resize(inPoints.size());
157
status.resize(inPoints.size());
158
err.resize(inPoints.size());
160
std::vector<Mat> pyramid1, pyramid2;
162
maxLevel = buildOpticalFlowPyramid(frame1, pyramid1, Size(winSize, winSize), maxLevel, withDerivatives);
163
maxLevel = buildOpticalFlowPyramid(frame2, pyramid2, Size(winSize, winSize), maxLevel, withDerivatives);
165
declare.in(pyramid1, pyramid2, inPoints).out(outPoints);
169
TEST_CYCLE_MULTIRUN(runs)
171
calcOpticalFlowPyrLK(pyramid1, pyramid2, inPoints, outPoints, status, err,
172
Size(winSize, winSize), maxLevel, criteria,
173
flags, minEigThreshold);
176
SANITY_CHECK(outPoints, 0.3);
177
SANITY_CHECK(status);
178
SANITY_CHECK(err, 2);
181
CV_ENUM(PyrBorderMode, BORDER_DEFAULT, BORDER_TRANSPARENT)
182
typedef tr1::tuple<std::string, int, bool, PyrBorderMode, bool> Path_Win_Deriv_Border_Reuse_t;
183
typedef TestBaseWithParam<Path_Win_Deriv_Border_Reuse_t> Path_Win_Deriv_Border_Reuse;
185
PERF_TEST_P(Path_Win_Deriv_Border_Reuse, OpticalFlowPyrLK_pyr, testing::Combine(
186
testing::Values<std::string>("cv/optflow/frames/720p_01.png"),
187
testing::Values(7, 11),
189
PyrBorderMode::all(),
194
string filename = getDataPath(get<0>(GetParam()));
195
Mat img = imread(filename);
196
Size winSize(get<1>(GetParam()), get<1>(GetParam()));
197
bool withDerivatives = get<2>(GetParam());
198
int derivBorder = get<3>(GetParam());
199
int pyrBorder = derivBorder;
200
if(derivBorder != BORDER_TRANSPARENT)
202
derivBorder = BORDER_CONSTANT;
203
pyrBorder = BORDER_REFLECT_101;
205
bool tryReuseInputImage = get<4>(GetParam());
206
std::vector<Mat> pyramid;
208
img.adjustROI(winSize.height, winSize.height, winSize.width, winSize.width);
210
int maxLevel = buildOpticalFlowPyramid(img, pyramid, winSize, 1000, withDerivatives, BORDER_CONSTANT, BORDER_CONSTANT, tryReuseInputImage);
212
declare.in(img).out(pyramid);
217
buildOpticalFlowPyramid(img, pyramid, winSize, maxLevel, withDerivatives, pyrBorder, derivBorder, tryReuseInputImage);
220
SANITY_CHECK(pyramid);