Search in sources :

Example 41 with DogArray

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

the class TestAssociateGreedyBruteForce2D_MT method createPoints.

public static DogArray<Point2D_F64> createPoints(int count) {
    Random rand = new Random(234);
    DogArray<Point2D_F64> ret = new DogArray<>(count, Point2D_F64::new);
    for (int i = 0; i < count; i++) {
        ret.grow().setTo(rand.nextDouble() * width, rand.nextDouble() * height);
    }
    return ret;
}
Also used : Random(java.util.Random) Point2D_F64(georegression.struct.point.Point2D_F64) DogArray(org.ddogleg.struct.DogArray)

Example 42 with DogArray

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

the class PointCloudUtils_F64 method prune.

/**
 * Prunes points from the point cloud if they have very few neighbors
 *
 * @param cloud Point cloud
 * @param colors Color of each point.
 * @param minNeighbors Minimum number of neighbors for it to not be pruned
 * @param radius search distance for neighbors
 */
public static void prune(List<Point3D_F64> cloud, DogArray_I32 colors, int minNeighbors, double radius) {
    if (minNeighbors < 0)
        throw new IllegalArgumentException("minNeighbors must be >= 0");
    NearestNeighbor<Point3D_F64> nn = FactoryNearestNeighbor.kdtree(new KdTreePoint3D_F64());
    NearestNeighbor.Search<Point3D_F64> search = nn.createSearch();
    nn.setPoints(cloud, false);
    DogArray<NnData<Point3D_F64>> results = new DogArray<>(NnData::new);
    // It will always find itself
    minNeighbors += 1;
    // distance is Euclidean squared
    radius *= radius;
    for (int i = cloud.size() - 1; i >= 0; i--) {
        search.findNearest(cloud.get(i), radius, minNeighbors, results);
        if (results.size < minNeighbors) {
            cloud.remove(i);
            colors.remove(i);
        }
    }
}
Also used : FactoryNearestNeighbor(org.ddogleg.nn.FactoryNearestNeighbor) NearestNeighbor(org.ddogleg.nn.NearestNeighbor) KdTreePoint3D_F64(georegression.helper.KdTreePoint3D_F64) Point3D_F64(georegression.struct.point.Point3D_F64) NnData(org.ddogleg.nn.NnData) DogArray(org.ddogleg.struct.DogArray) KdTreePoint3D_F64(georegression.helper.KdTreePoint3D_F64)

Example 43 with DogArray

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

the class TestRelinearlize method createInputs.

private void createInputs(int numControl) {
    if (numControl == 4) {
        L_full = new DMatrixRMaj(6, 10);
        y = new DMatrixRMaj(6, 1);
    } else {
        L_full = new DMatrixRMaj(3, 6);
        y = new DMatrixRMaj(3, 1);
    }
    // randomly select null points,
    List<Point3D_F64>[] nullPts = new ArrayList[numControl];
    for (int i = 0; i < numControl - 1; i++) {
        nullPts[i] = GeoTestingOps.randomPoints_F64(-1, 1, -1, 1, -1, 1, numControl, rand);
    }
    nullPts[numControl - 1] = new ArrayList<>();
    nullPts[numControl - 1].add(new Point3D_F64(1, 0, 0));
    nullPts[numControl - 1].add(new Point3D_F64(0, 1, 0));
    nullPts[numControl - 1].add(new Point3D_F64(0, 0, 1));
    if (numControl == 4)
        nullPts[numControl - 1].add(new Point3D_F64(0, 0, 0));
    // using the provided beta compute the world points
    // this way the constraint matrix will be consistent
    DogArray<Point3D_F64> worldPts = new DogArray<>(4, Point3D_F64::new);
    worldPts.grow().setTo(1, 0, 0);
    worldPts.grow().setTo(0, 1, 0);
    worldPts.grow().setTo(0, 0, 1);
    if (numControl == 4)
        worldPts.grow().setTo(0, 0, 0);
    if (numControl == 4)
        UtilLepetitEPnP.constraintMatrix6x10(L_full, y, worldPts, nullPts);
    else
        UtilLepetitEPnP.constraintMatrix3x6(L_full, y, worldPts, nullPts);
}
Also used : Point3D_F64(georegression.struct.point.Point3D_F64) DMatrixRMaj(org.ejml.data.DMatrixRMaj) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) DogArray(org.ddogleg.struct.DogArray)

Example 44 with DogArray

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

the class TestPnPLepetitEPnP method computeBarycentricCoordinates.

@Test
void computeBarycentricCoordinates() {
    List<Point3D_F64> worldPoints = GeoTestingOps.randomPoints_F64(-1, 10, -5, 20, 0.1, 0.5, 30, rand);
    DogArray<Point3D_F64> worldControlPts = new DogArray<>(4, Point3D_F64::new);
    PnPLepetitEPnP alg = new PnPLepetitEPnP();
    alg.selectWorldControlPoints(worldPoints, worldControlPts);
    DMatrixRMaj alpha = new DMatrixRMaj(1, 1);
    alg.computeBarycentricCoordinates(worldControlPts, alpha, worldPoints);
    // make sure it sums up to one and it should add up to the original point
    for (int i = 0; i < worldPoints.size(); i++) {
        double x = 0, y = 0, z = 0;
        double sum = 0;
        for (int j = 0; j < 4; j++) {
            Point3D_F64 cj = worldControlPts.get(j);
            double a = alpha.get(i, j);
            sum += a;
            x += a * cj.x;
            y += a * cj.y;
            z += a * cj.z;
        }
        Point3D_F64 p = worldPoints.get(i);
        assertEquals(1, sum, 1e-8);
        assertEquals(p.x, x, 1e-8);
        assertEquals(p.y, y, 1e-8);
        assertEquals(p.z, z, 1e-8);
    }
}
Also used : Point3D_F64(georegression.struct.point.Point3D_F64) DMatrixRMaj(org.ejml.data.DMatrixRMaj) DogArray(org.ddogleg.struct.DogArray) Test(org.junit.jupiter.api.Test)

Example 45 with DogArray

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

the class ExampleAssociateThreeView method main.

public static void main(String[] args) {
    String name = "rock_leaves_";
    GrayU8 gray01 = UtilImageIO.loadImage(UtilIO.pathExample("triple/" + name + "01.jpg"), GrayU8.class);
    GrayU8 gray02 = UtilImageIO.loadImage(UtilIO.pathExample("triple/" + name + "02.jpg"), GrayU8.class);
    GrayU8 gray03 = UtilImageIO.loadImage(UtilIO.pathExample("triple/" + name + "03.jpg"), GrayU8.class);
    // Using SURF features. Robust and fairly fast to compute
    DetectDescribePoint<GrayU8, TupleDesc_F64> detDesc = FactoryDetectDescribe.surfStable(new ConfigFastHessian(0, 4, 1000, 1, 9, 4, 2), null, null, GrayU8.class);
    ExampleAssociateThreeView example = new ExampleAssociateThreeView();
    example.initialize(detDesc);
    // Compute and describe features inside the image
    example.detectFeatures(gray01, 0);
    example.detectFeatures(gray02, 1);
    example.detectFeatures(gray03, 2);
    System.out.println("features01.size = " + example.features01.size);
    System.out.println("features02.size = " + example.features02.size);
    System.out.println("features03.size = " + example.features03.size);
    // Find features for an association ring across all the views. This removes most false positives.
    DogArray<AssociatedTripleIndex> associatedIdx = example.threeViewPairwiseAssociate();
    // Convert the matched indexes into AssociatedTriple which contain the actual pixel coordinates
    var associated = new DogArray<>(AssociatedTriple::new);
    associatedIdx.forEach(p -> associated.grow().setTo(example.locations01.get(p.a), example.locations02.get(p.b), example.locations03.get(p.c)));
    System.out.println("Total Matched Triples = " + associated.size);
    // Show remaining associations from RANSAC
    var triplePanel = new AssociatedTriplePanel();
    triplePanel.setImages(UtilImageIO.loadImageNotNull(UtilIO.pathExample("triple/" + name + "01.jpg")), UtilImageIO.loadImageNotNull(UtilIO.pathExample("triple/" + name + "02.jpg")), UtilImageIO.loadImageNotNull(UtilIO.pathExample("triple/" + name + "03.jpg")));
    triplePanel.setAssociation(associated.toList());
    ShowImages.showWindow(triplePanel, "Associations", true);
}
Also used : AssociatedTriple(boofcv.struct.geo.AssociatedTriple) ConfigFastHessian(boofcv.abst.feature.detect.interest.ConfigFastHessian) TupleDesc_F64(boofcv.struct.feature.TupleDesc_F64) AssociatedTriplePanel(boofcv.gui.feature.AssociatedTriplePanel) AssociatedTripleIndex(boofcv.struct.feature.AssociatedTripleIndex) GrayU8(boofcv.struct.image.GrayU8) DogArray(org.ddogleg.struct.DogArray)

Aggregations

DogArray (org.ddogleg.struct.DogArray)79 Test (org.junit.jupiter.api.Test)48 ArrayList (java.util.ArrayList)27 Point3D_F64 (georegression.struct.point.Point3D_F64)18 DogArray_I32 (org.ddogleg.struct.DogArray_I32)17 Point2D_F64 (georegression.struct.point.Point2D_F64)16 GrayU8 (boofcv.struct.image.GrayU8)13 TupleDesc_F64 (boofcv.struct.feature.TupleDesc_F64)10 Point2D_I32 (georegression.struct.point.Point2D_I32)7 DMatrixRMaj (org.ejml.data.DMatrixRMaj)7 BufferedImage (java.awt.image.BufferedImage)6 Point3dRgbI_F64 (boofcv.struct.Point3dRgbI_F64)5 CameraPinholeBrown (boofcv.struct.calib.CameraPinholeBrown)5 List (java.util.List)5 PositionPatternNode (boofcv.alg.fiducial.qrcode.PositionPatternNode)4 ConvertBufferedImage (boofcv.io.image.ConvertBufferedImage)4 GrayF32 (boofcv.struct.image.GrayF32)4 PointCloudViewer (boofcv.visualize.PointCloudViewer)4 Se3_F64 (georegression.struct.se.Se3_F64)4 FactoryNearestNeighbor (org.ddogleg.nn.FactoryNearestNeighbor)4