Search in sources :

Example 16 with DogArray_I32

use of org.ddogleg.struct.DogArray_I32 in project BoofCV by lessthanoptimal.

the class TestSimilarImagesSceneRecognition method simpleAllTogether.

/**
 * Simple scenario which exercises everything all at once
 */
@Test
void simpleAllTogether() {
    var config = new ConfigSimilarImagesSceneRecognition();
    // Needed to do some hacking since the defaults assume there are a bunch of image features
    config.minimumSimilar.setRelative(0.1, 0.0);
    config.recognizeNister2006.minimumDepthFromRoot = 0;
    SimilarImagesSceneRecognition<GrayU8, TupleDesc_F32> alg = FactorySceneReconstruction.createSimilarImages(config, ImageType.SB_U8);
    alg.detector = new HelperDetector();
    for (int i = 0; i < 5; i++) {
        alg.addImage("" + i, new GrayU8(50, 10));
    }
    alg.fixate();
    // For all these other functions just check to see if something got populated
    DogArray_I32 words = new DogArray_I32();
    alg.lookupImageWords("3", words);
    assertTrue(words.size > 0);
    var features = new DogArray<>(Point2D_F64::new);
    alg.lookupPixelFeats("1", features);
    assertTrue(features.size > 0);
    // Look up similar images. All but the query view should be similar
    List<String> similarImages = new ArrayList<>();
    alg.findSimilar("0", (a) -> true, similarImages);
    assertTrue(similarImages.size() > 0);
    var pairs = new DogArray<>(AssociatedIndex::new);
    alg.lookupAssociated(similarImages.get(0), pairs);
    assertTrue(features.size > 0);
}
Also used : TupleDesc_F32(boofcv.struct.feature.TupleDesc_F32) ArrayList(java.util.ArrayList) DogArray_I32(org.ddogleg.struct.DogArray_I32) DogArray(org.ddogleg.struct.DogArray) Point2D_F64(georegression.struct.point.Point2D_F64) GrayU8(boofcv.struct.image.GrayU8) AssociatedIndex(boofcv.struct.feature.AssociatedIndex) Test(org.junit.jupiter.api.Test)

Example 17 with DogArray_I32

use of org.ddogleg.struct.DogArray_I32 in project BoofCV by lessthanoptimal.

the class VisOdomBundlePnPBase method performKeyFrameMaintenance.

/**
 * Drops specified keyframes from the scene. Returns true if the current frame was dropped
 *
 * @param tracker tracker
 * @param newFrames Number of new frames added to the scene
 * @return true if current frame
 */
protected boolean performKeyFrameMaintenance(PointTracker<?> tracker, int newFrames) {
    DogArray_I32 dropFrameIndexes = frameManager.selectFramesToDiscard(tracker, maxKeyFrames, newFrames, bundleViso);
    boolean droppedCurrentFrame = false;
    if (dropFrameIndexes.size != 0) {
        droppedCurrentFrame = dropFrameIndexes.getTail(0) == bundleViso.frames.size - 1;
        dropFramesFromScene(dropFrameIndexes);
    }
    dropTracksNotVisibleAndTooFewObservations();
    updateListOfVisibleTracksForOutput();
    return droppedCurrentFrame;
}
Also used : DogArray_I32(org.ddogleg.struct.DogArray_I32)

Example 18 with DogArray_I32

use of org.ddogleg.struct.DogArray_I32 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 19 with DogArray_I32

use of org.ddogleg.struct.DogArray_I32 in project BoofCV by lessthanoptimal.

the class LearnHierarchicalTree method processLevel.

/**
 * Cluster each branch in the tree for the set of points in the node
 *
 * @param pointsInParent Points that are members of the parent
 * @param tree The tree that's being learned
 * @param level Level in the HierarchicalVocabularyTree
 * @param parentNodeIdx Array index for the parent node
 */
private void processLevel(PackedArray<Point> pointsInParent, HierarchicalVocabularyTree<Point> tree, int level, int parentNodeIdx) {
    // Stop here if we are at the maximum number of levels or there are too few points
    if (level >= tree.maximumLevel || pointsInParent.size() <= pointsRequiredForChildren)
        return;
    // Get k-means for this level
    StandardKMeans<Point> kmeans = listKMeans.get(level);
    // Cluster the input points
    kmeans.process(pointsInParent, tree.branchFactor);
    DogArray_I32 assignments = kmeans.getAssignments();
    List<Point> clusterMeans = kmeans.getBestClusters().toList();
    // and this "might" reduce cache misses in searching
    for (int label = 0; label < clusterMeans.size(); label++) {
        tree.addNode(parentNodeIdx, label, clusterMeans.get(label));
    }
    if (verbose != null)
        verbose.println("level=" + level + " kmeans.score=" + kmeans.getBestClusterScore());
    // Load the points that are in the child sub region
    Node parent = tree.nodes.get(parentNodeIdx);
    // Create pyramid nodes from the children
    PackedArray<Point> pointsInBranch = listPoints.get(level);
    pointsInBranch.reserve(pointsInParent.size() / (tree.branchFactor - 1));
    processChildren(tree, level, parent, pointsInParent, clusterMeans, assignments, pointsInBranch);
}
Also used : Node(boofcv.alg.scene.vocabtree.HierarchicalVocabularyTree.Node) DogArray_I32(org.ddogleg.struct.DogArray_I32) VerbosePrint(org.ddogleg.struct.VerbosePrint)

Example 20 with DogArray_I32

use of org.ddogleg.struct.DogArray_I32 in project BoofCV by lessthanoptimal.

the class TestReedSolomonCodes_U16 method correctErrors_hand.

/**
 * Compare against a hand computed scenario
 */
@Test
void correctErrors_hand() {
    DogArray_I16 message = DogArray_I16.parseHex("[ 0x40, 0xd2, 0x75, 0x47, 0x76, 0x17, 0x32, 0x06, 0x27, 0x26, 0x96, 0xc6, 0xc6, 0x96, 0x70, 0xec ]");
    var ecc = new DogArray_I16();
    DogArray_I16 syndromes = new DogArray_I16();
    DogArray_I16 errorLocator = new DogArray_I16();
    int nsyn = 10;
    var alg = new ReedSolomonCodes_U16(8, primitive8, 0);
    alg.generator(nsyn);
    alg.computeECC(message, ecc);
    DogArray_I16 corrupted = message.copy();
    corrupted.data[0] = 0;
    corrupted.data[4] = 8;
    corrupted.data[5] = 9;
    alg.computeSyndromes(corrupted, ecc, syndromes);
    alg.findErrorLocatorPolynomialBM(syndromes, errorLocator);
    DogArray_I32 errorLocations = new DogArray_I32(3);
    errorLocations.data[0] = 0;
    errorLocations.data[1] = 4;
    errorLocations.data[2] = 5;
    errorLocations.size = 3;
    alg.correctErrors(corrupted, message.size + ecc.size, syndromes, errorLocator, errorLocations);
    assertEquals(corrupted.size, message.size);
    for (int j = 0; j < corrupted.size; j++) {
        assertEquals(corrupted.get(j), message.get(j));
    }
}
Also used : DogArray_I16(org.ddogleg.struct.DogArray_I16) DogArray_I32(org.ddogleg.struct.DogArray_I32) Test(org.junit.jupiter.api.Test)

Aggregations

DogArray_I32 (org.ddogleg.struct.DogArray_I32)192 Test (org.junit.jupiter.api.Test)73 Point2D_I32 (georegression.struct.point.Point2D_I32)24 ArrayList (java.util.ArrayList)21 Point2D_F64 (georegression.struct.point.Point2D_F64)17 DogArray (org.ddogleg.struct.DogArray)17 TupleDesc_F64 (boofcv.struct.feature.TupleDesc_F64)15 GrayS32 (boofcv.struct.image.GrayS32)10 VerbosePrint (org.ddogleg.struct.VerbosePrint)7 View (boofcv.alg.structure.PairwiseImageGraph.View)6 AssociatedIndex (boofcv.struct.feature.AssociatedIndex)6 GrayI (boofcv.struct.image.GrayI)5 Point3D_F64 (georegression.struct.point.Point3D_F64)5 GrowArray (pabeles.concurrency.GrowArray)5 DetectDescribePoint (boofcv.abst.feature.detdesc.DetectDescribePoint)4 BTrack (boofcv.alg.sfm.d3.structure.VisOdomBundleAdjustment.BTrack)4 AssociatedTripleIndex (boofcv.struct.feature.AssociatedTripleIndex)4 SceneObservations (boofcv.abst.geo.bundle.SceneObservations)3 SceneWorkingGraph (boofcv.alg.structure.SceneWorkingGraph)3 ConfigAssociateGreedy (boofcv.factory.feature.associate.ConfigAssociateGreedy)3