Introduction
Optical flow and keypoint tracking
Slide set by Svetlana Lazebnik. Many slides adapted from S. Seitz, R. Szeliski, M. Pollefeys
1
Motion is a powerful perceptual cue
Sometimes, it is the only cue
2
Motion is a powerful perceptual cue
Even “impoverished” motion data can evoke a strong percept
G. Johansson, “Visual Perception of Biological Motion and a Model For Its Analysis”, Perception and Psychophysics 14, 201-211, 1973.
3
Motion is a powerful perceptual cue
Even “impoverished” motion data can evoke a strong percept
G. Johansson, “Visual Perception of Biological Motion and a Model For Its Analysis”, Perception and Psychophysics 14, 201-211, 1973.
4
Uses of motion in computer vision
3D shape reconstruction
Object segmentation
Learning and tracking of dynamical models
Event and activity recognition
Self-supervised and predictive learning
Motion field
The motion field is the projection of the 3D scene motion into the image
6
Optical flow
Definition: optical flow is the apparent motion of brightness patterns in the image
Ideally, optical flow would be the same as the motion field
Have to be careful: apparent motion can be caused by lighting changes without any actual motion
Think of a uniform rotating sphere under fixed lighting
vs. a stationary sphere under moving illumination
7
Estimating optical flow
Given two subsequent frames, estimate the apparent motion field u(x,y) and v(x,y) between them
Key assumptions
Brightness constancy: projection of the same point looks the same in every frame
Small motion: points do not move very far
Spatial coherence: points move like their neighbors
I(x,y,t–1)
I(x,y,t)
8
Brightness Constancy Equation:
Linearizing the right side using Taylor expansion:
The brightness constancy constraint
I(x,y,t–1)
I(x,y,t)
Hence,
9
The brightness constancy constraint
How many equations and unknowns per pixel?
One equation, two unknowns
What does this constraint mean?
The component of the flow perpendicular to the gradient (i.e., parallel to the edge) is unknown!
10
A: u and v are unknown, 1 equation
The brightness constancy constraint
How many equations and unknowns per pixel?
One equation, two unknowns
What does this constraint mean?
The component of the flow perpendicular to the gradient (i.e., parallel to the edge) is unknown!
edge
(u,v)
(u’,v’)
gradient
(u+u’,v+v’)
If (u, v) satisfies the equation,
so does (u+u’, v+v’) if
11
A: u and v are unknown, 1 equation
The aperture problem
Perceived motion
12
The aperture problem
Actual motion
13
The barber pole illusion
http://en.wikipedia.org/wiki/Barberpole_illusion
14
The barber pole illusion
http://en.wikipedia.org/wiki/Barberpole_illusion
15
Solving the aperture problem
How to get more equations for a pixel?
Spatial coherence constraint: assume the pixel’s neighbors have the same (u,v)
E.g., if we use a 5×5 window, that gives us 25 equations per pixel
B. Lucas and T. Kanade. An iterative image registration technique with an application to
stereo vision. In Proceedings of the International Joint Conference on Artificial Intelligence, pp. 674–679, 1981.
16
Lucas-Kanade flow
Linear least squares problem:
B. Lucas and T. Kanade. An iterative image registration technique with an application to
stereo vision. In Proceedings of the International Joint Conference on Artificial Intelligence, pp. 674–679, 1981.
When is this system solvable?
17
Lucas-Kanade flow
Linear least squares problem:
B. Lucas and T. Kanade. An iterative image registration technique with an application to
stereo vision. In Proceedings of the International Joint Conference on Artificial Intelligence, pp. 674–679, 1981.
(summations are over all pixels in the window)
Solution given by
M = ATA is the second moment matrix!
18
Recall: second moment matrix
1
2
“Corner”
1 and 2 are large,
1 ~ 2
1 and 2 are small
“Edge”
1 >> 2
“Edge”
2 >> 1
“Flat” region
Estimation of optical flow is well-conditioned precisely for regions with high “cornerness”:
19
Conditions for solvability
“Bad” case: single straight edge
20
Conditions for solvability
“Good” case
21
Lucas-Kanade flow example
Input frames
Output
Source: MATLAB Central File Exchange
Errors in Lucas-Kanade
The motion is large (larger than a pixel)
A point does not move like its neighbors
Brightness constancy does not hold
23
Iterative refinement:
Estimate velocity at each pixel using one iteration of Lucas and Kanade estimation
Warp one image toward the other using the estimated flow field
Refine estimate by repeating the process
“Flower garden” example
* From Khurram Hassan-Shafique CAP5415 Computer Vision 2003
“Flower garden” example
* From Khurram Hassan-Shafique CAP5415 Computer Vision 2003
Lucas-Kanade fails in areas of large motion
Multi-resolution estimation
* From Khurram Hassan-Shafique CAP5415 Computer Vision 2003
Multi-resolution estimation
* From Khurram Hassan-Shafique CAP5415 Computer Vision 2003
With multi-resolution estimation
Fixing the errors in Lucas-Kanade
The motion is large (larger than a pixel)
Multi-resolution estimation, iterative refinement
Feature matching
A point does not move like its neighbors
Motion segmentation
J. Wang and E. Adelson, Representing Moving Images with Layers, IEEE Transactions on Image Processing, 1994
28
Iterative refinement:
Estimate velocity at each pixel using one iteration of Lucas and Kanade estimation
Warp one image toward the other using the estimated flow field
Refine estimate by repeating the process
Fixing the errors in Lucas-Kanade
The motion is large (larger than a pixel)
Multi-resolution estimation, iterative refinement
Feature matching
A point does not move like its neighbors
Motion segmentation
Brightness constancy does not hold
Feature matching
29
Iterative refinement:
Estimate velocity at each pixel using one iteration of Lucas and Kanade estimation
Warp one image toward the other using the estimated flow field
Refine estimate by repeating the process
Feature tracking
C. Tomasi and T. Kanade. Shape and motion from image streams under orthography:
A factorization method. IJCV, 9(2):137-154, November 1992.
30
Feature tracking
If we have more than two images, we can track a feature from one frame to the next by following the optical flow
Challenges
Finding good features to track
Adding and deleting tracks
31
Shi-Tomasi feature tracker
Find good features using eigenvalues of second-moment matrix
Key idea: “good” features to track are the ones whose motion can be estimated reliably
From frame to frame, track with Lucas-Kanade
This amounts to assuming a translation model for frame-to-frame feature movement
Check consistency of tracks by affine registration to the first observed instance of the feature
Affine model is more accurate for larger displacements
Comparing to the first frame helps to minimize drift
J. Shi and C. Tomasi. Good Features to Track. CVPR 1994.
32
Tracking example
J. Shi and C. Tomasi. Good Features to Track. CVPR 1994.
33
Required reading
Further reading
https://docs.opencv.org/3.4/d4/dee/tutorial_optical_flow.html
)
,
(
)
1
,
,
(
),
,
(
)
,
(
t
y
x
y
x
v
y
u
x
I
t
y
x
I
+
+
=
–
)
,
(
)
,
(
)
,
,
(
)
1
,
,
(
y
x
v
I
y
x
u
I
t
y
x
I
t
y
x
I
y
x
+
+
»
–
0
»
+
+
t
y
x
I
v
I
u
I
0
=
+
+
t
y
x
I
v
I
u
I
0
)
,
(
=
+
×
Ñ
t
I
v
u
I
0
=
+
+
t
y
x
I
v
I
u
I
0
)
‘
,
‘
(
=
×
Ñ
v
u
I
0
)
(
]
,
[
)
(
=
+
×
Ñ
i
t
i
I
v
u
I
x
x
ú
ú
ú
ú
û
ù
ê
ê
ê
ê
ë
é
–
=
ú
û
ù
ê
ë
é
ú
ú
ú
ú
ú
û
ù
ê
ê
ê
ê
ê
ë
é
)
(
)
(
)
(
)
(
)
(
)
(
)
(
)
(
)
(
2
1
2
2
1
1
n
t
t
t
n
y
n
x
y
x
y
x
I
I
I
v
u
I
I
I
I
I
I
x
x
x
x
x
x
x
x
x
M
M
M
ú
ú
ú
ú
û
ù
ê
ê
ê
ê
ë
é
–
=
ú
û
ù
ê
ë
é
ú
ú
ú
ú
ú
û
ù
ê
ê
ê
ê
ê
ë
é
)
(
)
(
)
(
)
(
)
(
)
(
)
(
)
(
)
(
2
1
2
2
1
1
n
t
t
t
n
y
n
x
y
x
y
x
I
I
I
v
u
I
I
I
I
I
I
x
x
x
x
x
x
x
x
x
M
M
M
1
1
2
2
´
´
´
=
n
n
b
d
A
b
A
A)d
A
T
T
=
(
ú
ú
û
ù
ê
ê
ë
é
–
=
ú
û
ù
ê
ë
é
ú
ú
û
ù
ê
ê
ë
é
å
å
å
å
å
å
t
y
t
x
y
y
y
x
y
x
x
x
I
I
I
I
v
u
I
I
I
I
I
I
I
I
/docProps/thumbnail.jpeg