Search in sources :

Example 1 with Frame

use of boofcv.alg.similar.SimilarImagesFromTracks.Frame in project BoofCV by lessthanoptimal.

the class TestSimilarImagesFromTracks method findRelatedPastFrames_no_common.

/**
 * No common features so no match should be created.
 */
@Test
void findRelatedPastFrames_no_common() {
    var tracker = new MockTracker();
    SimilarImagesFromTracks<PointTrack> alg = createTracker();
    // create two frames with common observations
    for (int i = 0; i < 2; i++) {
        tracker.process(null);
        alg.createFrameSaveObservations(tracker.getActiveTracks(null), tracker.getFrameID());
    }
    // make the most recent incompatible with the previous
    Frame current = alg.frames.get(1);
    current.id_to_index.clear();
    for (int i = 0; i < current.featureCount(); i++) {
        current.ids[i] = 100 + i;
        current.id_to_index.put(current.ids[i], i);
    }
    alg.findRelatedPastFrames(current);
    for (int i = 0; i < alg.frames.size; i++) {
        assertEquals(0, alg.frames.get(i).matches.size());
    }
}
Also used : Frame(boofcv.alg.similar.SimilarImagesFromTracks.Frame) PointTrack(boofcv.abst.tracker.PointTrack) Test(org.junit.jupiter.api.Test)

Example 2 with Frame

use of boofcv.alg.similar.SimilarImagesFromTracks.Frame in project BoofCV by lessthanoptimal.

the class TestSimilarImagesFromTracks method minimumCommonTracks.

/**
 * Nake sure that this configuration is used correctly internally
 */
@Test
void minimumCommonTracks() {
    var tracker = new MockTracker();
    tracker.numTracks = 20;
    SimilarImagesFromTracks<PointTrack> alg = createTracker();
    alg.initialize(30, 40);
    // every frame there is one less track in common. Since there are 20 tracks, 18 means it should
    // be matched with 2 frames within its radius
    alg.minimumCommonTracks.setFixed(18);
    for (int i = 0; i < 6; i++) {
        tracker.process(null);
        // this is what causes N-1 features to be in common between frames
        tracker.offsetID++;
        alg.processFrame(tracker.getActiveTracks(null), tracker.getFrameID());
        if (i <= 2)
            continue;
        // Check the most recently added frame
        SimilarImagesFromTracks.Frame frame = alg.frames.getTail();
        assertEquals(2, frame.related.size());
    }
    // double check that it's matching them symmetrically
    assertEquals(4, alg.frames.get(3).related.size());
}
Also used : PointTrack(boofcv.abst.tracker.PointTrack) Frame(boofcv.alg.similar.SimilarImagesFromTracks.Frame) Test(org.junit.jupiter.api.Test)

Example 3 with Frame

use of boofcv.alg.similar.SimilarImagesFromTracks.Frame in project BoofCV by lessthanoptimal.

the class TestSimilarImagesFromTracks method createFrameSaveObservations.

@Test
void createFrameSaveObservations() {
    var tracker = new MockTracker();
    SimilarImagesFromTracks<PointTrack> alg = createTracker();
    assertEquals(0, alg.frames.size);
    tracker.process(null);
    alg.createFrameSaveObservations(tracker.getActiveTracks(null), tracker.getFrameID());
    assertEquals(1, alg.frameMap.size());
    assertEquals(1, alg.frames.size);
    Frame frame = alg.frames.get(0);
    assertEquals("0", frame.frameID);
    assertSame(frame, alg.frameMap.get(frame.frameID));
    assertEquals(tracker.numTracks, frame.featureCount());
    var foundPixel = new Point2D_F64();
    for (int i = 0; i < frame.featureCount(); i++) {
        assertEquals(i, frame.getID(i));
        frame.getPixel(i, foundPixel);
        assertEquals(i, foundPixel.x, UtilEjml.TEST_F64);
        assertEquals(i + 1, foundPixel.y, UtilEjml.TEST_F64);
    }
    // see if it can handle adding another frame
    tracker.process(null);
    alg.createFrameSaveObservations(tracker.getActiveTracks(null), tracker.getFrameID());
    assertEquals(2, alg.frameMap.size());
    assertEquals(2, alg.frames.size);
    frame = alg.frames.get(1);
    assertEquals("1", frame.frameID);
    assertSame(frame, alg.frameMap.get(frame.frameID));
    assertEquals(tracker.numTracks, frame.featureCount());
}
Also used : Frame(boofcv.alg.similar.SimilarImagesFromTracks.Frame) PointTrack(boofcv.abst.tracker.PointTrack) Point2D_F64(georegression.struct.point.Point2D_F64) Test(org.junit.jupiter.api.Test)

Example 4 with Frame

use of boofcv.alg.similar.SimilarImagesFromTracks.Frame in project BoofCV by lessthanoptimal.

the class TestSimilarImagesFromTracks method findRelatedPastFrames_matched.

/**
 * All but one observation match
 */
@Test
void findRelatedPastFrames_matched() {
    var tracker = new MockTracker();
    SimilarImagesFromTracks<PointTrack> alg = createTracker();
    // create two frames with common observations
    for (int i = 0; i < 2; i++) {
        tracker.process(null);
        alg.createFrameSaveObservations(tracker.getActiveTracks(null), tracker.getFrameID());
    }
    // make the most recent incompatible with the previous
    Frame current = alg.frames.get(1);
    current.id_to_index.remove(15);
    current.ids[15] = 115;
    current.id_to_index.put(115, 15);
    // randomize the ID order to make things more interesting. This will mess up which observation they point to
    PrimitiveArrays.shuffle(current.ids, 0, current.ids.length, rand);
    alg.findRelatedPastFrames(current);
    for (int i = 0; i < alg.frames.size; i++) {
        Frame f = alg.frames.get(i);
        assertEquals(1, f.matches.size());
        Match matches = alg.connections.get(0);
        assertEquals(19, matches.size());
        assertNotSame(matches.frameSrc, matches.frameDst);
        assertTrue(matches.frameSrc == f || matches.frameDst == f);
    // checks to see if the ids are consistent is done in the system check above
    }
}
Also used : Frame(boofcv.alg.similar.SimilarImagesFromTracks.Frame) PointTrack(boofcv.abst.tracker.PointTrack) Match(boofcv.alg.similar.SimilarImagesFromTracks.Match) Test(org.junit.jupiter.api.Test)

Aggregations

PointTrack (boofcv.abst.tracker.PointTrack)4 Frame (boofcv.alg.similar.SimilarImagesFromTracks.Frame)4 Test (org.junit.jupiter.api.Test)4 Match (boofcv.alg.similar.SimilarImagesFromTracks.Match)1 Point2D_F64 (georegression.struct.point.Point2D_F64)1