Class AutoTracker

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

public class AutoTracker extends Object implements Interactive, Trackable, 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
  • Field Details

    • neverPause

      protected static boolean neverPause
    • autoSkip

      protected static boolean autoSkip
  • Constructor Details

    • AutoTracker

      public AutoTracker(TrackerPanel panel)
      Constructs an AutoTracker for a specified TrackerPanel.
      Parameters:
      panel - the TrackerPanel
  • Method Details

    • getTrack

      protected TTrack getTrack()
    • setTrack

      protected void setTrack(TTrack newTrack)
      Sets the track to mark when matches are found.
      Parameters:
      newTrack - 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.
      Parameters:
      now - true to stop now
      update - true to update derivatives
    • 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
      Returns:
      true if a step was marked or possible match found and skipped
    • 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, 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
    • isActive

      public boolean isActive()
      Determines if this autotracker is in active use
      Returns:
      true if active
    • isInteracting

      public boolean isInteracting()
      Determines if this autotracker is interacting (via the mouse)
      Returns:
      true if interacting
    • isInteracting

      public boolean isInteracting(TTrack track)
      Determines if this autotracker is interacting with a specified track
      Parameters:
      track - the track
      Returns:
      true if interacting
    • getTemplateMatcher

      public TemplateMatcher getTemplateMatcher()
      Gets the TemplateMatcher. May return null.
      Returns:
      the template matcher
    • getSearchRect

      public 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)
    • getVideo

      protected Video getVideo()
    • propertyChange

      public void propertyChange(PropertyChangeEvent e)
      Responds to property change events.
      Specified by:
      propertyChange in interface 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(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
    • buildEvolvedTemplateImage

      protected BufferedImage buildEvolvedTemplateImage(AutoTracker.FrameData frameData)
      Builds an evolved template based on data in the specified FrameData and the current video image.
      Parameters:
      frameData - the FrameData frame
      Returns:
      the evolved template
    • 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
    • getMapOfIndexToMapofIndexToFrameData

      protected Map<Integer,Map<Integer,AutoTracker.FrameData>> getMapOfIndexToMapofIndexToFrameData()
      Get or create for the currently selected track a Map of an Integer to a Map of Integer to FrameData, caching this in trackDataMap
      Returns:
      map
    • getIndexToFrameDataMap

      protected Map<Integer,AutoTracker.FrameData> getIndexToFrameDataMap(int index)
      Map the
      Parameters:
      index -
      Returns:
    • getTrackTargetIndexToFrameDataMap

      protected Map<Integer,AutoTracker.FrameData> getTrackTargetIndexToFrameDataMap()
      get the FrameData map for the current track, or track 0 if it is not selected.
      Returns:
    • getPanelFrameData

      protected AutoTracker.FrameData getPanelFrameData()
      Get or create the FrameData object for the current trackerPanel frame.
      Returns:
      FrameData object
    • getPanelKeyFrameData

      protected AutoTracker.KeyFrameData getPanelKeyFrameData()
      Get or create KeyFrameData for the current tracker panel frame.
      Returns:
    • isOnKeyFrame

      public boolean isOnKeyFrame(TrackerPanel panel)
      Check to see if the autotracker is on the current frame of a panel.
      Parameters:
      panel -
      Returns:
    • isOnKeyFrame

      public boolean isOnKeyFrame(int n)
      Check to see if the autotracker is on the current frame by number.
      Parameters:
      panel -
      Returns:
    • isAutoTrackTrigger

      protected static boolean isAutoTrackTrigger(InputEvent e)
      Check to see if the mouse action was to trigger AutoTracker.
      Parameters:
      e -
      Returns:
    • getOrCreateFrameData

      protected AutoTracker.FrameData getOrCreateFrameData(int frameNumber)
      Get or create a new FrameData object for a given frame number.
      Parameters:
      frameNumber -
      Returns:
    • getOrCreatePreviousFrameData

      protected AutoTracker.FrameData getOrCreatePreviousFrameData(int frameNumber)
    • getStepPointIndex

      protected int getStepPointIndex(TPoint p)
    • erase

      protected void erase()
      Erases the current mark.
    • repaint

      protected void repaint()
      Repaints this object.
    • dispose

      protected void dispose()
      Disposes of this autotracker.
    • finalize

      public void finalize()
      Overrides:
      finalize in class Object
    • 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.
      Parameters:
      center - the center point
      Returns:
      the target
    • getMatchCenter

      protected TPoint getMatchCenter(TPoint target)
      Returns the center point for a specified match target.
      Parameters:
      target - the target
      Returns:
      the center
    • 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.KeyFrameData keyFrame)
      Refreshes the key frame to reflect current center and corner positions.
      Parameters:
      keyFrame - the KeyFrame
    • createMagnifiedImage

      protected BufferedImage createMagnifiedImage(BufferedImage source)
    • getMatchShape

      protected 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 10: calibration tool possible match
      Parameters:
      n - the frame number
      Returns:
      the status code
    • canStep

      protected boolean canStep()
    • mayLeaveGaps

      protected static boolean mayLeaveGaps()
    • isDrawingKeyFrameFor

      protected boolean isDrawingKeyFrameFor(TTrack track, int index)
    • clearSearchPointsDownstream

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

      protected boolean moveRectIntoImage(Rectangle2D searchRect)
    • getDerivatives

      protected double[][] getDerivatives(TPoint[] positions, int order)
      Gets the available derivatives of the specified order. These are NOT time derivatives, but simply differences in pixel units: order 1 is deltaPosition, order 2 is change in deltaPosition, order 3 is change in order 2. Note the TPoint positions are in image units, not world units.
      Parameters:
      positions - an array of positions
      order - may be 1 (v), 2 (a) or 3 (jerk)
      Returns:
      the derivative data