Class AutoTracker
java.lang.Object
org.opensourcephysics.cabrillo.tracker.AutoTracker
- All Implemented Interfaces:
PropertyChangeListener
,EventListener
,Drawable
,Interactive
,Measurable
,Trackable
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
Nested ClassesModifier and TypeClassDescriptionprotected class
protected class
A corner point used for resizing.protected class
A class to hold frame data.protected class
An edge point used for translation.protected class
A class to hold keyframe data.protected class
A point that defines the target location relative to the mask center.protected class
A wizard to guide users of AutoTracker. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static boolean
protected static boolean
Fields inherited from interface org.opensourcephysics.media.core.Trackable
PROPERTY_ADJUSTING
-
Constructor Summary
ConstructorsConstructorDescriptionAutoTracker
(TrackerPanel panel) Constructs an AutoTracker for a specified TrackerPanel. -
Method Summary
Modifier and TypeMethodDescriptionprotected void
addKeyFrame
(TPoint p, double x, double y) Adds a key frame for a given track point and mask center position.protected BufferedImage
buildEvolvedTemplateImage
(AutoTracker.FrameData frameData) Builds an evolved template based on data in the specified FrameData and the current video image.protected boolean
canStep()
protected void
Clears search points in frames downstream of the current frame number.protected BufferedImage
createMagnifiedImage
(BufferedImage source) protected TemplateMatcher
Creates a TemplateMatcher based on the current image and mask.protected void
delete
(int n) Deletes the match data at a specified frame number.protected void
dispose()
Disposes of this autotracker.void
draw
(DrawingPanel panel, Graphics g) Draws this object.protected void
erase()
Erases the current mark.void
finalize()
findInteractive
(DrawingPanel panel, int xpix, int ypix) Finds the TPoint, if any, located at a specified pixel position.findMatchTarget
(boolean predict) Finds the match target, if any.protected TPoint
findMatchTarget
(Rectangle searchRect) Finds the target for the best match found within the specified searchRect.protected double[][]
getDerivatives
(TPoint[] positions, int order) Gets the available derivatives of the specified order.protected Map<Integer,
AutoTracker.FrameData> getIndexToFrameDataMap
(int index) Map theprotected Map<Integer,
Map<Integer, AutoTracker.FrameData>> Get or create for the currently selected track a Map of an Integer to a Map of Integer to FrameData, caching this in trackDataMapprotected Mark
getMark()
Gets the drawing mark.protected TPoint
getMatchCenter
(TPoint target) Returns the center point for a specified match target.protected 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.protected AutoTracker.FrameData
getOrCreateFrameData
(int frameNumber) Get or create a new FrameData object for a given frame number.protected AutoTracker.FrameData
getOrCreatePreviousFrameData
(int frameNumber) protected AutoTracker.FrameData
Get or create the FrameData object for the current trackerPanel frame.protected AutoTracker.KeyFrameData
Get or create KeyFrameData for the current tracker panel frame.getPredictedMatchTarget
(int frameNumber) Gets the predicted target point in a specified video frame, based on previously marked steps.Gets the search rectangle.protected int
getStatusCode
(int n) Determines the status code for a given frame.protected int
Gets the TemplateMatcher.protected TTrack
getTrack()
protected Map<Integer,
AutoTracker.FrameData> get the FrameData map for the current track, or track 0 if it is not selected.protected Video
getVideo()
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.boolean
isActive()
Determines if this autotracker is in active useprotected static boolean
Check to see if the mouse action was to trigger AutoTracker.protected boolean
isDrawingKeyFrameFor
(TTrack track, int index) boolean
boolean
Determines if this autotracker is interacting (via the mouse)boolean
isInteracting
(TTrack track) Determines if this autotracker is interacting with a specified trackboolean
Determines if information is available to set min/max values.boolean
isOnKeyFrame
(int n) Check to see if the autotracker is on the current frame by number.boolean
isOnKeyFrame
(TrackerPanel panel) Check to see if the autotracker is on the current frame of a panel.boolean
markCurrentFrame
(boolean predictLoc) Marks a new step in the current frame if a match is found.protected static boolean
protected boolean
moveRectIntoImage
(Rectangle2D searchRect) void
Responds to property change events.protected void
refreshKeyFrame
(AutoTracker.KeyFrameData keyFrame) Refreshes the key frame to reflect current center and corner positions.void
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
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, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.opensourcephysics.display.Interactive
isInteractive
-
Field Details
-
neverPause
protected static boolean neverPause -
autoSkip
protected static boolean autoSkip
-
-
Constructor Details
-
AutoTracker
Constructs an AutoTracker for a specified TrackerPanel.- Parameters:
panel
- the TrackerPanel
-
-
Method Details
-
getTrack
-
setTrack
Sets the track to mark when matches are found.- Parameters:
newTrack
- the track
-
addKeyFrame
Adds a key frame for a given track point and mask center position.- Parameters:
p
- the track pointx
- the mask center xy
- the mask center y
-
search
protected void search(boolean startWithThis, boolean keepGoing) Starts the search process.- Parameters:
startWithThis
- true to search the current framekeepGoing
- 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 nowupdate
- 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
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
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
Gets the wizard.- Returns:
- the wizard
-
draw
Draws this object. -
findInteractive
Finds the TPoint, if any, located at a specified pixel position. May return null.- Specified by:
findInteractive
in interfaceInteractive
- Parameters:
panel
- the drawing panelxpix
- the x pixel positionypix
- 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
Determines if this autotracker is interacting with a specified track- Parameters:
track
- the track- Returns:
- true if interacting
-
getTemplateMatcher
Gets the TemplateMatcher. May return null.- Returns:
- the template matcher
-
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
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 positioncorner
- the desired corner position (may be null)
-
getVideo
-
propertyChange
Responds to property change events.- Specified by:
propertyChange
in interfacePropertyChangeListener
- Parameters:
e
- the property change event
-
setEnabled
public void setEnabled(boolean enabled) - Specified by:
setEnabled
in interfaceInteractive
-
isEnabled
public boolean isEnabled()- Specified by:
isEnabled
in interfaceInteractive
-
setXY
public void setXY(double x, double y) - Specified by:
setXY
in interfaceInteractive
-
setX
public void setX(double x) - Specified by:
setX
in interfaceInteractive
-
setY
public void setY(double y) - Specified by:
setY
in interfaceInteractive
-
getX
public double getX()- Specified by:
getX
in interfaceInteractive
-
getY
public double getY()- Specified by:
getY
in interfaceInteractive
-
getXMin
public double getXMin()Description copied from interface:Measurable
Gets the minimum x needed to draw this object.- Specified by:
getXMin
in interfaceMeasurable
- Returns:
- minimum
-
getXMax
public double getXMax()Description copied from interface:Measurable
Gets the maximum x needed to draw this object.- Specified by:
getXMax
in interfaceMeasurable
- Returns:
- maximum
-
getYMin
public double getYMin()Description copied from interface:Measurable
Gets the minimum y needed to draw this object.- Specified by:
getYMin
in interfaceMeasurable
- Returns:
- minimum
-
getYMax
public double getYMax()Description copied from interface:Measurable
Gets the maximum y needed to draw this object.- Specified by:
getYMax
in interfaceMeasurable
- 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 interfaceMeasurable
- Returns:
- true if min/max values are valid
-
findMatchTarget
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
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
Creates a TemplateMatcher based on the current image and mask.- Returns:
- a newly created template matcher, or null if no video image exists
-
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
Map the- Parameters:
index
-- Returns:
-
getTrackTargetIndexToFrameDataMap
get the FrameData map for the current track, or track 0 if it is not selected.- Returns:
-
getPanelFrameData
Get or create the FrameData object for the current trackerPanel frame.- Returns:
- FrameData object
-
getPanelKeyFrameData
Get or create KeyFrameData for the current tracker panel frame.- Returns:
-
isOnKeyFrame
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
Check to see if the mouse action was to trigger AutoTracker.- Parameters:
e
-- Returns:
-
getOrCreateFrameData
Get or create a new FrameData object for a given frame number.- Parameters:
frameNumber
-- Returns:
-
getOrCreatePreviousFrameData
-
getStepPointIndex
-
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() -
getMark
Gets the drawing mark.- Returns:
- the mark
-
getMatchTarget
Returns the target for a specified match center point.- Parameters:
center
- the center point- Returns:
- the target
-
getMatchCenter
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
Refreshes the key frame to reflect current center and corner positions.- Parameters:
keyFrame
- the KeyFrame
-
createMagnifiedImage
-
getMatchShape
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
-
clearSearchPointsDownstream
protected void clearSearchPointsDownstream()Clears search points in frames downstream of the current frame number. -
moveRectIntoImage
-
getDerivatives
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 positionsorder
- may be 1 (v), 2 (a) or 3 (jerk)- Returns:
- the derivative data
-