Search in sources :

Example 46 with DogArray_I32

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

the class PruneStructureFromSceneMetric method pruneViews.

/**
 * Removes views with less than or equal to 'count' features visible. Observations of features
 * in removed views are also removed. Views which are parents (after children than can be removed have been
 * removed) will remain since they are needed for the correct transform.
 *
 * @param count Prune if less than or equal to this many features
 * @return true if the graph has been modified
 */
public boolean pruneViews(int count) {
    DogArray_I32 removeIdx = new DogArray_I32();
    Set<SceneStructureMetric.View> parents = new HashSet<>();
    // chain of views needs to be removed they will be removed
    for (int viewId = structure.views.size - 1; viewId >= 0; viewId--) {
        SceneObservations.View oview = observations.views.data[viewId];
        SceneStructureMetric.View sview = structure.views.data[viewId];
        // See if has enough observations to not prune or is a parent and can't be pruned
        if (oview.size() > count || parents.contains(sview)) {
            // mark it's parent as a parent
            if (sview.parent != null)
                parents.add(sview.parent);
            continue;
        }
        removeIdx.add(viewId);
        // Go through list of points and remove this view from them
        for (int pointIdx = 0; pointIdx < oview.point.size; pointIdx++) {
            int pointId = oview.getPointId(pointIdx);
            int viewIdx = structure.points.data[pointId].views.indexOf(viewId);
            if (viewIdx < 0)
                throw new RuntimeException("Bug in structure. view has point but point doesn't have view");
            structure.points.data[pointId].views.remove(viewIdx);
        }
    }
    if (removeIdx.isEmpty())
        return false;
    // Remove the views
    structure.views.remove(removeIdx.data, 0, removeIdx.size, null);
    observations.views.remove(removeIdx.data, 0, removeIdx.size, null);
    return true;
}
Also used : DogArray_I32(org.ddogleg.struct.DogArray_I32)

Example 47 with DogArray_I32

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

the class PruneStructureFromSceneProjective method prunePoints.

/**
 * Prunes Points/features with less than 'count' observations. Observations of the points are also removed.
 *
 * Call {@link #pruneViews(int)} to ensure that all views have points in view
 *
 * @param count Minimum number of observations
 */
public boolean prunePoints(int count) {
    // create a lookup table from old to new point indexes
    int[] oldToNew = new int[structure.points.size];
    // list of remaining points
    DogArray_I32 removeIdx = new DogArray_I32();
    // List<SceneStructureProjective.Point> remainingP = new ArrayList<>();
    for (int pointIdx = 0; pointIdx < structure.points.size; pointIdx++) {
        SceneStructureCommon.Point sp = structure.points.data[pointIdx];
        if (sp.views.size < count) {
            removeIdx.add(pointIdx);
            // remove observations of this point from each view
            for (int i = 0; i < sp.views.size; i++) {
                int viewIdx = sp.views.data[i];
                SceneObservations.View ov = observations.views.get(viewIdx);
                int localIdx = ov.point.indexOf(pointIdx);
                if (localIdx == -1)
                    throw new RuntimeException("Point not in view's observation!?");
                ov.remove(localIdx);
            }
        } else {
            oldToNew[pointIdx] = pointIdx - removeIdx.size();
        }
    }
    // if all of them are still remaining nothing changed
    if (removeIdx.size == 0)
        return false;
    // update point references
    for (int viewIdx = 0; viewIdx < structure.views.size; viewIdx++) {
        SceneObservations.View so = observations.views.get(viewIdx);
        for (int i = 0; i < so.point.size; i++) {
            so.point.data[i] = oldToNew[so.point.data[i]];
        }
    }
    // Remove the pruned points
    structure.removePoints(removeIdx);
    return true;
}
Also used : DogArray_I32(org.ddogleg.struct.DogArray_I32)

Example 48 with DogArray_I32

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

the class TestSceneStructureCommon method removePoints.

@Test
void removePoints() {
    MockSceneStructureCommon structure = new MockSceneStructureCommon(false);
    structure.homogenous = false;
    structure.pointSize = 3;
    List<Point> original = new ArrayList<>();
    for (int i = 0; i < 20; i++) {
        original.add(structure.points.grow());
    }
    DogArray_I32 which = new DogArray_I32();
    which.add(2);
    which.add(5);
    structure.removePoints(which);
    assertEquals(18, structure.points.size);
    assertSame(original.get(0), structure.points.data[0]);
    assertSame(original.get(3), structure.points.data[2]);
    assertSame(original.get(4), structure.points.data[3]);
    assertSame(original.get(7), structure.points.data[5]);
    assertSame(original.get(19), structure.points.data[17]);
}
Also used : ArrayList(java.util.ArrayList) Point(boofcv.abst.geo.bundle.SceneStructureCommon.Point) DogArray_I32(org.ddogleg.struct.DogArray_I32) Point(boofcv.abst.geo.bundle.SceneStructureCommon.Point) Test(org.junit.jupiter.api.Test)

Example 49 with DogArray_I32

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

the class CommonGenerateMetricCameraTripleChecks method checkScene.

private void checkScene() {
    ModelGeneratorViews<MetricCameraTriple, AssociatedTriple, ElevateViewInfo> alg = createGenerator();
    assertEquals(3, alg.getNumberOfViews());
    for (int i = 0; i < 3; i++) {
        alg.setView(i, new ElevateViewInfo(800, 600, i));
    }
    assertTrue(alg.getMinimumPoints() > 0);
    var found = new MetricCameraTriple();
    List<AssociatedTriple> selected = new ArrayList<>();
    DogArray_I32 indexes = DogArray_I32.range(0, numFeatures);
    int countSuccess = 0;
    for (int trial = 0; trial < totalTrials; trial++) {
        // Randomly select different points each trial
        PrimitiveArrays.shuffle(indexes.data, 0, numFeatures, rand);
        selected.clear();
        for (int i = 0; i < alg.getMinimumPoints() + extraObservations; i++) {
            selected.add(observations3.get(indexes.get(i)));
        }
        // Compute the model
        if (!alg.generate(selected, found)) {
            continue;
        }
        countSuccess++;
        // System.out.println("Trial = "+trial);
        // Check results
        checkEquals(cameraA, found.view1);
        checkEquals(cameraB, found.view2);
        checkEquals(cameraC, found.view3);
        BoofTesting.assertEqualsToScaleS(truthView_1_to_i(1), found.view_1_to_2, 1e-2, 1e-3);
        BoofTesting.assertEqualsToScaleS(truthView_1_to_i(2), found.view_1_to_3, 1e-2, 1e-3);
    }
    // System.out.println("Passed "+countSuccess+" / "+totalTrials);
    assertTrue(minimumFractionSuccess * totalTrials <= countSuccess, "Failed " + (totalTrials - countSuccess) + " min " + (minimumFractionSuccess * totalTrials - countSuccess));
}
Also used : MetricCameraTriple(boofcv.alg.geo.selfcalib.MetricCameraTriple) AssociatedTriple(boofcv.struct.geo.AssociatedTriple) ArrayList(java.util.ArrayList) DogArray_I32(org.ddogleg.struct.DogArray_I32) ElevateViewInfo(boofcv.struct.calib.ElevateViewInfo)

Example 50 with DogArray_I32

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

the class TestPointCloudUtils_F64 method prune_color.

@Test
void prune_color() {
    List<Point3D_F64> list = new ArrayList<>();
    DogArray_I32 rgb = new DogArray_I32();
    for (int i = 0; i < 100; i++) {
        list.add(new Point3D_F64(i * 0.1, 0, 0));
        rgb.add(i);
    }
    PointCloudUtils_F64.prune(list, rgb, 3, 0.31);
    assertEquals(100, list.size());
    assertEquals(100, rgb.size());
    // end points should be pruned
    PointCloudUtils_F64.prune(list, rgb, 3, 0.28);
    assertEquals(98, list.size());
    assertEquals(98, rgb.size());
    assertEquals(1, rgb.get(0));
    assertEquals(97, rgb.get(96));
}
Also used : Point3D_F64(georegression.struct.point.Point3D_F64) ArrayList(java.util.ArrayList) 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