codeanticode.progpuklt
Class FeatureTracker

java.lang.Object
  extended by codeanticode.progpuklt.FeatureTracker

public class FeatureTracker
extends java.lang.Object

This class encapsulates the GPU implementation of the KLT feature tracker, developed by Christopher Zach at the University of North Carolina at Chapel Hill. Features are defined to be corners points (pixels with large intensity variations along the x and y directions) found in the image, and the algorithm is able to follow these feature points through successive frames, until they disappear and are replaced by new features. This GPU implementation is substantially faster than a regular CPU version. More information about the KLT tracker can be found in the following pages:
Christopher Zach's GPU-KLT page
CPU implementation of KLT by Stan Birchfield
Wikipedia entry about the KLT algorithm
Page about KLT tracker in computer vision tutorial

Author:
Andres Colubri

Constructor Summary
FeatureTracker(processing.core.PApplet parent, int imgWidth, int imgHeight, int nFeatures)
          Creates an instance of FeatureTracker to track nFeatures features on images with a resolution of imgWidth x imgHeight pixels.
FeatureTracker(processing.core.PApplet parent, int imgWidth, int imgHeight, int nFeatures, FeatureTrackerParameters params)
          Creates an instance of FeatureTracker to track nFeatures features on images with a resolution of imgWidth x imgHeight pixels.
 
Method Summary
 void drawFeatures(float diam)
          Draws the current positions of all the feature points using circles of diameter diam.
 void drawFeatures(float x, float y, float w, float h, float diam)
          Draws the current positions of all the feature points using circles of diameter diam.
 void drawTracks()
          Draws the tracks for all the feature points using lines connecting successive positions.
 void drawTracks(float x, float y, float w, float h)
          Draws the tracks for all the feature points using lines connecting successive positions.
 int getHeight()
          Returns the supported image height.
 int getMaxTrackLength()
          Returns the maximum track length.
 int getNDetectedFeatures()
          Returns the number of detected features when running the track method for the first time.
 int getNFeatures()
          Returns the number of features being detected and tracked.
 int getNNewFeatures()
          Returns the number of re-detected features.
 int getNPresentFeatures()
          Returns the number of present features being tracked.
 float getPosX(int i)
          Returns the current x coordinate feature i.
 float getPosY(int i)
          Returns the current y coordinate feature i.
 FeatureTrack getTrack(int i)
          Returns the entire track of feature i.
 int getTrackLength(int i)
          Returns the current track length of feature i.
 float getTrackX(int i, int t)
          Returns the x coordinate of position of feature i at frame t.
 float getTrackY(int i, int t)
          Returns the y coordinate of position of feature i at frame t.
 int getWidth()
          Returns the supported image width.
static void setMaxTrackLength(int mLength)
          Sets the maximum length of a feature track (in frames), i.e., how many post positions will be stored for a given feature point until it disappears from the image.
 void stop()
          Stops the tracker.
 void track(int texID)
          Track features in the image stored in the OpenGL texture with id texID.
 void track(int[] pixels)
          Track features in the image stored in the pixels array.
 void track(processing.core.PImage image)
          Track features in the image stored in the PImage object.
 boolean trackRestarted(int i)
          Returns true or false depending on weather feature i has been restarted or not.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FeatureTracker

public FeatureTracker(processing.core.PApplet parent,
                      int imgWidth,
                      int imgHeight,
                      int nFeatures)
Creates an instance of FeatureTracker to track nFeatures features on images with a resolution of imgWidth x imgHeight pixels. The actual number nFeatures that the tracker uses is adjusted from the input value to the closest number that can be expressed as a power-of-two integer. This adjusted value can be obtained by calling the getNFeatures() method.

Parameters:
parent - PApplet
imgWidth - int
imgHeight - int
nFeatures - int
See Also:
getNFeatures

FeatureTracker

public FeatureTracker(processing.core.PApplet parent,
                      int imgWidth,
                      int imgHeight,
                      int nFeatures,
                      FeatureTrackerParameters params)
Creates an instance of FeatureTracker to track nFeatures features on images with a resolution of imgWidth x imgHeight pixels. The actual number nFeatures that the tracker uses is adjusted from the input value to the closest number that can be expressed as a power-of-two integer. This adjusted value can be obtained by calling the getNFeatures() method. Further tracker parameters can be set with the params object.

Parameters:
parent - PApplet
imgWidth - int
imgHeight - int
nFeatures - int
params - FeatureTrackerParameters
See Also:
getNFeatures, FeatureTrackerParameters
Method Detail

setMaxTrackLength

public static void setMaxTrackLength(int mLength)
Sets the maximum length of a feature track (in frames), i.e., how many post positions will be stored for a given feature point until it disappears from the image. If a feature points exists longer than this value, the first mLength - 1 recorded positions are kept, but the last one is constantly updated to be the current feature position, thus discarding all the past positions between mLength - 1 and the current one. This value cannot be updated unless the tracker object is re-created.

Parameters:
mLength - int

track

public void track(int texID)
Track features in the image stored in the OpenGL texture with id texID. This is usually much faster than using the track() method with the PImage or int[] parameters, since those require transferring the image from CPU to GPU memory.

Parameters:
texID - int

track

public void track(processing.core.PImage image)
Track features in the image stored in the PImage object.

Parameters:
image - PImage

track

public void track(int[] pixels)
Track features in the image stored in the pixels array.

Parameters:
pixels - int[]

stop

public void stop()
Stops the tracker.


getNFeatures

public int getNFeatures()
Returns the number of features being detected and tracked.

Returns:
int

getNDetectedFeatures

public int getNDetectedFeatures()
Returns the number of detected features when running the track method for the first time.

Returns:
int

getNNewFeatures

public int getNNewFeatures()
Returns the number of re-detected features. The re-detection occurs once every FeatureTrackerParameters.nTrackedFrames frames.

Returns:
int
See Also:
FeatureTrackerParameters

getNPresentFeatures

public int getNPresentFeatures()
Returns the number of present features being tracked. This number could be different than the number of originally detected features, because new feature points can appear (identified when re-detecting) or old points could disappear.

Returns:
int

getWidth

public int getWidth()
Returns the supported image width.

Returns:
int

getHeight

public int getHeight()
Returns the supported image height.

Returns:
int

getMaxTrackLength

public int getMaxTrackLength()
Returns the maximum track length.

Returns:
int

getTrackLength

public int getTrackLength(int i)
Returns the current track length of feature i.

Parameters:
i - int
Returns:
int

trackRestarted

public boolean trackRestarted(int i)
Returns true or false depending on weather feature i has been restarted or not.

Parameters:
i - int
Returns:
int

getPosX

public float getPosX(int i)
Returns the current x coordinate feature i.

Parameters:
i - int
Returns:
float

getPosY

public float getPosY(int i)
Returns the current y coordinate feature i.

Parameters:
i - int
Returns:
float

getTrackX

public float getTrackX(int i,
                       int t)
Returns the x coordinate of position of feature i at frame t.

Parameters:
i - int
t - int
Returns:
float

getTrackY

public float getTrackY(int i,
                       int t)
Returns the y coordinate of position of feature i at frame t.

Parameters:
i - int
t - int
Returns:
float

getTrack

public FeatureTrack getTrack(int i)
Returns the entire track of feature i.

Parameters:
i - int
Returns:
FeatureTrack
See Also:
FeatureTrack

drawTracks

public void drawTracks()
Draws the tracks for all the feature points using lines connecting successive positions. The track are drawn inside a rectangle located at (0, 0) and covering the entire sketch screen.


drawTracks

public void drawTracks(float x,
                       float y,
                       float w,
                       float h)
Draws the tracks for all the feature points using lines connecting successive positions. The track are drawn inside a rectangle located at (x, y) of size w x h.

Parameters:
x - float
y - float
w - float
h - float

drawFeatures

public void drawFeatures(float diam)
Draws the current positions of all the feature points using circles of diameter diam. The features are drawn inside a rectangle located at (0, 0) and covering the entire sketch screen.

Parameters:
diam - float

drawFeatures

public void drawFeatures(float x,
                         float y,
                         float w,
                         float h,
                         float diam)
Draws the current positions of all the feature points using circles of diameter diam. The features are drawn inside a rectangle located at (x, y) of size w x h.

Parameters:
diam - float
x - float
y - float
w - float
h - float


processing library proGPUKLT by Andres Colubri. (c) 2008