Difference between revisions of "Example Tracker Object"
From BoofCV
Jump to navigationJump to search (Created page with "<center> <gallery widths=400px heights=300px> file:Example_tracking_object.jpg | Last frame from a sequence where the book was tracked using the ciruclant tracker. </gallery> ...") |
m |
||
(8 intermediate revisions by the same user not shown) | |||
Line 8: | Line 8: | ||
Example Code: | Example Code: | ||
* [https://github.com/lessthanoptimal/BoofCV/blob/v0. | * [https://github.com/lessthanoptimal/BoofCV/blob/v0.38/examples/src/main/java/boofcv/examples/tracking/ExampleTrackerObjectQuad.java ExampleTrackerObjectQuad.java] | ||
Concepts: | Concepts: | ||
Line 15: | Line 15: | ||
* Re-detection | * Re-detection | ||
Media: | |||
* [ | * [https://youtu.be/ItssLfIGZYM Video of Demonstration App] | ||
= Example Code = | = Example Code = | ||
Line 23: | Line 23: | ||
/** | /** | ||
* Demonstration on how to use the high level {@link TrackerObjectQuad} interface for tracking objects in a | * Demonstration on how to use the high level {@link TrackerObjectQuad} interface for tracking objects in a | ||
* video sequence. | * video sequence. This interface allows the target to be specified using an arbitrary quadrilateral. Specific | ||
* implementations might not support that shape, so they instead will track an approximation of it. | * implementations might not support that shape, so they instead will track an approximation of it. The | ||
* interface also allows information on target visibility to be returned. | * interface also allows information on target visibility to be returned. As is usually the case, tracker | ||
* specific information is lost in the high level interface and you should consider using the trackers | * specific information is lost in the high level interface and you should consider using the trackers | ||
* directly if more control is needed. | * directly if more control is needed. | ||
Line 34: | Line 34: | ||
*/ | */ | ||
public class ExampleTrackerObjectQuad { | public class ExampleTrackerObjectQuad { | ||
public static void main( String[] args ) { | |||
MediaManager media = DefaultMediaManager.INSTANCE; | |||
String fileName = UtilIO.pathExample("tracking/wildcat_robot.mjpeg"); | |||
// Create the tracker. Comment/Uncomment to change the tracker. | |||
TrackerObjectQuad tracker = | |||
FactoryTrackerObjectQuad.circulant(null, GrayU8.class); | |||
// FactoryTrackerObjectQuad.sparseFlow(null,GrayU8.class,null); | |||
// FactoryTrackerObjectQuad.tld(null,GrayU8.class); | |||
// FactoryTrackerObjectQuad.meanShiftComaniciu2003(new ConfigComaniciu2003(), ImageType.pl(3, GrayU8.class)); | |||
// FactoryTrackerObjectQuad.meanShiftComaniciu2003(new ConfigComaniciu2003(true),ImageType.pl(3,GrayU8.class)); | |||
// Mean-shift likelihood will fail in this video, but is excellent at tracking objects with | |||
// a single unique color. See ExampleTrackerMeanShiftLikelihood | |||
// FactoryTrackerObjectQuad.meanShiftLikelihood(30,5,255, MeanShiftLikelihoodType.HISTOGRAM,ImageType.pl(3,GrayU8.class)); | |||
SimpleImageSequence video = media.openVideo(fileName, tracker.getImageType()); | |||
// specify the target's initial location and initialize with the first frame | // specify the target's initial location and initialize with the first frame | ||
Quadrilateral_F64 location = new Quadrilateral_F64( | Quadrilateral_F64 location = new Quadrilateral_F64(211.0, 162.0, 326.0, 153.0, 335.0, 258.0, 215.0, 249.0); | ||
ImageBase frame = video.next(); | |||
tracker.initialize(frame,location); | tracker.initialize(frame, location); | ||
// For displaying the results | // For displaying the results | ||
var gui = new TrackerObjectQuadPanel(null); | |||
gui.setPreferredSize(new Dimension(frame.getWidth(),frame.getHeight())); | gui.setPreferredSize(new Dimension(frame.getWidth(), frame.getHeight())); | ||
gui. | gui.setImageUI((BufferedImage)video.getGuiImage()); | ||
gui.setTarget(location,true); | gui.setTarget(location, true); | ||
ShowImages.showWindow(gui,"Tracking Results"); | ShowImages.showWindow(gui, "Tracking Results", true); | ||
// Track the object across each video frame and display the results | // Track the object across each video frame and display the results | ||
while( video.hasNext() ) { | long previous = 0; | ||
while (video.hasNext()) { | |||
frame = video.next(); | frame = video.next(); | ||
boolean visible = tracker.process(frame,location); | boolean visible = tracker.process(frame, location); | ||
gui. | gui.setImageUI((BufferedImage)video.getGuiImage()); | ||
gui.setTarget(location,visible); | gui.setTarget(location, visible); | ||
gui.repaint(); | gui.repaint(); | ||
BoofMiscOps.pause( | // shoot for a specific frame rate | ||
long time = System.currentTimeMillis(); | |||
BoofMiscOps.pause(Math.max(0, 80 - (time - previous))); | |||
previous = time; | |||
} | } | ||
} | } | ||
} | } | ||
</syntaxhighlight> | </syntaxhighlight> |
Latest revision as of 03:23, 22 July 2021
In this example several different trackers can be used to track the object in the video. All of the trackers in this example use texture information (see mean-shift example for color based trackers) to localize and track the object. No one single tracker can track all the video sequences provided with BoofCV or in general. You should try out all the different video sequences and see which trackers work best when.
Example Code:
Concepts:
- Object tracking
- Local trackers
- Re-detection
Media:
Example Code
/**
* Demonstration on how to use the high level {@link TrackerObjectQuad} interface for tracking objects in a
* video sequence. This interface allows the target to be specified using an arbitrary quadrilateral. Specific
* implementations might not support that shape, so they instead will track an approximation of it. The
* interface also allows information on target visibility to be returned. As is usually the case, tracker
* specific information is lost in the high level interface and you should consider using the trackers
* directly if more control is needed.
*
* This is an active area of research and all of the trackers eventually diverge given a long enough sequence.
*
* @author Peter Abeles
*/
public class ExampleTrackerObjectQuad {
public static void main( String[] args ) {
MediaManager media = DefaultMediaManager.INSTANCE;
String fileName = UtilIO.pathExample("tracking/wildcat_robot.mjpeg");
// Create the tracker. Comment/Uncomment to change the tracker.
TrackerObjectQuad tracker =
FactoryTrackerObjectQuad.circulant(null, GrayU8.class);
// FactoryTrackerObjectQuad.sparseFlow(null,GrayU8.class,null);
// FactoryTrackerObjectQuad.tld(null,GrayU8.class);
// FactoryTrackerObjectQuad.meanShiftComaniciu2003(new ConfigComaniciu2003(), ImageType.pl(3, GrayU8.class));
// FactoryTrackerObjectQuad.meanShiftComaniciu2003(new ConfigComaniciu2003(true),ImageType.pl(3,GrayU8.class));
// Mean-shift likelihood will fail in this video, but is excellent at tracking objects with
// a single unique color. See ExampleTrackerMeanShiftLikelihood
// FactoryTrackerObjectQuad.meanShiftLikelihood(30,5,255, MeanShiftLikelihoodType.HISTOGRAM,ImageType.pl(3,GrayU8.class));
SimpleImageSequence video = media.openVideo(fileName, tracker.getImageType());
// specify the target's initial location and initialize with the first frame
Quadrilateral_F64 location = new Quadrilateral_F64(211.0, 162.0, 326.0, 153.0, 335.0, 258.0, 215.0, 249.0);
ImageBase frame = video.next();
tracker.initialize(frame, location);
// For displaying the results
var gui = new TrackerObjectQuadPanel(null);
gui.setPreferredSize(new Dimension(frame.getWidth(), frame.getHeight()));
gui.setImageUI((BufferedImage)video.getGuiImage());
gui.setTarget(location, true);
ShowImages.showWindow(gui, "Tracking Results", true);
// Track the object across each video frame and display the results
long previous = 0;
while (video.hasNext()) {
frame = video.next();
boolean visible = tracker.process(frame, location);
gui.setImageUI((BufferedImage)video.getGuiImage());
gui.setTarget(location, visible);
gui.repaint();
// shoot for a specific frame rate
long time = System.currentTimeMillis();
BoofMiscOps.pause(Math.max(0, 80 - (time - previous)));
previous = time;
}
}
}