Anda di halaman 1dari 78

Stanford CS223B Computer Vision, Winter 2007

Lecture 12
Tracking Motion
Professors Sebastian Thrun and Jana Koeck
CAs: Vaibhav Vaish and David Stavens



Sebastian Thrun and Jana Koeck CS223B Computer Vision, Winter 2007
Overview
The Tracking Problem
Bayes Filters
Particle Filters
Kalman Filters
Using Kalman Filters

Sebastian Thrun and Jana Koeck CS223B Computer Vision, Winter 2007
The Tracking Problem
Can we estimate the position of the object?
Can we estimate its velocity?
Can we predict future positions?
Image 4 Image 1 Image 2 Image 3
Sebastian Thrun and Jana Koeck CS223B Computer Vision, Winter 2007
The Tracking Problem
Given Sequence of Images
Find center of moving object
Camera might be moving or stationary


We assume: We can find object in individual
images.
The Problem: Track across multiple images.

Is a fundamental problem in computer vision
Sebastian Thrun and Jana Koeck CS223B Computer Vision, Winter 2007
Methods
Bayes Filter
Particle Filter
Uncented
Kalman Filter
Kalman Filter
Extended
Kalman Filter
Sebastian Thrun and Jana Koeck CS223B Computer Vision, Winter 2007
Further Reading
Sebastian Thrun and Jana Koeck CS223B Computer Vision, Winter 2007
Example: Moving Object
Sebastian Thrun and Jana Koeck CS223B Computer Vision, Winter 2007
Kalman Filter Tracking
Sebastian Thrun and Jana Koeck CS223B Computer Vision, Winter 2007
Particle Filter Tracking
Sebastian Thrun and Jana Koeck CS223B Computer Vision, Winter 2007
Mixture of KF / PF (Unscented PF)
Sebastian Thrun and Jana Koeck CS223B Computer Vision, Winter 2007
Overview
The Tracking Problem
Bayes Filters
Particle Filters
Kalman Filters
Using Kalman Filters

Sebastian Thrun and Jana Koeck CS223B Computer Vision, Winter 2007
Slow
Down!
Example of Bayesian Inference
?
Environment prior
p(staircase) = 0.1
Bayesian inference
p(staircase | image)
p(image | staircasse) p(staircase)
p(im | stair) p(stair) + p(im | no stair) p(no stair)
= 0.7 - 0.1 / (0.7 - 0.1 + 0.2 - 0.9) = 0.28
Sensor model
p(image | staircase) = 0.7
p(image | no staircase) = 0.2
p(staircase)
= 0.28
Cost model
cost(fast walk | staircase) = $1,000
cost(fast walk | no staircase) = $0
cost(slow+sense) = $1
Decision Theory
E[cost(fast walk)] = $1,000 - 0.28 = $280
E[cost(slow+sense)] = $1
=
Sebastian Thrun and Jana Koeck CS223B Computer Vision, Winter 2007
Bayes Filter Definition
Environment state x
t
Measurement z
t

Can we calculate p(x
t
| z
1
, z
2
, , z
t
) ?
Sebastian Thrun and Jana Koeck CS223B Computer Vision, Winter 2007
Bayes Filters Illustrated
Sebastian Thrun and Jana Koeck CS223B Computer Vision, Winter 2007
Bayes Filters: Essential Steps
Belief: Bel(x
t
)

Measurement update: Bel(x
t
) Bel(x
t
) p(z
t
|x
t
)
Time update: Bel(x
t+1
) Bel(x
t
) p(x
t+1
|u
t
,x
t
)

Sebastian Thrun and Jana Koeck CS223B Computer Vision, Winter 2007
x = state
t = time
z = observation
u = action
q = constant
Bayes Filters
) , | ( ) (
0 0 t t t t
u z x p x Bel

=
) , , , | ( ) , , , , | (
0 1 1 0 1 1
z z u x p z z u x z p
t t t t t t t


= q
) , , , | ( ) | (
0 1 1
z z u x p x z p
t t t t t


= q
1 0 1 1 0 1 1
) , , | ( ) , , , | ( ) | (

}
=
t t t t t t t t
dx z u x p z u x x p x z p q
1 1 1 1
) ( ) , | ( ) | (

}
=
t t t t t t t
dx x Bel u x x p x z p q
) , , , , | (
0 1 1
u z u z x p
t t t t


=
Markov
Bayes
Markov
1 0 2 1 1 1 1
) , , | ( ) , | ( ) | (

}
=
t t t t t t t t t
dx u u z x p u x x p x z p q
Sebastian Thrun and Jana Koeck CS223B Computer Vision, Winter 2007
Bayes Filters
x = state
t = time
z = observation
u = action
1 1 1 1
) ( ) , | ( ) | ( ) (

}
=
t t t t t t t t
dx x Bel u x x p x z p x Bel q
Sebastian Thrun and Jana Koeck CS223B Computer Vision, Winter 2007
Bayes Filters Illustrated
Sebastian Thrun and Jana Koeck CS223B Computer Vision, Winter 2007
Bayes Filters
Initial Estimate of State
Iterate
Receive measurement, update your belief (uncertainty
shrinks)
Predict, update your belief (uncertainty grows)

Sebastian Thrun and Jana Koeck CS223B Computer Vision, Winter 2007
Methods
Bayes Filter
Particle Filter
Uncented
Kalman Filter
Kalman Filter
Extended
Kalman Filter
Sebastian Thrun and Jana Koeck CS223B Computer Vision, Winter 2007
Overview
The Tracking Problem
Bayes Filters
Particle Filters
Kalman Filters
Using Kalman Filters

Sebastian Thrun and Jana Koeck CS223B Computer Vision, Winter 2007
Particle Filters: Basic Idea
) (x p
t
x
) | ( ) (
... 1 t t t t
z x p X x p ~ e
(equality for ) | n
set of n particles X
t


Sebastian Thrun and Jana Koeck CS223B Computer Vision, Winter 2007
Particle Filter Explained
Sebastian Thrun and Jana Koeck CS223B Computer Vision, Winter 2007
1 1 ... 1 1 ... 1 1 1 ... 1 ... 1
) , | ( ) , | ( ) | ( ) , | (

}
=
t t t t t t t t t t t t
dx u z x p x u x p x z p u z x p q
Basic Particle Filter Algorithm
) , | ( ) (
... 1 ... 1 t t t t t
u z x p X x p ~ e
Initialization:
X
0
n particles x
0
[i]
~ p(x
0
)
particleFilters(X
t 1
){
for i=1 to n
x
t
[i]
~ p(x
t

| x
t 1
[i]
) (prediction)
w
t
[i]
= p(z
t

| x
t
[i]
) (importance weights)
endfor
for i=1 to n
include x
t
[i]
in X
t
with probability w
t
[i]
(resampling)

}
Sebastian Thrun and Jana Koeck CS223B Computer Vision, Winter 2007
Weight samples: w = f / g
Importance Sampling
Sebastian Thrun and Jana Koeck CS223B Computer Vision, Winter 2007
Particle Filter
By Frank Dellaert
Sebastian Thrun and Jana Koeck CS223B Computer Vision, Winter 2007
Case Study:
Track moving objects from Helicopter
1. Harris Corners
2. Optical Flow (with clustering)
3. Motion likelihood function
4. Particle Filter
5. Centroid Extraction
David Stavens, Andrew Lookingbill, David Lieb, CS223b Winter 2004
Sebastian Thrun and Jana Koeck CS223B Computer Vision, Winter 2007
1. Harris Corner Extraction
David Stavens, Andrew Lookingbill, David Lieb, CS223b Winter 2004
Sebastian Thrun and Jana Koeck CS223B Computer Vision, Winter 2007
2. Optical Flow + Motion Detection
David Stavens, Andrew Lookingbill, David Lieb, CS223b Winter 2004
Sebastian Thrun and Jana Koeck CS223B Computer Vision, Winter 2007
3. Motion Likelihood Function
David Stavens, Andrew Lookingbill, David Lieb, CS223b Winter 2004
Sebastian Thrun and Jana Koeck CS223B Computer Vision, Winter 2007
4. Particle Filters
David Stavens, Andrew Lookingbill, David Lieb, CS223b Winter 2004
Sebastian Thrun and Jana Koeck CS223B Computer Vision, Winter 2007
5. Extract Centroid
David Stavens, Andrew Lookingbill, David Lieb, CS223b Winter 2004
Sebastian Thrun and Jana Koeck CS223B Computer Vision, Winter 2007
More Particle Filter Tracking
David Stavens, Andrew Lookingbill, David Lieb, CS223b Winter 2004
Sebastian Thrun and Jana Koeck CS223B Computer Vision, Winter 2007
Some Robotics Examples
Tracking Hands, People
Mobile Robot localization
People localization
Car localization
Mapping
Sebastian Thrun and Jana Koeck CS223B Computer Vision, Winter 2007
Examples Particle Filter
Siu Chi Chan McGill University

Sebastian Thrun and Jana Koeck CS223B Computer Vision, Winter 2007
Another Example
Mike Isard and Andrew Blake

Sebastian Thrun and Jana Koeck CS223B Computer Vision, Winter 2007
Tracking Fast moving Objects

K. Toyama, A.Blake
Sebastian Thrun and Jana Koeck CS223B Computer Vision, Winter 2007
Particle Filters: Illustration
With: Wolfram Burgard, Dieter Fox, Frank Dellaert

) , | ( ) (
... 1 ... 1 t t t t t
u z x p X x p ~ e
Sebastian Thrun and Jana Koeck CS223B Computer Vision, Winter 2007
Particle Filters (1)
Sebastian Thrun and Jana Koeck CS223B Computer Vision, Winter 2007
Particle Filters (2)

Sebastian Thrun and Jana Koeck CS223B Computer Vision, Winter 2007
Particles = Robustness
Sebastian Thrun and Jana Koeck CS223B Computer Vision, Winter 2007
Tracking People from Moving Platform

- robot location (particles)
- people location (particles)
- laser measurements (wall)

With Michael Montemerlo
Sebastian Thrun and Jana Koeck CS223B Computer Vision, Winter 2007
Tracking People from Moving Platform
With Michael Montemerlo

- robot location (particles)
- people location (particles)
- laser measurements (wall)

Sebastian Thrun and Jana Koeck CS223B Computer Vision, Winter 2007
Particle Filters for Tracking Cars
With Anya Petrovskaya
Sebastian Thrun and Jana Koeck CS223B Computer Vision, Winter 2007
Mapping Environments (SFM)
With Dirk Haehnel
Sebastian Thrun and Jana Koeck CS223B Computer Vision, Winter 2007
Overview
The Tracking Problem
Bayes Filters
Particle Filters
Kalman Filters
Using Kalman Filters

Sebastian Thrun and Jana Koeck CS223B Computer Vision, Winter 2007
Tracking with KFs: Gaussians!
update initial estimte
x
y
x
y
prediction
x
y
measurement
x
y
Sebastian Thrun and Jana Koeck CS223B Computer Vision, Winter 2007
Kalman Filters
) , ( ~ ) ( E N x p
)
`

E

) ( ) (
2
1
exp ) (
1
x x x p
T
Sebastian Thrun and Jana Koeck CS223B Computer Vision, Winter 2007
Kalman Filters
prior
Measurement
evidence
posterior
) ( ) | ( ) | ( x p x z p z x p
dx x p x x p x p ) ( ) | ' ( ) ' (
}
=
Sebastian Thrun and Jana Koeck CS223B Computer Vision, Winter 2007
A Quiz
prior
Measurement
evidence
) ( ) | ( ) | ( x p x z p z x p
posterior?
Sebastian Thrun and Jana Koeck CS223B Computer Vision, Winter 2007
Gaussians
2
2
) (
2
1
2
2
1
) (
: ) , ( ~ ) (
o

o t
o

=
x
e x p
N x p
-o o

Univariate
) ( ) (
2
1
2 / 1
2 /
1
) 2 (
1
) (
: ) ( ~ ) (
x x

x
x


=
t
e p
, p
d
t

Multivariate
Sebastian Thrun and Jana Koeck CS223B Computer Vision, Winter 2007
) , ( ~
) , ( ~
2 2
2
o
o
a b a N Y
b aX Y
N X
+
)
`

+ =
Properties of Univariate Gaussians
|
|
.
|

\
|
+ +
+
+

)
`

2
2
2
1
2
2
2
2
1
2
1
1
2
2
2
1
2
2
2 1
2
2 2 2
2
1 1 1
1
, ~ ) ( ) (
) , ( ~
) , ( ~
o o

o o
o

o o
o
o
o
N X p X p
N X
N X
Sebastian Thrun and Jana Koeck CS223B Computer Vision, Winter 2007
Measurement Update Derived
( ) ( )
)
`

=
)
`

2
2
2
2
2
1
2
1
2 1
2
2 2 2
2
1 1 1
2
1
2
1
exp const. ) ( ) (
) , ( ~
) , ( ~
o

o
o x x
X p X p
N X
N X
( ) ( )
) new (for 0
2
1
2
1
2
2
2
2
1
1
2
2
2
2
2
1
2
1

o

o

o

=
)
`

c
c x x x x
x
( ) ( ) 0
2
1 2
2
2 1
= + o o
2
1 2
2
2 1
2
2
2
1
) ( o o o o + = +
2
2
2
1
2
1 2
2
2 1
o o
o o

+
+
=
( ) ( )
2
2
2
1
2
2
2
2
2
1
2
1
2
2
2
1
2
1

+ =
)
`

c
c
o o
o

o
x x
x
2
2
2
1
1

+
=
o o
o
Sebastian Thrun and Jana Koeck CS223B Computer Vision, Winter 2007







We stay in the Gaussian world as long as we start with Gaussians
and perform only linear transformations.
) , ( ~
) , ( ~
T
A A B A N Y
B AX Y
N X
E +
)
`

+ =
E

Properties Multivariate Gaussians


Essentially the same as in the 1-D case, but with more general notation
( )
1 1
2
1
1 2 1
1
2 1 1 2
1
2 1 2 1
2 2 2
1 1 1
) ( , ) ( ) ( ~ ) ( ) (
) , ( ~
) , ( ~

E + E E E + E + E E + E
)
`

E
E

N X p X p
N X
N X
Sebastian Thrun and Jana Koeck CS223B Computer Vision, Winter 2007
Linear Kalman Filter
t t t t t t
u B x A x c + + =
1
t t t t
x C z o + =
Estimates the state x of a discrete-time
controlled process that is governed by the
linear stochastic difference equation
with a measurement
Sebastian Thrun and Jana Koeck CS223B Computer Vision, Winter 2007
Components of a Kalman Filter
t
c
Matrix (n n) that describes how the state
evolves from t to t+1 without controls or
noise.
t
A
Matrix (n i) that describes how the control
u
t
changes the state from t to t+1.
t
B
Matrix (k n) that describes how to map the
state x
t
to an observation z
t
.
t
C
t
o
Random variables representing the process
and measurement noise that are assumed to
be independent and normally distributed
with covariance R
t
and Q
t
respectively.
Sebastian Thrun and Jana Koeck CS223B Computer Vision, Winter 2007
Kalman Filter Algorithm
1. Algorithm Kalman_filter(
t-1
,

E
t-1
, u
t
, z
t
):

2. Prediction:
3.
4.

5. Correction:
6.
7.
8.
9. Return
t
,

E
t

t t t t t
u B A + =
1

t
T
t t t
t R A A + E = E
1
t
t t t
C K I E = E ) (
1
) (

+ E E =
t
T
t
t
t
T
t
t
t
Q C C C K
) (
t t t t t t
C z K + =
Sebastian Thrun and Jana Koeck CS223B Computer Vision, Winter 2007
Kalman Filter Updates in 1D
old belief
measurement
belief
new belief
belief
Sebastian Thrun and Jana Koeck CS223B Computer Vision, Winter 2007
Kalman Filter Updates in 1D
1
) ( with
) (
) (
) (

+ E E =

E = E
+ =
=
t
T
t
t
t
T
t
t
t
t
t t t
t t t t t t
t
Q C C C K
C K I
C z K
x bel

2
,
2
2
2 2
with
) 1 (
) (
) (
t obs t
t
t
t t t
t t t t t
t
K
K
z K
x bel
o o
o
o o

+
=

=
+ =
=
old belief
new belief
Sebastian Thrun and Jana Koeck CS223B Computer Vision, Winter 2007
Kalman Filter Updates in 1D

+ E = E
+ =
=

t
T
t t t
t
t t t t t
t
R A A
u B A
x bel
1
1
) (

+ =
+ =
=

2
,
2 2 2
1
) (
t act t t t
t t t t t
t
a
u b a
x bel
o o o

old belief
new belief new belief
newest belief
Sebastian Thrun and Jana Koeck CS223B Computer Vision, Winter 2007
Kalman Filter Updates
belief
latest belief
belief
measurement
belief
Sebastian Thrun and Jana Koeck CS223B Computer Vision, Winter 2007
The Prediction-Correction-Cycle

+ E = E
+ =
=

t
T
t t t
t
t t t t t
t
R A A
u B A
x bel
1
1
) (

+ =
+ =
=

2
,
2 2 2
1
) (
t act t t t
t t t t t
t
a
u b a
x bel
o o o

Prediction
Sebastian Thrun and Jana Koeck CS223B Computer Vision, Winter 2007
The Prediction-Correction-Cycle
1
) ( ,
) (
) (
) (

+ E E =

E = E
+ =
=
t
T
t
t
t
T
t
t
t
t
t t t
t t t t t t
t
Q C C C K
C K I
C z K
x bel

2
,
2
2
2 2
,
) 1 (
) (
) (
t obs t
t
t
t t t
t t t t t
t
K
K
z K
x bel
o o
o
o o

+
=

=
+ =
=
Correction
Sebastian Thrun and Jana Koeck CS223B Computer Vision, Winter 2007
The Prediction-Correction-Cycle
1
) ( ,
) (
) (
) (

+ E E =

E = E
+ =
=
t
T
t
t
t
T
t
t
t
t
t t t
t t t t t t
t
Q C C C K
C K I
C z K
x bel

2
,
2
2
2 2
,
) 1 (
) (
) (
t obs t
t
t
t t t
t t t t t
t
K
K
z K
x bel
o o
o
o o

+
=

=
+ =
=

+ E = E
+ =
=

t
T
t t t
t
t t t t t
t
R A A
u B A
x bel
1
1
) (

+ =
+ =
=

2
,
2 2 2
1
) (
t act t t t
t t t t t
t
a
u b a
x bel
o o o

Correction
Prediction
Sebastian Thrun and Jana Koeck CS223B Computer Vision, Winter 2007
Kalman Filter Summary
Highly efficient: Polynomial in measurement
dimensionality k and state dimensionality n:
O(k
2.376
+ n
2
)

Optimal for linear Gaussian systems!

Most robotics systems are nonlinear!
Sebastian Thrun and Jana Koeck CS223B Computer Vision, Winter 2007
Overview
The Tracking Problem
Bayes Filters
Particle Filters
Kalman Filters
Using Kalman Filters

Sebastian Thrun and Jana Koeck CS223B Computer Vision, Winter 2007
Lets Apply KFs to Tracking Problem
Image 4 Image 1 Image 2 Image 3
Sebastian Thrun and Jana Koeck CS223B Computer Vision, Winter 2007
Kalman Filter with 2-Dim Linear Model
Linear Change (Motion)




Linear Measurement Model
) , 0 ( Q N D Cx z + + =
|
|
.
|

\
|
=
2
2
0
0
o
o
Q
|
|
.
|

\
|
=
0
0
D
|
|
.
|

\
|
=
1 0
0 1
C
|
|
.
|

\
|
=
0
0
B
|
|
.
|

\
|
=
1 0
0 1
A
) , 0 ( ' R N B Ax x + + =
|
|
.
|

\
|
=
2
2
0
0

R
Sebastian Thrun and Jana Koeck CS223B Computer Vision, Winter 2007
Kalman Filter Algorithm
1. Algorithm Kalman_filter(
t-1
,

E
t-1
, u
t
, z
t
):

2. Prediction:
3.
4.

5. Correction:
6.
7.
8.
9. Return
t
,

E
t

t t t t t
u B A + =
1

t
T
t t t
t R A A + E = E
1
1
) (

+ E E =
t
T
t
t
t
T
t
t
t
Q C C C K
) ( D C z K
t t t t t t
+ =
t
t t t
C K I E = E ) (
|
|
.
|

\
|
=
2
2
0
0
o
o
Q
|
|
.
|

\
|
=
0
0
D
|
|
.
|

\
|
=
1 0
0 1
C
|
|
.
|

\
|
=
0
0
B
|
|
.
|

\
|
=
1 0
0 1
A
|
|
.
|

\
|
=
2
2
0
0

R
Sebastian Thrun and Jana Koeck CS223B Computer Vision, Winter 2007
Kalman Filter in Detail
Measurements
Change
Prediction
Measurement Update


) , 0 ( R N x z + =
) , 0 ( ' Q N x x + =
( )
) ' ( ' ' ' ' '
' ' '
1
1
1 1
E + =
+ E = E


z R
R
= + E = E ' ' Q
update initial position
x
y
x
y
prediction
x
y
measurement
x
y
Sebastian Thrun and Jana Koeck CS223B Computer Vision, Winter 2007
Can We Do Better?
Sebastian Thrun and Jana Koeck CS223B Computer Vision, Winter 2007
Kalman, Better!
initial position prediction measurement
x

x
x

x
x

x
next prediciton
x

x
update
x

x
Sebastian Thrun and Jana Koeck CS223B Computer Vision, Winter 2007
We Can Estimate Velocity!
past measurements
prediction
Sebastian Thrun and Jana Koeck CS223B Computer Vision, Winter 2007
Kalman Filter For 2D Tracking
Linear Measurement model (now with 4 state variables)




Linear Change


|
|
|
|
|
.
|

\
|
=
2
2
0 0 0
0 0 0
0 0 0 0
0 0 0 0
q
q
Q
|
|
.
|

\
|
=
2
2
0
0
r
r
R ) , 0 (
0 0 1 0
0 0 0 1
R N
y
x
y
x
y
x
obs
obs
+
|
|
|
|
|
.
|

\
|
|
|
.
|

\
|
=
|
|
.
|

\
|

) , 0 (
1 0 0 0
0 1 0 0
0 1 0
0 0 1
'
'
'
'
Q N
y
x
y
x
t
t
y
x
y
x
+
|
|
|
|
|
.
|

\
|
|
|
|
|
|
.
|

\
|
A
A
=
|
|
|
|
|
.
|

\
|

Sebastian Thrun and Jana Koeck CS223B Computer Vision, Winter 2007
Putting It Together Again
Measurements


Change


Prediction


Measurement Update



) , 0 (
0 0 1 0
0 0 0 1
R N x z +
|
|
.
|

\
|
=

) , 0 (
1 0 0 0
0 1 0 0
0 1 0
0 0 1
' Q N x
t
t
x +
|
|
|
|
|
.
|

\
|
A
A
=

( )
) ( ' '
'
1
1
1 1
A z R A
A R A
T
T
E + =
+ E = E


C
CQC
T
=
+ E = E
'
'
Sebastian Thrun and Jana Koeck CS223B Computer Vision, Winter 2007
Summary Kalman Filter
Estimates state of a system
Position
Velocity
Many other continuous state variables possible
KF maintains
Mean vector for the state
Covariance matrix of state uncertainty
Implements
Time update = prediction
Measurement update
Standard Kalman filter is linear-Gaussian
Linear system dynamics, linear sensor model
Additive Gaussian noise (independent)
Nonlinear extensions: extended KF, unscented KF: linearize
More info:
CS226
Probabilistic Robotics (Thrun/Burgard/Fox, MIT Press)
Sebastian Thrun and Jana Koeck CS223B Computer Vision, Winter 2007
Summary Kalman Filter
Estimates state of a system
Position
Velocity
Many other continuous state variables possible
KF maintains
Mean vector for the state
Covariance matrix of state uncertainty
Implements
Time update = prediction
Measurement update
Standard Kalman filter is linear-Gaussian
Linear system dynamics, linear sensor model
Additive Gaussian noise (independent)
Nonlinear extensions: extended KF, unscented KF: linearize
More info:
CS226
Probabilistic Robotics (Thrun/Burgard/Fox, MIT Press)
Particle
and discrete
set of particles
(example states)
= predictive sampling
= resampling, importance weights
fully nonlinear
Sebastian Thrun and Jana Koeck CS223B Computer Vision, Winter 2007
Summary
The Tracking Problem
Bayes Filters
Particle Filters
Kalman Filters
Using Kalman Filters

Anda mungkin juga menyukai