Search in sources :

Example 11 with FastQueue

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

the class TestMergeRegionMeanShift method basicAll.

@Test
public void basicAll() {
    MergeRegionMeanShift alg = new MergeRegionMeanShift(1, 1);
    GrayS32 pixelToRegion = new GrayS32(4, 4);
    pixelToRegion.data = new int[] { 0, 0, 0, 1, 2, 0, 0, 1, 2, 0, 1, 1, 0, 0, 3, 1 };
    GrowQueue_I32 regionMemberCount = new GrowQueue_I32();
    regionMemberCount.data = new int[] { 1, 2, 3, 4 };
    regionMemberCount.size = 4;
    FastQueue<float[]> regionColor = createList(5, 1, 6, 4);
    FastQueue<Point2D_I32> modeLocation = new FastQueue<>(Point2D_I32.class, true);
    modeLocation.grow().set(0, 0);
    modeLocation.grow().set(3, 3);
    modeLocation.grow().set(0, 1);
    modeLocation.grow().set(2, 3);
    alg.process(pixelToRegion, regionMemberCount, regionColor, modeLocation);
    GrayS32 expectedP2R = new GrayS32(4, 4);
    expectedP2R.data = new int[] { 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 2, 1 };
    int[] expectedCount = new int[] { 4, 2, 4 };
    for (int i = 0; i < expectedP2R.data.length; i++) assertEquals(expectedP2R.data[i], pixelToRegion.data[i]);
    for (int i = 0; i < expectedCount.length; i++) assertEquals(expectedCount[i], regionMemberCount.data[i]);
}
Also used : FastQueue(org.ddogleg.struct.FastQueue) Point2D_I32(georegression.struct.point.Point2D_I32) GrayS32(boofcv.struct.image.GrayS32) GrowQueue_I32(org.ddogleg.struct.GrowQueue_I32) Test(org.junit.Test)

Example 12 with FastQueue

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

the class GenericFhEdgeWeightsChecks method basicTest.

@Test
public void basicTest() {
    T input = imageType.createImage(10, 12);
    GImageMiscOps.fillUniform(input, rand, 0, 200);
    FhEdgeWeights<T> alg = createAlg();
    FastQueue<Edge> edges = new FastQueue<>(Edge.class, true);
    alg.process(input, edges);
    int[] hist = new int[input.width * input.height];
    // see if the edges computed the expected weight
    for (int i = 0; i < edges.size(); i++) {
        Edge e = edges.get(i);
        int indexA = e.indexA;
        int indexB = e.indexB;
        hist[indexA]++;
        hist[indexB]++;
        float expected = weight(input, indexA, indexB);
        assertEquals(expected, e.weight(), 1e-4f);
    }
    // make sure each pixel was inspected
    if (rule == ConnectRule.FOUR) {
        for (int y = 0; y < input.height; y++) {
            for (int x = 0; x < input.width; x++) {
                if (x >= 1 && x < input.width - 1 && y >= 1 && y < input.height - 1)
                    assertEquals(hist[input.getIndex(x, y)], 4);
                else if (x == 0 && y == 0)
                    assertEquals(hist[input.getIndex(x, y)], 2);
                else if (x == input.width - 1 && y == 0)
                    assertEquals(hist[input.getIndex(x, y)], 2);
                else if (x == input.width - 1 && y == input.height - 1)
                    assertEquals(hist[input.getIndex(x, y)], 2);
                else if (x == 0 && y == input.height - 1)
                    assertEquals(hist[input.getIndex(x, y)], 2);
                else {
                    assertEquals(hist[input.getIndex(x, y)], 3);
                }
            }
        }
    } else if (rule == ConnectRule.EIGHT) {
        for (int y = 0; y < input.height; y++) {
            for (int x = 0; x < input.width; x++) {
                if (x >= 1 && x < input.width - 1 && y >= 1 && y < input.height - 1)
                    assertEquals(hist[input.getIndex(x, y)], 8);
                else if (x == 0 && y == 0)
                    assertEquals(hist[input.getIndex(x, y)], 3);
                else if (x == input.width - 1 && y == 0)
                    assertEquals(hist[input.getIndex(x, y)], 3);
                else if (x == input.width - 1 && y == input.height - 1)
                    assertEquals(hist[input.getIndex(x, y)], 3);
                else if (x == 0 && y == input.height - 1)
                    assertEquals(hist[input.getIndex(x, y)], 3);
                else {
                    assertEquals(hist[input.getIndex(x, y)], 5);
                }
            }
        }
    } else {
        throw new RuntimeException("Unknown rule");
    }
}
Also used : FastQueue(org.ddogleg.struct.FastQueue) Edge(boofcv.alg.segmentation.fh04.SegmentFelzenszwalbHuttenlocher04.Edge) Test(org.junit.Test)

Example 13 with FastQueue

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

the class FactoryMultiView method computePnP_1.

/**
 * Created an estimator for the P3P problem that selects a single solution by considering additional
 * observations.
 *
 * <p>NOTE: Observations are in normalized image coordinates NOT pixels.</p>
 *
 * <p>
 * NOTE: EPnP has several tuning parameters and the defaults here might not be the best for your situation.
 * Use {@link #computePnPwithEPnP} if you wish to have access to all parameters.
 * </p>
 *
 * @param which The algorithm which is to be returned.
 * @param numIterations Number of iterations. Only used by some algorithms and recommended number varies
 *                      significantly by algorithm.
 * @param numTest How many additional sample points are used to remove ambiguity in the solutions.  Not used
 *                if only a single solution is found.
 * @return An estimator which returns a single estimate.
 */
public static Estimate1ofPnP computePnP_1(EnumPNP which, int numIterations, int numTest) {
    if (which == EnumPNP.EPNP) {
        PnPLepetitEPnP alg = new PnPLepetitEPnP(0.1);
        alg.setNumIterations(numIterations);
        return new WrapPnPLepetitEPnP(alg);
    }
    FastQueue<Se3_F64> solutions = new FastQueue<>(4, Se3_F64.class, true);
    return new EstimateNto1ofPnP(computePnP_N(which, -1), solutions, numTest);
}
Also used : PnPLepetitEPnP(boofcv.alg.geo.pose.PnPLepetitEPnP) FastQueue(org.ddogleg.struct.FastQueue) Se3_F64(georegression.struct.se.Se3_F64)

Example 14 with FastQueue

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

the class TestVisualDepthOps method depthTo3D_with_rgb.

@Test
public void depthTo3D_with_rgb() {
    GrayU16 depth = new GrayU16(width, height);
    depth.set(200, 80, 3400);
    depth.set(600, 420, 50);
    Planar<GrayU8> rgb = new Planar<>(GrayU8.class, width, height, 3);
    GImageMiscOps.fillUniform(rgb, rand, 0, 200);
    FastQueue<Point3D_F64> pts = new FastQueue<>(Point3D_F64.class, true);
    FastQueueArray_I32 color = new FastQueueArray_I32(3);
    VisualDepthOps.depthTo3D(param, rgb, depth, pts, color);
    assertEquals(2, pts.size());
    assertEquals(2, color.size());
    assertEquals(0, compute(200, 80, 3400).distance(pts.get(0)), 1e-8);
    assertEquals(0, compute(600, 420, 50).distance(pts.get(1)), 1e-8);
    color(200, 80, rgb, color.get(0));
    color(600, 420, rgb, color.get(1));
}
Also used : Point3D_F64(georegression.struct.point.Point3D_F64) GrayU16(boofcv.struct.image.GrayU16) FastQueue(org.ddogleg.struct.FastQueue) Planar(boofcv.struct.image.Planar) GrayU8(boofcv.struct.image.GrayU8) FastQueueArray_I32(boofcv.struct.FastQueueArray_I32) Test(org.junit.Test)

Example 15 with FastQueue

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

the class TestAssociateSurfBasic method basicAssociation.

@Test
public void basicAssociation() {
    FastQueue<BrightFeature> src = new FastQueue<>(10, BrightFeature.class, false);
    FastQueue<BrightFeature> dst = new FastQueue<>(10, BrightFeature.class, false);
    // create a list where some should be matched and others not
    src.add(createDesc(true, 10));
    src.add(createDesc(true, 12));
    src.add(createDesc(false, 5));
    src.add(createDesc(false, 2344));
    src.add(createDesc(false, 1000));
    dst.add(createDesc(true, 0));
    dst.add(createDesc(true, 10.1));
    dst.add(createDesc(true, 13));
    dst.add(createDesc(false, 0.1));
    dst.add(createDesc(false, 7));
    alg.setSrc(src);
    alg.setDst(dst);
    alg.associate();
    FastQueue<AssociatedIndex> matches = alg.getMatches();
    assertEquals(3, matches.size());
    assertTrue(matches.get(0).fitScore != 0);
    assertEquals(0, matches.get(0).src);
    assertEquals(1, matches.get(0).dst);
    assertTrue(matches.get(1).fitScore != 0);
    assertEquals(1, matches.get(1).src);
    assertEquals(2, matches.get(1).dst);
    assertTrue(matches.get(2).fitScore != 0);
    assertEquals(2, matches.get(2).src);
    assertEquals(4, matches.get(2).dst);
    // see if the expected number of features are in the unassociated list
    GrowQueue_I32 unassoc = alg.unassociatedSrc;
    assertEquals(2, unassoc.size);
    // make sure none of the unassociated are contained in the associated list
    for (int i = 0; i < unassoc.size; i++) {
        int index = unassoc.data[i];
        for (int j = 0; j < matches.size(); j++) {
            if (matches.get(j).src == index)
                fail("match found");
        }
    }
}
Also used : BrightFeature(boofcv.struct.feature.BrightFeature) FastQueue(org.ddogleg.struct.FastQueue) AssociatedIndex(boofcv.struct.feature.AssociatedIndex) GrowQueue_I32(org.ddogleg.struct.GrowQueue_I32) Test(org.junit.Test)

Aggregations

FastQueue (org.ddogleg.struct.FastQueue)27 Test (org.junit.Test)17 Point3D_F64 (georegression.struct.point.Point3D_F64)9 GrayU16 (boofcv.struct.image.GrayU16)5 GrayU8 (boofcv.struct.image.GrayU8)5 GrowQueue_I32 (org.ddogleg.struct.GrowQueue_I32)5 ConvertBufferedImage (boofcv.io.image.ConvertBufferedImage)4 FastQueueArray_I32 (boofcv.struct.FastQueueArray_I32)4 Point2D_F64 (georegression.struct.point.Point2D_F64)4 Point2D_I32 (georegression.struct.point.Point2D_I32)4 BufferedImage (java.awt.image.BufferedImage)4 ArrayList (java.util.ArrayList)4 DMatrixRMaj (org.ejml.data.DMatrixRMaj)4 BrightFeature (boofcv.struct.feature.BrightFeature)3 GrayS32 (boofcv.struct.image.GrayS32)3 File (java.io.File)3 DetectDescribePoint (boofcv.abst.feature.detdesc.DetectDescribePoint)2 Edge (boofcv.alg.segmentation.fh04.SegmentFelzenszwalbHuttenlocher04.Edge)2 PointCloudViewer (boofcv.gui.d3.PointCloudViewer)2 CameraPinholeRadial (boofcv.struct.calib.CameraPinholeRadial)2