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 classprotected classA corner point used for resizing.protected classA class to hold frame data.protected classAn edge point used for translation.protected classA class to hold keyframe data.protected classA point that defines the target location relative to the mask center.protected classA wizard to guide users of AutoTracker. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static booleanprotected static booleanFields 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 voidaddKeyFrame(TPoint p, double x, double y) Adds a key frame for a given track point and mask center position.protected BufferedImagebuildEvolvedTemplateImage(AutoTracker.FrameData frameData) Builds an evolved template based on data in the specified FrameData and the current video image.protected booleancanStep()protected voidClears search points in frames downstream of the current frame number.protected BufferedImagecreateMagnifiedImage(BufferedImage source) protected TemplateMatcherCreates a TemplateMatcher based on the current image and mask.protected voiddelete(int n) Deletes the match data at a specified frame number.protected voiddispose()Disposes of this autotracker.voiddraw(DrawingPanel panel, Graphics g) Draws this object.protected voiderase()Erases the current mark.voidfinalize()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 TPointfindMatchTarget(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 MarkgetMark()Gets the drawing mark.protected TPointgetMatchCenter(TPoint target) Returns the center point for a specified match target.protected ShapegetMatchShape(TPoint[] pts) Gets the match shape for the specified center and frame corner positions.protected TPointgetMatchTarget(TPoint center) Returns the target for a specified match center point.protected AutoTracker.FrameDatagetOrCreateFrameData(int frameNumber) Get or create a new FrameData object for a given frame number.protected AutoTracker.FrameDatagetOrCreatePreviousFrameData(int frameNumber) protected AutoTracker.FrameDataGet or create the FrameData object for the current trackerPanel frame.protected AutoTracker.KeyFrameDataGet 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 intgetStatusCode(int n) Determines the status code for a given frame.protected intGets the TemplateMatcher.protected TTrackgetTrack()protected Map<Integer,AutoTracker.FrameData> get the FrameData map for the current track, or track 0 if it is not selected.protected VideogetVideo()Gets the wizard.doublegetX()doublegetXMax()Gets the maximum x needed to draw this object.doublegetXMin()Gets the minimum x needed to draw this object.doublegetY()doublegetYMax()Gets the maximum y needed to draw this object.doublegetYMin()Gets the minimum y needed to draw this object.booleanisActive()Determines if this autotracker is in active useprotected static booleanCheck to see if the mouse action was to trigger AutoTracker.protected booleanisDrawingKeyFrameFor(TTrack track, int index) booleanbooleanDetermines if this autotracker is interacting (via the mouse)booleanisInteracting(TTrack track) Determines if this autotracker is interacting with a specified trackbooleanDetermines if information is available to set min/max values.booleanisOnKeyFrame(int n) Check to see if the autotracker is on the current frame by number.booleanisOnKeyFrame(TrackerPanel panel) Check to see if the autotracker is on the current frame of a panel.booleanmarkCurrentFrame(boolean predictLoc) Marks a new step in the current frame if a match is found.protected static booleanprotected booleanmoveRectIntoImage(Rectangle2D searchRect) voidResponds to property change events.protected voidrefreshKeyFrame(AutoTracker.KeyFrameData keyFrame) Refreshes the key frame to reflect current center and corner positions.voidRefreshes the search rectangle based on the current center and corner points.protected voidrepaint()Repaints this object.protected voidreset()Clears all existing steps and match data for the current point index.protected voidsearch(boolean startWithThis, boolean keepGoing) Starts the search process.voidsetEnabled(boolean enabled) protected voidsetSearchPoints(TPoint center, TPoint corner) Sets the position of the center and corner of the search rectangle.protected voidSets the track to mark when matches are found.voidsetX(double x) voidsetXY(double x, double y) voidsetY(double y) protected voidstop(boolean now, boolean update) Stops the search process.Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods 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:
findInteractivein 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:
propertyChangein interfacePropertyChangeListener- Parameters:
e- the property change event
-
setEnabled
public void setEnabled(boolean enabled) - Specified by:
setEnabledin interfaceInteractive
-
isEnabled
public boolean isEnabled()- Specified by:
isEnabledin interfaceInteractive
-
setXY
public void setXY(double x, double y) - Specified by:
setXYin interfaceInteractive
-
setX
public void setX(double x) - Specified by:
setXin interfaceInteractive
-
setY
public void setY(double y) - Specified by:
setYin interfaceInteractive
-
getX
public double getX()- Specified by:
getXin interfaceInteractive
-
getY
public double getY()- Specified by:
getYin interfaceInteractive
-
getXMin
public double getXMin()Description copied from interface:MeasurableGets the minimum x needed to draw this object.- Specified by:
getXMinin interfaceMeasurable- Returns:
- minimum
-
getXMax
public double getXMax()Description copied from interface:MeasurableGets the maximum x needed to draw this object.- Specified by:
getXMaxin interfaceMeasurable- Returns:
- maximum
-
getYMin
public double getYMin()Description copied from interface:MeasurableGets the minimum y needed to draw this object.- Specified by:
getYMinin interfaceMeasurable- Returns:
- minimum
-
getYMax
public double getYMax()Description copied from interface:MeasurableGets the maximum y needed to draw this object.- Specified by:
getYMaxin interfaceMeasurable- Returns:
- minimum
-
isMeasured
public boolean isMeasured()Description copied from interface:MeasurableDetermines if information is available to set min/max values. Objects that store data should return false if data is null.- Specified by:
isMeasuredin 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
-