Lucas-Kanade tracker

From MMVLWiki
(Difference between revisions)
Jump to: navigation, search
(Added page about Lucas-Kanade tracker)
 
m
 
(38 intermediate revisions by one user not shown)
Line 1: Line 1:
=Lucas-Kanade tracker=
 
 
{|align=right
 
{|align=right
 
|-
 
|-
 
|<html><div class="thumb tright"><div style="width:320px;">
 
|<html><div class="thumb tright"><div style="width:320px;">
<embed style="width:320px; height:236px;" id="VideoPlayback" type="application/x-shockwave-flash" src="http://vision.eng.shu.ac.uk/jan/foodautomation/flvplayer.swf" width="320" height="236" flashvars="file=http://vision.eng.shu.ac.uk/jan/flv/lucaskanade.flv&image=http://vision.eng.shu.ac.uk/jan/flv/lucaskanade.jpg&displayheight=236" pluginspage="http://www.macromedia.com/go/getflashplayer"/>
+
<object type="application/x-shockwave-flash" data="http://vision.eng.shu.ac.uk/jan/flv/flvplayer.swf" width="320" height="236"><param name="flashvars" value="file=http://vision.eng.shu.ac.uk/jan/flv/lucaskanade.flv&amp;image=http://vision.eng.shu.ac.uk/jan/flv/lucaskanade.jpg&amp;searchbar=false&amp;displayheight=236" /><param name="movie" value="http://vision.eng.shu.ac.uk/jan/flv/flvplayer.swf" /><param name="allowfullscreen" value="true" /></object>
<div class="thumbcaption">Tracking 2-D affine transforms of a texture patch using Lucas-Kanade</div></div></div></html>
+
<div class="thumbcaption">Tracking of a texture patch in a <a href="http://www.nasa.gov/multimedia/hd/">NASA HD-video</a> with Lucas-Kanade tracker (using 2-D affine model)</div></div></div></html>
 +
|-
 +
|<html><div class="thumb tright"><div style="width:320px;">
 +
<object type="application/x-shockwave-flash" data="http://vision.eng.shu.ac.uk/jan/flv/flvplayer.swf" width="320" height="320"><param name="flashvars" value="file=http://vision.eng.shu.ac.uk/jan/flv/book.xml&amp;displayheight=240&amp;shuffle=false&amp;repeat=false&amp;searchbar=false"/><param name="movie" value="http://vision.eng.shu.ac.uk/jan/flv/flvplayer.swf" /><param name="allowfullscreen" value="true" /></object>
 +
<div class="thumbcaption">Visualisation of Lucas-Kanade template tracking (2-D affine model,2-D homography). Note that the algorithm is sensitive to illumination changes which are not modelled in this implementation (the videos can also be downloaded here:
 +
<a href="http://vision.eng.shu.ac.uk/jan/book.avi">2-D affine on a book (1.78 MByte)</a>, <a href="http://vision.eng.shu.ac.uk/jan/runninglinux.avi">2-D homography on a book (2.28 MByte)</a>, and <a href="http://vision.eng.shu.ac.uk/jan/cup.avi">2-D homography on a cup (2.05 MByte)</a>)
 +
</div></div></div></html>
 +
|-
 +
|<html>
 +
  <div class="thumb tright">
 +
    <div style="width:320px;">
 +
      <object type="application/x-shockwave-flash" data="http://vision.eng.shu.ac.uk/jan/flv/flvplayer.swf" width="320" height="340"><param name="flashvars" value="file=http://vision.eng.shu.ac.uk/jan/flv/indentation.xml&amp;shuffle=false&amp;repeat=false&amp;searchbar=false&amp;displayheight=260" /><param name="movie" value="http://vision.eng.shu.ac.uk/jan/flv/flvplayer.swf" /><param name="allowfullscreen" value="true" /></object>
 +
      <div class="thumbcaption" >
 +
        Tracking of a nano-indenter in a TEM-video (using isometric model) with <a href="http://vision.eng.shu.ac.uk/jan/tipfatigure.avi">high magnification</a> and <a href="http://vision.eng.shu.ac.uk/jan/tip10lk.avi">low magnification</a>. The indenter is lost where it moves to fast for the tracking algorithm
 +
      </div>
 +
    </div>
 +
  </div>
 +
</html>
 
|-
 
|-
 
|}
 
|}
The Lucas-Kanade algorithm iteratively tries to minimise the difference between the image and a warped template. The technique can be
+
The '''Lucas Kanade tracking algorithm''' iteratively tries to minimise the difference between the image and a warped template. The
used for image alignment, tracking, optic flow analysis, and motion estimation. In this example a texture patch in a Space Shuttle
+
technique can be used for image alignment, tracking, optic flow analysis, and motion estimation.
video is tracked over 324 frames. A 2-D affine transform was used as a model.
+
  
 
For the documentation of the mathematics have a look at the web-page of the CMU-project [http://www.ri.cmu.edu/projects/project_515.html "Lucas-Kanade 20 years on"] and at the
 
For the documentation of the mathematics have a look at the web-page of the CMU-project [http://www.ri.cmu.edu/projects/project_515.html "Lucas-Kanade 20 years on"] and at the
 
[http://www.ri.cmu.edu/pub_files/pub3/baker_simon_2004_1/baker_simon_2004_1.pdf publication by Baker and Matthews].
 
[http://www.ri.cmu.edu/pub_files/pub3/baker_simon_2004_1/baker_simon_2004_1.pdf publication by Baker and Matthews].
  
The implementation is available as an example application with [[HornetsEye]]. There also is a web-page with the [http://www.wedesoft.demon.co.uk/hornetseye-api/files/lktracker-txt.html source code of the Lucas-Kanade tracker].
+
==Implementation==
 +
The crucial parts of the implementation (here: 2-d isometric model, three degrees of freedom) are only a few lines of code. An initial parameter vector <code>p</code> (obtained by performing object recognition), an image <code>img</code> and a template <code>tpl</code> are required. In this example we are using a 2-d isometric model with three degrees of freedom (i.e. <code>p</code> has three elements). In
 +
this case the tracking algorithm (inverse compositional Lucas-Kanade) is initialised as follows:
 +
# three numbers indicating x-, y-position and angle
 +
p = Vector[ xshift, yshift, rotation ]
 +
# retrieve width and height of tracking template
 +
w, h = *tpl.shape
 +
# create a 2-D array with x-values and a 2-D array with y-values
 +
x, y = xramp( w, h ), yramp( w, h )
 +
sigma = 5.0
 +
gx = tpl.gauss_gradient_x( sigma )
 +
gy = tpl.gauss_gradient_y( sigma )
 +
# compute Jacobian matrix (note that x, y, gx, and gy are 2-D arrays)
 +
c = Matrix[ [ 1, 0 ], [ 0, 1 ], [ -y, x ] ] * Vector[ gx, gy ]
 +
# compute Hessian matrix
 +
hs = ( c * c.covector ).collect { |e| e.sum }
 +
 
 +
A tracking step then is done by applying the following piece of code to each image <code>img</code>. Usually the tracking step is performed
 +
multiple times on each image to improve the tracking estimate.
 +
# allocate 3-D array with warp vectors
 +
field = MultiArray.new( MultiArray::SFLOAT, w, h, 2 )
 +
# compute first component of warp vectors
 +
field[ 0...w, 0...h, 0 ] = x * cos( p[2] ) - y * sin( p[2] ) + p[0]
 +
# compute second component of warp vectors
 +
field[ 0...w, 0...h, 1 ] = x * sin( p[2] ) + y * cos( p[2] ) + p[1]
 +
# take difference of warped image and template
 +
diff = img.warp_clipped_interpolate( field ) - tpl
 +
# multiply with Jacobian (note that some elements of c are 2-D arrays)
 +
s = c.collect { |e| ( e * diff ).sum }
 +
# get estimate for change of pose
 +
d = hs.inverse * s
 +
# update pose vector
 +
p += Matrix[ [  cos(p[2]), -sin(p[2]), 0 ],
 +
              [  sin(p[2]),  cos(p[2]), 0 ],
 +
              [          0,          0, 1 ] ] * d
 +
 
 +
A full implementation is available as an example application with [[HornetsEye]]. The implementation does interpolation which is very important for the stability of the Lucas-Kanade tracker. Furthermore the gradient is computed using the surroundings of the initial template to avoid boundary effects. Note that the implementation does not model illumination changes so that the homography and the
 +
affine model required controlled lighting conditions. You can find a listing of the source code [http://www.wedesoft.demon.co.uk/hornetseye-api/files/lktracker-txt.html here].
  
[[Image:Working.gif]]
 
 
=See Also=
 
=See Also=
 
* [[Image:Hornetseye.png|40px]] [[HornetsEye]]
 
* [[Image:Hornetseye.png|40px]] [[HornetsEye]]
 +
* [[Random Sample Consensus]]
 +
* [[Registration of TEM images]]
 
* [[Gradient Based Motion Estimation]]
 
* [[Gradient Based Motion Estimation]]
  
 
=External Links=
 
=External Links=
 
* [http://www.wedesoft.demon.co.uk/hornetseye-api/files/lktracker-txt.html Hornetseye implementation]
 
* [http://www.wedesoft.demon.co.uk/hornetseye-api/files/lktracker-txt.html Hornetseye implementation]
 +
* J. Wedekind, B. P. Amavasai, K. Dutton, M. Boissenin: [http://digitalcommons.shu.ac.uk/mmvl_papers/2/ A Machine Vision Extension for the Ruby Programming Language] (also see [http://vision.eng.shu.ac.uk/jan/icia08-foils.pdf foils (PDF)])
 
* [http://www.ri.cmu.edu/projects/project_515.html CMU project: "Lucas-Kanade 20 years on"]
 
* [http://www.ri.cmu.edu/projects/project_515.html CMU project: "Lucas-Kanade 20 years on"]
 
** S. Baker, I. Matthews: [http://www.ri.cmu.edu/pub_files/pub3/baker_simon_2004_1/baker_simon_2004_1.pdf Lucas-Kanade 20 Years On: A Unifying Framework], International Journal of Computer Vision, Vol. 56, No. 3, March, 2004, pp. 221-255.
 
** S. Baker, I. Matthews: [http://www.ri.cmu.edu/pub_files/pub3/baker_simon_2004_1/baker_simon_2004_1.pdf Lucas-Kanade 20 Years On: A Unifying Framework], International Journal of Computer Vision, Vol. 56, No. 3, March, 2004, pp. 221-255.
 
* [http://www.nasa.gov/multimedia/hd/HDGalleryCollection_archive_1.html NASA high definition videos]
 
* [http://www.nasa.gov/multimedia/hd/HDGalleryCollection_archive_1.html NASA high definition videos]
 +
 +
{{Addthis}}
 +
 +
[[Category:Projects]]
 +
[[Category:Nanorobotics]]

Latest revision as of 21:49, 18 May 2010

Tracking of a texture patch in a NASA HD-video with Lucas-Kanade tracker (using 2-D affine model)
Visualisation of Lucas-Kanade template tracking (2-D affine model,2-D homography). Note that the algorithm is sensitive to illumination changes which are not modelled in this implementation (the videos can also be downloaded here: 2-D affine on a book (1.78 MByte), 2-D homography on a book (2.28 MByte), and 2-D homography on a cup (2.05 MByte))
Tracking of a nano-indenter in a TEM-video (using isometric model) with high magnification and low magnification. The indenter is lost where it moves to fast for the tracking algorithm

The Lucas Kanade tracking algorithm iteratively tries to minimise the difference between the image and a warped template. The technique can be used for image alignment, tracking, optic flow analysis, and motion estimation.

For the documentation of the mathematics have a look at the web-page of the CMU-project "Lucas-Kanade 20 years on" and at the publication by Baker and Matthews.

[edit] Implementation

The crucial parts of the implementation (here: 2-d isometric model, three degrees of freedom) are only a few lines of code. An initial parameter vector p (obtained by performing object recognition), an image img and a template tpl are required. In this example we are using a 2-d isometric model with three degrees of freedom (i.e. p has three elements). In this case the tracking algorithm (inverse compositional Lucas-Kanade) is initialised as follows:

# three numbers indicating x-, y-position and angle
p = Vector[ xshift, yshift, rotation ]
# retrieve width and height of tracking template
w, h = *tpl.shape
# create a 2-D array with x-values and a 2-D array with y-values
x, y = xramp( w, h ), yramp( w, h )
sigma = 5.0
gx = tpl.gauss_gradient_x( sigma )
gy = tpl.gauss_gradient_y( sigma )
# compute Jacobian matrix (note that x, y, gx, and gy are 2-D arrays)
c = Matrix[ [ 1, 0 ], [ 0, 1 ], [ -y, x ] ] * Vector[ gx, gy ]
# compute Hessian matrix
hs = ( c * c.covector ).collect { |e| e.sum }

A tracking step then is done by applying the following piece of code to each image img. Usually the tracking step is performed multiple times on each image to improve the tracking estimate.

# allocate 3-D array with warp vectors
field = MultiArray.new( MultiArray::SFLOAT, w, h, 2 )
# compute first component of warp vectors
field[ 0...w, 0...h, 0 ] = x * cos( p[2] ) - y * sin( p[2] ) + p[0]
# compute second component of warp vectors
field[ 0...w, 0...h, 1 ] = x * sin( p[2] ) + y * cos( p[2] ) + p[1]
# take difference of warped image and template
diff = img.warp_clipped_interpolate( field ) - tpl
# multiply with Jacobian (note that some elements of c are 2-D arrays)
s = c.collect { |e| ( e * diff ).sum }
# get estimate for change of pose
d = hs.inverse * s
# update pose vector
p += Matrix[ [  cos(p[2]), -sin(p[2]), 0 ],
             [  sin(p[2]),  cos(p[2]), 0 ],
             [          0,          0, 1 ] ] * d

A full implementation is available as an example application with HornetsEye. The implementation does interpolation which is very important for the stability of the Lucas-Kanade tracker. Furthermore the gradient is computed using the surroundings of the initial template to avoid boundary effects. Note that the implementation does not model illumination changes so that the homography and the affine model required controlled lighting conditions. You can find a listing of the source code here.

[edit] See Also

[edit] External Links

Bookmark and Share

Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox