use of boofcv.abst.tracker.PointTrack in project BoofCV by lessthanoptimal.
the class ExamplePointFeatureTracker method updateGUI.
/**
* Draw tracked features in blue, or red if they were just spawned.
*/
private void updateGUI(SimpleImageSequence<T> sequence) {
BufferedImage orig = sequence.getGuiImage();
Graphics2D g2 = orig.createGraphics();
// draw tracks with semi-unique colors so you can track individual points with your eyes
for (PointTrack p : tracker.getActiveTracks(null)) {
int red = (int) (2.5 * (p.featureId % 100));
int green = (int) ((255.0 / 150.0) * (p.featureId % 150));
int blue = (int) (p.featureId % 255);
VisualizeFeatures.drawPoint(g2, (int) p.pixel.x, (int) p.pixel.y, new Color(red, green, blue));
}
// draw tracks which have just been spawned green
for (PointTrack p : tracker.getNewTracks(null)) {
VisualizeFeatures.drawPoint(g2, (int) p.pixel.x, (int) p.pixel.y, Color.green);
}
// tell the GUI to update
gui.setImage(orig);
gui.repaint();
}
use of boofcv.abst.tracker.PointTrack in project BoofCV by lessthanoptimal.
the class ExampleTrackingKlt method main.
public static void main(String[] args) {
// tune the tracker for the image size and visual appearance
ConfigPointDetector configDetector = new ConfigPointDetector();
configDetector.type = PointDetectorTypes.SHI_TOMASI;
configDetector.general.radius = 8;
configDetector.general.threshold = 1;
ConfigPKlt configKlt = new ConfigPKlt(3);
PointTracker<GrayF32> tracker = FactoryPointTracker.klt(configKlt, configDetector, GrayF32.class, null);
// Open a webcam at a resolution close to 640x480
Webcam webcam = UtilWebcamCapture.openDefault(640, 480);
// Create the panel used to display the image and feature tracks
ImagePanel gui = new ImagePanel();
gui.setPreferredSize(webcam.getViewSize());
ShowImages.showWindow(gui, "KLT Tracker", true);
int minimumTracks = 100;
while (true) {
BufferedImage image = webcam.getImage();
GrayF32 gray = ConvertBufferedImage.convertFrom(image, (GrayF32) null);
tracker.process(gray);
List<PointTrack> tracks = tracker.getActiveTracks(null);
// Spawn tracks if there are too few
if (tracks.size() < minimumTracks) {
tracker.spawnTracks();
tracks = tracker.getActiveTracks(null);
minimumTracks = tracks.size() / 2;
}
// Draw the tracks
Graphics2D g2 = image.createGraphics();
for (PointTrack t : tracks) {
VisualizeFeatures.drawPoint(g2, (int) t.pixel.x, (int) t.pixel.y, Color.RED);
}
gui.setImageUI(image);
}
}
use of boofcv.abst.tracker.PointTrack in project BoofCV by lessthanoptimal.
the class DetectDescribeAssociateTracker method performTracking.
/**
* Associate detections to tracks
*/
protected void performTracking() {
// Create a list for association from all tracks
final int numTracks = tracksAll.size();
srcDesc.resize(numTracks);
srcPixels.resize(numTracks);
srcSet.resize(numTracks);
for (int i = 0; i < numTracks; i++) {
PointTrack t = tracksAll.get(i);
srcDesc.data[i] = t.getDescription();
srcPixels.data[i] = t.pixel;
srcSet.data[i] = t.detectorSetId;
}
// Associate existing tracks with detections
UtilFeature.setSource(srcDesc, srcSet, srcPixels, associate);
UtilFeature.setDestination(dstDesc, dstSet, dstPixels, associate);
associate.associate();
FastAccess<AssociatedIndex> matches = associate.getMatches();
for (int i = 0; i < matches.size; i++) {
AssociatedIndex indexes = matches.data[i];
PointTrack track = tracksAll.get(indexes.src);
Point2D_F64 loc = dstPixels.data[indexes.dst];
track.pixel.setTo(loc.x, loc.y);
track.lastSeenFrameID = frameID;
tracksActive.add(track);
// update the description
if (updateDescription) {
((TD) track.getDescription()).setTo(dstDesc.get(indexes.dst));
}
}
}
use of boofcv.abst.tracker.PointTrack in project BoofCV by lessthanoptimal.
the class TestPruneCloseTracks method bruteForce.
List<PointTrack> bruteForce(List<PointTrack> tracks, int radius) {
List<PointTrack> dropped = new ArrayList<>();
for (int i = 0; i < tracks.size(); i++) {
PointTrack a = tracks.get(i);
boolean keep = true;
for (int j = 0; j < tracks.size(); j++) {
if (i == j)
continue;
PointTrack b = tracks.get(j);
double d = Math.max(Math.abs(a.pixel.x - b.pixel.x), Math.abs(a.pixel.y - b.pixel.y));
if (d < radius) {
if (a.featureId > b.featureId) {
keep = false;
break;
}
}
}
if (!keep) {
dropped.add(tracks.get(i));
}
}
return dropped;
}
use of boofcv.abst.tracker.PointTrack in project BoofCV by lessthanoptimal.
the class TestPruneCloseTracks method negative.
@Test
void negative() {
var alg = PruneCloseTracks.prunePointTrack(2);
alg.init(10, 20);
var tracks = new ArrayList<PointTrack>();
// space them out far enough so that non of them should be dropped
tracks.add(new PointTrack(0, 3, 4));
tracks.add(new PointTrack(0, 0, 0));
tracks.add(new PointTrack(0, 6, 6));
var dropped = new ArrayList<PointTrack>();
alg.process(tracks, dropped);
assertEquals(0, dropped.size());
}
Aggregations