Search in sources :

Example 11 with PointTrack

use of boofcv.abst.tracker.PointTrack in project BoofCV by lessthanoptimal.

the class PointTrackerPerfectCloud method process.

@Override
public void process(T image) {
    Objects.requireNonNull(norm_to_pixel, "You must set norm_to_pixel first");
    BoofMiscOps.checkTrue(width != 0 && height != 0, "You must specify width and height");
    frameID++;
    observedID.clear();
    dropped.clear();
    spawned.clear();
    spawnable.reset();
    for (int cloudIdx = 0; cloudIdx < cloud.size(); cloudIdx++) {
        Point3D_F64 X = cloud.get(cloudIdx);
        world_to_view.transform(X, viewX);
        if (viewX.z <= 0.0)
            continue;
        norm_to_pixel.compute(viewX.x / viewX.z, viewX.y / viewX.z, pixel);
        if (!BoofMiscOps.isInside(width, height, pixel.x, pixel.y))
            continue;
        if (cloudIdx_to_id.containsKey(cloudIdx)) {
            long id = cloudIdx_to_id.get(cloudIdx);
            PointTrack track = id_to_track.get(id);
            // if it has been observed twice, that's a bug
            BoofMiscOps.checkTrue(observedID.add(id));
            // Save the observed pixel coordinate
            track.pixel.setTo(pixel);
            track.lastSeenFrameID = frameID;
            continue;
        }
        // Mark this point as a potential point that can be spawned into a new track
        spawnable.grow().setTo(cloudIdx, pixel);
    }
    // Drop tracks which have not been observed.
    dropUnobserved();
// System.out.println("active.size="+activeTracks.size+" dropped.size="+dropped.size()+" totalTracks="+totalTracks);
}
Also used : Point3D_F64(georegression.struct.point.Point3D_F64) PointTrack(boofcv.abst.tracker.PointTrack)

Example 12 with PointTrack

use of boofcv.abst.tracker.PointTrack in project BoofCV by lessthanoptimal.

the class PointTrackerPerfectCloud method dropUnobserved.

/**
 * Drops tracks which were not visible in the FOV
 */
void dropUnobserved() {
    // Make a list first to avoid modifying a data structure while traversing through it
    DogArray_I64 dropList = new DogArray_I64();
    for (long id : id_to_track.keys()) {
        // lint:forbidden ignore_line
        if (!observedID.contains(id)) {
            dropList.add(id);
        }
    }
    // Now actually drop the tracks
    dropList.forEach(id -> {
        PointTrack track = Objects.requireNonNull(id_to_track.remove(id));
        // Don't worry about track being recycled since it won't be recycled until the next call to process
        // and at that point drop is reset
        dropped.add(track);
        BoofMiscOps.checkTrue(activeTracks.remove(track));
        int cloudIdx = id_to_cloudIdx.remove(id);
        cloudIdx_to_id.remove(cloudIdx);
    });
}
Also used : PointTrack(boofcv.abst.tracker.PointTrack) DogArray_I64(org.ddogleg.struct.DogArray_I64)

Example 13 with PointTrack

use of boofcv.abst.tracker.PointTrack in project BoofCV by lessthanoptimal.

the class TestPruneCloseTracks method positive.

@Test
void positive() {
    var alg = PruneCloseTracks.prunePointTrack(2);
    alg.init(10, 20);
    var tracks = new ArrayList<PointTrack>();
    tracks.add(new PointTrack(3, 3, 4));
    tracks.add(new PointTrack(9, 0, 0));
    // sometimes it won't be in the same cell
    for (int y = -1; y <= 1; y++) {
        for (int x = -1; x <= 1; x++) {
            tracks.add(new PointTrack(3 + x, 3 + y, 4));
            var dropped = new ArrayList<PointTrack>();
            alg.process(tracks, dropped);
            assertEquals(3, tracks.size());
            assertEquals(1, dropped.size(), x + " " + y);
            tracks.remove(2);
        }
    }
}
Also used : PointTrack(boofcv.abst.tracker.PointTrack) ArrayList(java.util.ArrayList) Test(org.junit.jupiter.api.Test)

Example 14 with PointTrack

use of boofcv.abst.tracker.PointTrack in project BoofCV by lessthanoptimal.

the class TestPruneCloseTracks method createRandom.

List<PointTrack> createRandom(int total, int width, int height) {
    var tracks = new ArrayList<PointTrack>();
    for (int i = 0; i < total; i++) {
        PointTrack t = new PointTrack();
        // make setting it to the width impossible
        t.pixel.x = rand.nextDouble() * 0.9999 * width;
        t.pixel.y = rand.nextDouble() * 0.9999 * height;
        t.featureId = i;
        t.spawnFrameID = rand.nextInt(100);
        tracks.add(t);
    }
    return tracks;
}
Also used : PointTrack(boofcv.abst.tracker.PointTrack) ArrayList(java.util.ArrayList)

Example 15 with PointTrack

use of boofcv.abst.tracker.PointTrack in project BoofCV by lessthanoptimal.

the class TestDetectDescribeAssociateTracker method addNewTrack.

@Test
void addNewTrack() {
    var alg = createAlgorithm();
    alg.frameID = 7;
    alg.featureID = 8;
    alg.addNewTrack(9, 1, 2, new TupleDesc_F64(3));
    assertEquals(1, alg.tracksAll.size);
    assertEquals(1, alg.tracksActive.size());
    assertEquals(0, alg.tracksInactive.size());
    PointTrack t = alg.tracksAll.get(0);
    assertEquals(7, t.spawnFrameID);
    assertEquals(7, t.lastSeenFrameID);
    assertEquals(8, t.featureId);
    assertEquals(9, t.detectorSetId);
    assertEquals(1, t.pixel.x, UtilEjml.TEST_F64);
    assertEquals(2, t.pixel.y, UtilEjml.TEST_F64);
}
Also used : TupleDesc_F64(boofcv.struct.feature.TupleDesc_F64) PointTrack(boofcv.abst.tracker.PointTrack) Test(org.junit.jupiter.api.Test)

Aggregations

PointTrack (boofcv.abst.tracker.PointTrack)44 Test (org.junit.jupiter.api.Test)11 Frame (boofcv.alg.similar.SimilarImagesFromTracks.Frame)5 ArrayList (java.util.ArrayList)5 BTrack (boofcv.alg.sfm.d3.structure.VisOdomBundleAdjustment.BTrack)3 AssociatedIndex (boofcv.struct.feature.AssociatedIndex)3 Point2D_F64 (georegression.struct.point.Point2D_F64)3 Point3D_F64 (georegression.struct.point.Point3D_F64)3 DetectDescribePoint (boofcv.abst.feature.detdesc.DetectDescribePoint)2 Match (boofcv.alg.similar.SimilarImagesFromTracks.Match)2 CameraPinhole (boofcv.struct.calib.CameraPinhole)2 GrayU8 (boofcv.struct.image.GrayU8)2 BufferedImage (java.awt.image.BufferedImage)2 DogArray (org.ddogleg.struct.DogArray)2 ScoreAssociateEuclideanSq (boofcv.abst.feature.associate.ScoreAssociateEuclideanSq)1 ConfigPointDetector (boofcv.abst.feature.detect.interest.ConfigPointDetector)1 AssociatedPairTrack (boofcv.alg.sfm.d2.AssociatedPairTrack)1 VisOdomMonoPlaneInfinity (boofcv.alg.sfm.d3.VisOdomMonoPlaneInfinity)1 ConfigPKlt (boofcv.alg.tracker.klt.ConfigPKlt)1 ImagePanel (boofcv.gui.image.ImagePanel)1