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);
}
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);
});
}
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);
}
}
}
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;
}
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);
}
Aggregations