Search in sources :

Example 6 with BTrack

use of boofcv.alg.sfm.d3.structure.VisOdomBundleAdjustment.BTrack in project BoofCV by lessthanoptimal.

the class SelectTracksInFrameForBundleAdjustment method selectTracks.

/**
 * Selects tracks to include in bundle adjustment
 *
 * @param sba The scene graph
 * @param selected (Output) list of selected tracks
 */
public void selectTracks(VisOdomBundleAdjustment<?> sba, List<BTrack> selected) {
    // Initialize data structures
    selected.clear();
    // Mark all tracks as not selected
    for (int trackIdx = 0; trackIdx < sba.tracks.size; trackIdx++) {
        sba.tracks.get(trackIdx).selected = false;
    }
    // skip degenerate situation
    DogArray<BFrame> frames = sba.frames;
    if (frames.size < 1)
        return;
    if (maxFeaturesPerFrame <= 0) {
        // handle the case where it's unlimited differently
        for (int trackIdx = 0; trackIdx < sba.tracks.size; trackIdx++) {
            BTrack track = sba.tracks.get(trackIdx);
            if (track.observations.size >= minTrackObservations) {
                track.selected = true;
                selected.add(track);
            }
        }
    } else {
        // Start with older frames since we want to be biased to select tracks that have been seen by more frames
        for (int frameIdx = 0; frameIdx < frames.size; frameIdx++) {
            selectTracksInFrame(frames.get(frameIdx), selected);
        }
    }
}
Also used : BFrame(boofcv.alg.sfm.d3.structure.VisOdomBundleAdjustment.BFrame) BTrack(boofcv.alg.sfm.d3.structure.VisOdomBundleAdjustment.BTrack)

Example 7 with BTrack

use of boofcv.alg.sfm.d3.structure.VisOdomBundleAdjustment.BTrack in project BoofCV by lessthanoptimal.

the class TestTickTockKeyFrameManager method alwaysAddBeforeMax.

@Test
void alwaysAddBeforeMax() {
    var tracker = new DummyTracker();
    VisOdomBundleAdjustment<BTrack> scene = createScene();
    var alg = new TickTockKeyFrameManager();
    // don't want it to add a new keyframe right afterwards
    alg.keyframePeriod = 10000;
    // not used but call it just in case that changes in the future
    alg.initialize(scene.cameras);
    // add the initial set of frames
    for (int i = 0; i < 5; i++) {
        DogArray_I32 discard = alg.selectFramesToDiscard(tracker, maxKeyFrames, 1, scene);
        assertEquals(0, discard.size);
        scene.addFrame(i);
        tracker.process(null);
    }
    // add one more frame. It should now want to discard the current frame
    scene.addFrame(6);
    tracker.process(null);
    DogArray_I32 discard = alg.selectFramesToDiscard(tracker, maxKeyFrames, 1, scene);
    assertEquals(1, discard.size);
    assertEquals(5, discard.get(0));
}
Also used : DogArray_I32(org.ddogleg.struct.DogArray_I32) BTrack(boofcv.alg.sfm.d3.structure.VisOdomBundleAdjustment.BTrack) Test(org.junit.jupiter.api.Test)

Example 8 with BTrack

use of boofcv.alg.sfm.d3.structure.VisOdomBundleAdjustment.BTrack in project BoofCV by lessthanoptimal.

the class ChecksVisOdomKeyFrameManager method createScene.

public VisOdomBundleAdjustment<BTrack> createScene() {
    VisOdomBundleAdjustment<BTrack> scene = new VisOdomBundleAdjustment<>(BTrack::new);
    scene.addCamera(new CameraPinholeBrown(0, 0, 0, 0, 0, width, height));
    return scene;
}
Also used : CameraPinholeBrown(boofcv.struct.calib.CameraPinholeBrown) BTrack(boofcv.alg.sfm.d3.structure.VisOdomBundleAdjustment.BTrack)

Example 9 with BTrack

use of boofcv.alg.sfm.d3.structure.VisOdomBundleAdjustment.BTrack in project BoofCV by lessthanoptimal.

the class TestSelectTracksInFrameForBundleAdjustment method initializeGrid.

@Test
void initializeGrid() {
    var scene = new VisOdomBundleAdjustment<>(BTrack::new);
    var alg = new SelectTracksInFrameForBundleAdjustment(0xBEEF);
    alg.minTrackObservations = 1;
    scene.addCamera(new CameraPinholeBrown(0, 0, 0, 0, 0, width, height));
    for (int i = 0; i < 3; i++) {
        scene.addFrame(i);
    }
    BFrame targetFrame = scene.frames.get(2);
    // create enough tracks for there to be one in each cell
    connectFrames(1, 2, 200, scene);
    for (int i = 0; i < scene.tracks.size; i++) {
        BTrack track = scene.tracks.get(i);
        // pixel coordinates
        int x = (i * 10) % width;
        int y = 10 * ((i * 10) / width);
        // make sure it's false. should be already
        track.selected = false;
        track.findObservationBy(targetFrame).pixel.setTo(x, y);
    }
    // mark this one as active so that it isn't added to a cell. There should only be one empty cell
    scene.tracks.get(2).selected = true;
    // run it
    alg.initializeGrid(targetFrame, width, height, 10);
    // There should be one track in all but one cell
    for (int i = 0; i < alg.grid.cells.size; i++) {
        Info cell = alg.grid.cells.get(i);
        if (i != 2) {
            assertEquals(0, cell.alreadySelected);
            assertEquals(1, cell.unselected.size());
            assertSame(scene.tracks.get(i), cell.unselected.get(0));
        } else {
            assertEquals(1, cell.alreadySelected);
            assertEquals(0, cell.unselected.size());
        }
    }
}
Also used : CameraPinholeBrown(boofcv.struct.calib.CameraPinholeBrown) BFrame(boofcv.alg.sfm.d3.structure.VisOdomBundleAdjustment.BFrame) Info(boofcv.alg.sfm.d3.structure.SelectTracksInFrameForBundleAdjustment.Info) BTrack(boofcv.alg.sfm.d3.structure.VisOdomBundleAdjustment.BTrack) Test(org.junit.jupiter.api.Test)

Example 10 with BTrack

use of boofcv.alg.sfm.d3.structure.VisOdomBundleAdjustment.BTrack in project BoofCV by lessthanoptimal.

the class TestVisOdomBundleAdjustment method addFrame.

@Test
void addFrame() {
    VisOdomBundleAdjustment<BTrack> alg = createAlgSingleCamera();
    BFrame frameA = alg.addFrame(0);
    frameA.frame_to_world.T.x = 10;
    // Very simple test
    assertEquals(1, alg.frames.size);
    assertEquals(0, alg.frames.get(0).id);
    // See if the frame is recycled correctly
    alg.reset();
    alg.addFrameDebug(2);
    assertEquals(1, alg.frames.size);
    assertSame(frameA, alg.frames.get(0));
    assertEquals(2, frameA.id);
    assertEquals(0, frameA.frame_to_world.T.x, UtilEjml.TEST_F64);
    // Add one more frame now
    BFrame frameB = alg.addFrameDebug(11);
    assertEquals(2, alg.frames.size);
    assertSame(frameB, alg.getLastFrame());
    assertEquals(11, frameB.id);
}
Also used : BFrame(boofcv.alg.sfm.d3.structure.VisOdomBundleAdjustment.BFrame) BTrack(boofcv.alg.sfm.d3.structure.VisOdomBundleAdjustment.BTrack) Test(org.junit.jupiter.api.Test)

Aggregations

BTrack (boofcv.alg.sfm.d3.structure.VisOdomBundleAdjustment.BTrack)25 BFrame (boofcv.alg.sfm.d3.structure.VisOdomBundleAdjustment.BFrame)13 Test (org.junit.jupiter.api.Test)12 CameraPinholeBrown (boofcv.struct.calib.CameraPinholeBrown)4 DogArray_I32 (org.ddogleg.struct.DogArray_I32)4 BObservation (boofcv.alg.sfm.d3.structure.VisOdomBundleAdjustment.BObservation)3 VerbosePrint (org.ddogleg.struct.VerbosePrint)3 PointTrack (boofcv.abst.tracker.PointTrack)1 LensDistortionPinhole (boofcv.alg.distort.pinhole.LensDistortionPinhole)1 Info (boofcv.alg.sfm.d3.structure.SelectTracksInFrameForBundleAdjustment.Info)1 Point2Transform2_F64 (boofcv.struct.distort.Point2Transform2_F64)1 UtilPoint3D_F64 (georegression.geometry.UtilPoint3D_F64)1 Point2D_F64 (georegression.struct.point.Point2D_F64)1 Point3D_F64 (georegression.struct.point.Point3D_F64)1 Point4D_F64 (georegression.struct.point.Point4D_F64)1 ArrayList (java.util.ArrayList)1