Skip to content

Commit 1c9e237

Browse files
tsenstalalek
authored andcommitted
Merge pull request #1940 from tsenst:add_robust_optical_flow_implementation
Add robust local optical flow (RLOF) implementations (#1940) * Add robust local optical flow (RLOF) implementations which is an improved pyramidal iterative Lucas-Kanade approach. This implementations contains interfaces for sparse optical flow for feature tracking and dense optical flow based on sparse-to-dense interpolation schemes. Add performance and accuracy tests have been implementation as well as documentation with the related publications * - exchange tabs with spaces - fix optflow.bib indentation - remove optflow_o.hpp - change RLOFOpticalFlowParameter interfaces to Ptr<RLOFOpticalFlowParameter> to remove error on building. Fix warnings * introducing precompiler flag RLOD_SSE * remove header that could not be found * remove whitespaces fix perf and accuracy tests * remove x86intrin.h header * fix ios and arm by removing last sse commands * fix warnings for windows compilation * fix documentation RLOFOpticalFlowParameter * integrate cast to remove last warnings * * add create method and function inferfaces to RLOFOpticalFlowParamter to enable python wrapper interfaces * white space fixes / coding style * fix perf test * other changes: precomp.hpp / static * use Matx44f and Vec4f instead of Mat * normSigmas into constants * replace ceil() calls * maximum level is set to 5 so that it is similar value used in the papers * implement paralellized horizontal cross segmentation as used in Geistert2016 * drop dead code * Avoid using "data" and "step" calculations. Use .ptr<mat_type>(row, col) instead. * Avoid using "data" and "step" calculations. Use .ptr<mat_type>(row, col) instead. * bugfix on BEPLK with ica and adapt the accuracy tests * more 'static' functions * bugfix after changing ptr + step to .ptr(y,x) calls by adjusting ROI of prevImage, currImage and derivI as well as changing the offset of the points in the invoker classes. * add some static_cast to avoid warning * remove 50 grid size sample from perf test. This grid size is to sparse for the epic interpolation * remove notSameColor function since it is not used anymore
1 parent b1e9dd5 commit 1c9e237

15 files changed

+7224
-6
lines changed

modules/optflow/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
set(the_description "Optical Flow Algorithms")
2-
ocv_define_module(optflow opencv_core opencv_imgproc opencv_video opencv_ximgproc opencv_imgcodecs opencv_flann WRAP python)
2+
ocv_define_module(optflow opencv_core opencv_imgproc opencv_calib3d opencv_video opencv_ximgproc opencv_imgcodecs opencv_flann WRAP python)

modules/optflow/doc/optflow.bib

+49
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,52 @@ @inproceedings{Wang_2016_CVPR
6161
month = {June},
6262
year = {2016}
6363
}
64+
65+
@inproceedings{Geistert2016,
66+
author = {Jonas Geistert and Tobias Senst and Thomas Sikora},
67+
title = {Robust Local Optical Flow: Dense Motion Vector Field Interpolation},
68+
booktitle = {Picture Coding Symposium},
69+
year = {2016},
70+
pages = {1--5},
71+
}
72+
73+
@inproceedings{Senst2016,
74+
author = {Tobias Senst and Jonas Geistert and Thomas Sikora},
75+
title = {Robust local optical flow: Long-range motions and varying illuminations},
76+
booktitle = {IEEE International Conference on Image Processing},
77+
year = {2016},
78+
pages = {4478--4482},
79+
}
80+
81+
@inproceedings{Senst2014,
82+
author = {Tobias Senst and Thilo Borgmann and Ivo Keller and Thomas Sikora},
83+
title = {Cross based Robust Local Optical Flow},
84+
booktitle = {21th IEEE International Conference on Image Processing},
85+
year = {2014},
86+
pages = {1967--1971},
87+
}
88+
89+
@inproceedings{Senst2013,
90+
author = {Tobias Senst and Jonas Geistert and Ivo Keller and Thomas Sikora},
91+
title = {Robust Local Optical Flow Estimation using Bilinear Equations for Sparse Motion Estimation},
92+
booktitle = {20th IEEE International Conference on Image Processing},
93+
year = {2013},
94+
pages = {2499--2503},
95+
}
96+
97+
@article{Senst2012,
98+
author = {Tobias Senst and Volker Eiselein and Thomas Sikora},
99+
title = {Robust Local Optical Flow for Feature Tracking},
100+
journal = {IEEE Transactions on Circuits and Systems for Video Technology},
101+
year = {2012},
102+
pages = {1377--1387},
103+
volume = {22},
104+
number = {9},
105+
}
106+
107+
@article{Tibshirani2008,
108+
title={Fast computation of the median by successive binning},
109+
author={Tibshirani, Ryan J},
110+
journal={arXiv preprint arXiv:0806.3301},
111+
year={2008}
112+
}

modules/optflow/include/opencv2/optflow.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ Functions reading and writing .flo files in "Middlebury" format, see: <http://vi
6868

6969
#include "opencv2/optflow/pcaflow.hpp"
7070
#include "opencv2/optflow/sparse_matching_gpc.hpp"
71-
71+
#include "opencv2/optflow/rlofflow.hpp"
7272
namespace cv
7373
{
7474
namespace optflow

modules/optflow/include/opencv2/optflow/rlofflow.hpp

+493
Large diffs are not rendered by default.

modules/optflow/perf/perf_rlof.cpp

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
#include "perf_precomp.hpp"
2+
namespace opencv_test { namespace {
3+
4+
typedef tuple<std::string, std::string, bool> ST_SR_IM_Sparse_t;
5+
typedef TestBaseWithParam<ST_SR_IM_Sparse_t> ST_SR_IM_Sparse;
6+
PERF_TEST_P(ST_SR_IM_Sparse, OpticalFlow_SparseRLOF,
7+
testing::Combine(
8+
testing::Values<std::string>("ST_BILINEAR", "ST_STANDART"),
9+
testing::Values<std::string>("SR_CROSS", "SR_FIXED"),
10+
testing::Values(true, false))
11+
)
12+
{
13+
Mat frame1 = imread(getDataPath("cv/optflow/RubberWhale1.png"));
14+
Mat frame2 = imread(getDataPath("cv/optflow/RubberWhale2.png"));
15+
ASSERT_FALSE(frame1.empty());
16+
ASSERT_FALSE(frame2.empty());
17+
vector<Point2f> prevPts, currPts;
18+
for (int r = 0; r < frame1.rows; r += 10)
19+
{
20+
for (int c = 0; c < frame1.cols; c += 10)
21+
{
22+
prevPts.push_back(Point2f(static_cast<float>(c), static_cast<float>(r)));
23+
}
24+
}
25+
vector<uchar> status(prevPts.size());
26+
vector<float> err(prevPts.size());
27+
28+
Ptr<RLOFOpticalFlowParameter> param = Ptr<RLOFOpticalFlowParameter>(new RLOFOpticalFlowParameter);
29+
if (get<0>(GetParam()) == "ST_BILINEAR")
30+
param->solverType = ST_BILINEAR;
31+
if (get<0>(GetParam()) == "ST_STANDART")
32+
param->solverType = ST_STANDART;
33+
if (get<1>(GetParam()) == "SR_CROSS")
34+
param->supportRegionType = SR_CROSS;
35+
if (get<1>(GetParam()) == "SR_FIXED")
36+
param->supportRegionType = SR_FIXED;
37+
param->useIlluminationModel = get<2>(GetParam());
38+
39+
PERF_SAMPLE_BEGIN()
40+
calcOpticalFlowSparseRLOF(frame1, frame2, prevPts, currPts, status, err, param, 1.f);
41+
PERF_SAMPLE_END()
42+
43+
SANITY_CHECK_NOTHING();
44+
}
45+
46+
typedef tuple<std::string, int> INTERP_GRID_Dense_t;
47+
typedef TestBaseWithParam<INTERP_GRID_Dense_t> INTERP_GRID_Dense;
48+
PERF_TEST_P(INTERP_GRID_Dense, OpticalFlow_DenseRLOF,
49+
testing::Combine(
50+
testing::Values<std::string>("INTERP_EPIC", "INTERP_GEO"),
51+
testing::Values<int>(4,10))
52+
)
53+
{
54+
Mat flow;
55+
Mat frame1 = imread(getDataPath("cv/optflow/RubberWhale1.png"));
56+
Mat frame2 = imread(getDataPath("cv/optflow/RubberWhale1.png"));
57+
ASSERT_FALSE(frame1.empty());
58+
ASSERT_FALSE(frame2.empty());
59+
Ptr<RLOFOpticalFlowParameter> param = Ptr<RLOFOpticalFlowParameter>(new RLOFOpticalFlowParameter);;
60+
Ptr< DenseRLOFOpticalFlow> algo = DenseRLOFOpticalFlow::create();
61+
InterpolationType interp_type = INTERP_EPIC;
62+
if (get<0>(GetParam()) == "INTERP_EPIC")
63+
interp_type = INTERP_EPIC;
64+
if (get<0>(GetParam()) == "INTERP_GEO")
65+
interp_type = INTERP_GEO;
66+
PERF_SAMPLE_BEGIN()
67+
calcOpticalFlowDenseRLOF(frame1, frame2,flow, param, 1.0f, Size(get<1>(GetParam()), get<1>(GetParam())), interp_type);
68+
PERF_SAMPLE_END()
69+
SANITY_CHECK_NOTHING();
70+
}
71+
72+
}} // namespace

0 commit comments

Comments
 (0)