org.opensourcephysics.cabrillo.tracker
Class AutoTracker

java.lang.Object
  extended by org.opensourcephysics.cabrillo.tracker.AutoTracker
All Implemented Interfaces:
java.beans.PropertyChangeListener, java.util.EventListener, Drawable, Interactive, Measurable, Trackable

public class AutoTracker
extends java.lang.Object
implements Interactive, Trackable, java.beans.PropertyChangeListener

A class to automatically track a feature of interest in a video. This uses a TemplateMatcher to find a match to the feature in each frame and, if found, marks the active track at the target location.

Author:
Douglas Brown

Nested Class Summary
protected  class AutoTracker.Corner
          A corner point used for resizing.
protected  class AutoTracker.FrameData
          A class to hold frame data.
protected  class AutoTracker.Handle
          An edge point used for translation.
protected  class AutoTracker.KeyFrame
          A class to hold keyframe data.
protected  class AutoTracker.Target
          A point that defines the target location relative to the mask center.
protected  class AutoTracker.Wizard
          A wizard to guide users of AutoTracker.
 
Constructor Summary
AutoTracker(TrackerPanel panel)
          Constructs an AutoTracker for a specified TrackerPanel.
 
Method Summary
protected  void addKeyFrame(TPoint p, double x, double y)
          Adds a key frame for a given track point and mask center position.
protected  void buildEvolvedTemplate(AutoTracker.FrameData frame)
          Builds an evolved template based on data in the specified FrameData and the current video image.
protected  boolean canStep()
           
protected  void cleanup()
          Cleans up resources.
protected  void clearSearchPointsDownstream()
          Clears search points in frames downstream of the current frame number.
protected  java.awt.image.BufferedImage createMagnifiedImage(java.awt.image.BufferedImage source)
           
protected  TemplateMatcher createTemplateMatcher()
          Creates a TemplateMatcher based on the current image and mask.
protected  void delete(int n)
          Deletes the match data at a specified frame number.
 void draw(DrawingPanel panel, java.awt.Graphics g)
          Draws this object.
protected  void erase()
          Erases the current mark.
 Interactive findInteractive(DrawingPanel panel, int xpix, int ypix)
          Finds the TPoint, if any, located at a specified pixel position.
 TPoint findMatchTarget(boolean predict)
          Finds the match target, if any.
protected  TPoint findMatchTarget(java.awt.Rectangle searchRect)
          Finds the target for the best match found within the specified searchRect.
protected  AutoTracker.FrameData getFrame(int frameNumber)
           
protected  java.util.Map<java.lang.Integer,AutoTracker.FrameData> getFrameData()
           
protected  java.util.Map<java.lang.Integer,AutoTracker.FrameData> getFrameData(int index)
           
protected  int getIndex(TPoint p)
           
protected  java.util.Map<java.lang.Integer,java.util.Map<java.lang.Integer,AutoTracker.FrameData>> getIndexFrameData()
           
protected  Mark getMark()
          Gets the drawing mark.
protected  TPoint getMatchCenter(TPoint target)
          Returns the center point for a specified match target.
protected  java.awt.Shape getMatchShape(TPoint[] pts)
          Gets the match shape for the specified center and frame corner positions.
protected  TPoint getMatchTarget(TPoint center)
          Returns the target for a specified match center point.
 TPoint getPredictedMatchTarget(int frameNumber)
          Gets the predicted target point in a specified video frame, based on previously marked steps.
 java.awt.Rectangle getSearchRect()
          Gets the search rectangle.
protected  int getStatusCode(int n)
          Determines the status code for a given frame.
 TemplateMatcher getTemplateMatcher()
          Gets the TemplateMatcher.
protected  TTrack getTrack()
           
 AutoTracker.Wizard getWizard()
          Gets the wizard.
 double getX()
           
 double getXMax()
          Gets the maximum x needed to draw this object.
 double getXMin()
          Gets the minimum x needed to draw this object.
 double getY()
           
 double getYMax()
          Gets the maximum y needed to draw this object.
 double getYMin()
          Gets the minimum y needed to draw this object.
protected  boolean isDrawingKeyFrameFor(TTrack track)
           
 boolean isEnabled()
           
 boolean isMeasured()
          Determines if information is available to set min/max values.
 boolean markCurrentFrame(boolean predictLoc)
          Marks a new step in the current frame if a match is found.
 void propertyChange(java.beans.PropertyChangeEvent e)
          Responds to property change events.
protected  void refreshKeyFrame(AutoTracker.KeyFrame keyFrame)
          Refreshes the key frame to reflect current center and corner positions.
 void refreshSearchRect()
          Refreshes the search rectangle based on the current center and corner points.
protected  void repaint()
          Repaints this object.
protected  void reset()
          Clears all existing steps and match data for the current point index.
protected  void search(boolean startWithThis, boolean keepGoing)
          Starts the search process.
 void setEnabled(boolean enabled)
           
protected  void setSearchPoints(TPoint center, TPoint corner)
          Sets the position of the center and corner of the search rectangle.
protected  void setTrack(TTrack aTrack)
          Sets the track to mark when matches are found.
 void setX(double x)
           
 void setXY(double x, double y)
           
 void setY(double y)
           
protected  void stop(boolean now, boolean update)
          Stops the search process.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AutoTracker

public AutoTracker(TrackerPanel panel)
Constructs an AutoTracker for a specified TrackerPanel.

Parameters:
panel - the TrackerPanel
Method Detail

setTrack

protected void setTrack(TTrack aTrack)
Sets the track to mark when matches are found.

Parameters:
aTrack - the track

addKeyFrame

protected void addKeyFrame(TPoint p,
                           double x,
                           double y)
Adds a key frame for a given track point and mask center position.

Parameters:
p - the track point
x - the mask center x
y - the mask center y

search

protected void search(boolean startWithThis,
                      boolean keepGoing)
Starts the search process.

Parameters:
startWithThis - true to search the current frame
keepGoing - true to continue stepping after the first search

stop

protected void stop(boolean now,
                    boolean update)
Stops the search process.


markCurrentFrame

public boolean markCurrentFrame(boolean predictLoc)
Marks a new step in the current frame if a match is found.

Parameters:
predictLoc - true to use look-ahead prediction for setting the search loc
Returns:
true if a new step was marked

getPredictedMatchTarget

public TPoint getPredictedMatchTarget(int frameNumber)
Gets the predicted target point in a specified video frame, based on previously marked steps.

Parameters:
frameNumber - the frame number
Returns:
the predicted target

findMatchTarget

public TPoint findMatchTarget(boolean predict)
Finds the match target, if any. Also saves search center and corner.

Parameters:
predict - true to predict the location before searching
Returns:
the match target, or null if no match is found

getWizard

public AutoTracker.Wizard getWizard()
Gets the wizard.

Returns:
the wizard

draw

public void draw(DrawingPanel panel,
                 java.awt.Graphics g)
Draws this object.

Specified by:
draw in interface Drawable
Parameters:
panel - the drawing panel requesting the drawing
g - the graphics context on which to draw

findInteractive

public Interactive findInteractive(DrawingPanel panel,
                                   int xpix,
                                   int ypix)
Finds the TPoint, if any, located at a specified pixel position. May return null.

Specified by:
findInteractive in interface Interactive
Parameters:
panel - the drawing panel
xpix - the x pixel position
ypix - the y pixel position
Returns:
the TPoint, or null if none

getTemplateMatcher

public TemplateMatcher getTemplateMatcher()
Gets the TemplateMatcher. May return null.

Returns:
the template matcher

getSearchRect

public java.awt.Rectangle getSearchRect()
Gets the search rectangle.

Returns:
the search rectangle

refreshSearchRect

public void refreshSearchRect()
Refreshes the search rectangle based on the current center and corner points.


setSearchPoints

protected void setSearchPoints(TPoint center,
                               TPoint corner)
Sets the position of the center and corner of the search rectangle. If the corner is null, the search rectangle is moved but not resized, and the entire rectangle is kept within the image.

Parameters:
center - the desired center position
corner - the desired corner position (may be null)

propertyChange

public void propertyChange(java.beans.PropertyChangeEvent e)
Responds to property change events. AutoTracker listens for the following events: "step" from PointMass, "selectedpoint", "video" and "stepnumber" from TrackerPanel.

Specified by:
propertyChange in interface java.beans.PropertyChangeListener
Parameters:
e - the property change event

setEnabled

public void setEnabled(boolean enabled)
Specified by:
setEnabled in interface Interactive

isEnabled

public boolean isEnabled()
Specified by:
isEnabled in interface Interactive

setXY

public void setXY(double x,
                  double y)
Specified by:
setXY in interface Interactive

setX

public void setX(double x)
Specified by:
setX in interface Interactive

setY

public void setY(double y)
Specified by:
setY in interface Interactive

getX

public double getX()
Specified by:
getX in interface Interactive

getY

public double getY()
Specified by:
getY in interface Interactive

getXMin

public double getXMin()
Description copied from interface: Measurable
Gets the minimum x needed to draw this object.

Specified by:
getXMin in interface Measurable
Returns:
minimum

getXMax

public double getXMax()
Description copied from interface: Measurable
Gets the maximum x needed to draw this object.

Specified by:
getXMax in interface Measurable
Returns:
maximum

getYMin

public double getYMin()
Description copied from interface: Measurable
Gets the minimum y needed to draw this object.

Specified by:
getYMin in interface Measurable
Returns:
minimum

getYMax

public double getYMax()
Description copied from interface: Measurable
Gets the maximum y needed to draw this object.

Specified by:
getYMax in interface Measurable
Returns:
minimum

isMeasured

public boolean isMeasured()
Description copied from interface: Measurable
Determines if information is available to set min/max values. Objects that store data should return false if data is null.

Specified by:
isMeasured in interface Measurable
Returns:
true if min/max values are valid

findMatchTarget

protected TPoint findMatchTarget(java.awt.Rectangle searchRect)
Finds the target for the best match found within the specified searchRect. Also saves match width, height, center and corner.

Parameters:
searchRect - the search rectangle
Returns:
the target, or null if no match found

buildEvolvedTemplate

protected void buildEvolvedTemplate(AutoTracker.FrameData frame)
Builds an evolved template based on data in the specified FrameData and the current video image.

Parameters:
frame - the FrameData frame

createTemplateMatcher

protected TemplateMatcher createTemplateMatcher()
Creates a TemplateMatcher based on the current image and mask.

Returns:
a newly created template matcher, or null if no video image exists

getIndexFrameData

protected java.util.Map<java.lang.Integer,java.util.Map<java.lang.Integer,AutoTracker.FrameData>> getIndexFrameData()

getFrameData

protected java.util.Map<java.lang.Integer,AutoTracker.FrameData> getFrameData(int index)

getFrameData

protected java.util.Map<java.lang.Integer,AutoTracker.FrameData> getFrameData()

getFrame

protected AutoTracker.FrameData getFrame(int frameNumber)

getIndex

protected int getIndex(TPoint p)

getTrack

protected TTrack getTrack()

erase

protected void erase()
Erases the current mark.


repaint

protected void repaint()
Repaints this object.


cleanup

protected void cleanup()
Cleans up resources.


getMark

protected Mark getMark()
Gets the drawing mark.

Returns:
the mark

getMatchTarget

protected TPoint getMatchTarget(TPoint center)
Returns the target for a specified match center point.


getMatchCenter

protected TPoint getMatchCenter(TPoint target)
Returns the center point for a specified match target.


delete

protected void delete(int n)
Deletes the match data at a specified frame number.

Parameters:
n - the frame number

reset

protected void reset()
Clears all existing steps and match data for the current point index.


refreshKeyFrame

protected void refreshKeyFrame(AutoTracker.KeyFrame keyFrame)
Refreshes the key frame to reflect current center and corner positions.

Parameters:
keyFrame - the KeyFrame

createMagnifiedImage

protected java.awt.image.BufferedImage createMagnifiedImage(java.awt.image.BufferedImage source)

getMatchShape

protected java.awt.Shape getMatchShape(TPoint[] pts)
Gets the match shape for the specified center and frame corner positions.

Parameters:
pts - TPoint[] {center, frame corner}
Returns:
a shape suitable for drawing

getStatusCode

protected int getStatusCode(int n)
Determines the status code for a given frame. The status codes are: 0: a key frame 1: automarked with a good match 2: possible match, not marked 3: searched but no match found 4: unable to search--search area outside image or x-axis 5: manually marked by the user 6: match accepted by the user 7: never searched 8: possible match but previously marked 9: no match found but previously marked

Parameters:
n - the frame number
Returns:
the status code

canStep

protected boolean canStep()

isDrawingKeyFrameFor

protected boolean isDrawingKeyFrameFor(TTrack track)

clearSearchPointsDownstream

protected void clearSearchPointsDownstream()
Clears search points in frames downstream of the current frame number.