Search in sources :

Example 1 with PackedTupleArray_F32

use of boofcv.struct.feature.PackedTupleArray_F32 in project BoofCV by lessthanoptimal.

the class TestSimilarImagesTrackThenMatch method simpleLoop.

/**
 * Faking the inputs, see if it can attack all frames to the first frame when tracking fails
 */
@Test
void simpleLoop() {
    int numViews = 6;
    var alg = new SimilarImagesTrackThenMatch<>(new DummyDetector(), new AssociateDescriptionHashSets<>(FactoryAssociation.greedy(null, new ScoreAssociateEuclideanSq.F32())), new DummyRecognizerLoop(numViews), () -> new PackedTupleArray_F32(1));
    // Remove any restriction on how many frames need to have past
    alg.minimumRecognizeDistance = 0;
    alg.initialize(10, 20);
    // A dummy image
    GrayU8 image = new GrayU8(10, 20);
    // Create a set of tracks
    int numTracks = 20;
    DogArray<PointTrack> tracks = new DogArray<>(PointTrack::new);
    for (int i = 0; i < numTracks; i++) {
        PointTrack t = tracks.grow();
        t.pixel.setTo(i, 21 * (i + 1));
        t.featureId = i;
    }
    // the frame-to-frame tracker will fail but the recognizer will match everything to frame 0
    for (int frameID = 0; frameID < numViews; frameID++) {
        alg.processFrame(image, tracks.toList(), frameID);
        for (int i = 0; i < tracks.size; i++) {
            PointTrack t = tracks.get(i);
            t.pixel.setTo((frameID + 1) * numTracks, 21 * (i + 1));
            // this will prevent the tracker from matching frames
            t.featureId = i + (frameID + 1) * numTracks;
        }
    }
    // Has to be called after frame to frame tracking
    alg.finishedTracking();
    // Storage for association results
    DogArray<AssociatedIndex> pairs = new DogArray<>(AssociatedIndex::new);
    List<String> listImages = alg.getImageIDs();
    List<String> listSimilar = new ArrayList<>();
    // everything should be matched to the first frame
    alg.findSimilar(listImages.get(0), null, listSimilar);
    assertEquals(numViews - 1, listSimilar.size());
    for (String similarID : listSimilar) {
        assertTrue(alg.lookupAssociated(similarID, pairs));
        assertEquals(numTracks, pairs.size);
    }
    // Other frames shouldn't be matched with each other
    for (int frameIdx = 1; frameIdx < 6; frameIdx++) {
        alg.findSimilar(listImages.get(frameIdx), null, listSimilar);
        assertEquals(1, listSimilar.size());
    }
}
Also used : PackedTupleArray_F32(boofcv.struct.feature.PackedTupleArray_F32) ArrayList(java.util.ArrayList) ScoreAssociateEuclideanSq(boofcv.abst.feature.associate.ScoreAssociateEuclideanSq) DogArray(org.ddogleg.struct.DogArray) PointTrack(boofcv.abst.tracker.PointTrack) GrayU8(boofcv.struct.image.GrayU8) AssociatedIndex(boofcv.struct.feature.AssociatedIndex) Test(org.junit.jupiter.api.Test)

Aggregations

ScoreAssociateEuclideanSq (boofcv.abst.feature.associate.ScoreAssociateEuclideanSq)1 PointTrack (boofcv.abst.tracker.PointTrack)1 AssociatedIndex (boofcv.struct.feature.AssociatedIndex)1 PackedTupleArray_F32 (boofcv.struct.feature.PackedTupleArray_F32)1 GrayU8 (boofcv.struct.image.GrayU8)1 ArrayList (java.util.ArrayList)1 DogArray (org.ddogleg.struct.DogArray)1 Test (org.junit.jupiter.api.Test)1