Search in sources :

Example 31 with AssociatedPair

use of boofcv.struct.geo.AssociatedPair in project BoofCV by lessthanoptimal.

the class QrCodeBinaryGridToPixel method computeTransform.

public void computeTransform() {
    generator.generate(pairs, H);
    H.invert(Hinv);
    ConvertFloatType.convert(Hinv, Hinv32);
    ConvertFloatType.convert(H, H32);
    adjustments.reset();
    if (adjustWithFeatures) {
        for (int i = 0; i < pairs.size(); i++) {
            AssociatedPair p = pairs.get(i);
            Point2D_F64 a = adjustments.grow();
            HomographyPointOps_F64.transform(Hinv, p.p2.x, p.p2.y, tmp64);
            a.x = p.p1.x - tmp64.x;
            a.y = p.p1.y - tmp64.y;
        }
    }
}
Also used : AssociatedPair(boofcv.struct.geo.AssociatedPair) Point2D_F64(georegression.struct.point.Point2D_F64)

Example 32 with AssociatedPair

use of boofcv.struct.geo.AssociatedPair in project BoofCV by lessthanoptimal.

the class QrCodeBinaryGridToPixel method addAllFeatures.

public void addAllFeatures(QrCode qr) {
    adjustWithFeatures = false;
    storagePairs.reset();
    pairs.clear();
    int N = qr.getNumberOfModules();
    // outside corner
    set(0, 0, qr.ppCorner, 0);
    set(0, 7, qr.ppCorner, 1);
    set(7, 7, qr.ppCorner, 2);
    set(7, 0, qr.ppCorner, 3);
    set(0, N - 7, qr.ppRight, 0);
    // outside corner
    set(0, N, qr.ppRight, 1);
    set(7, N, qr.ppRight, 2);
    set(7, N - 7, qr.ppRight, 3);
    set(N - 7, 0, qr.ppDown, 0);
    set(N - 7, 7, qr.ppDown, 1);
    set(N, 7, qr.ppDown, 2);
    // outside corner
    set(N, 0, qr.ppDown, 3);
    for (int i = 0; i < qr.alignment.size; i++) {
        QrCode.Alignment a = qr.alignment.get(i);
        AssociatedPair p = storagePairs.grow();
        p.set(a.pixel.x, a.pixel.y, a.moduleX + 0.5f, a.moduleY + 0.5f);
        pairs.add(p);
    }
}
Also used : AssociatedPair(boofcv.struct.geo.AssociatedPair)

Example 33 with AssociatedPair

use of boofcv.struct.geo.AssociatedPair in project BoofCV by lessthanoptimal.

the class TestBaseDetectFiducialSquare method render.

/**
 * Draws a distorted pattern onto the output
 */
public static void render(GrayU8 pattern, Quadrilateral_F64 where, GrayU8 output) {
    int w = pattern.width;
    int h = pattern.height;
    ArrayList<AssociatedPair> associatedPairs = new ArrayList<>();
    associatedPairs.add(new AssociatedPair(where.a, new Point2D_F64(0, 0)));
    associatedPairs.add(new AssociatedPair(where.b, new Point2D_F64(w, 0)));
    associatedPairs.add(new AssociatedPair(where.c, new Point2D_F64(w, h)));
    associatedPairs.add(new AssociatedPair(where.d, new Point2D_F64(0, h)));
    Estimate1ofEpipolar computeHomography = FactoryMultiView.computeHomographyDLT(true);
    DMatrixRMaj H = new DMatrixRMaj(3, 3);
    computeHomography.process(associatedPairs, H);
    // Create the transform for distorting the image
    FMatrixRMaj H32 = new FMatrixRMaj(3, 3);
    ConvertMatrixData.convert(H, H32);
    PointTransformHomography_F32 homography = new PointTransformHomography_F32(H32);
    PixelTransform2_F32 pixelTransform = new PointToPixelTransform_F32(homography);
    // Apply distortion and show the results
    DistortImageOps.distortSingle(pattern, output, pixelTransform, InterpolationType.BILINEAR, BorderType.SKIP);
// ShowImages.showWindow(output, "Rendered");
// try {Thread.sleep(10000);} catch (InterruptedException e) {}
}
Also used : AssociatedPair(boofcv.struct.geo.AssociatedPair) FMatrixRMaj(org.ejml.data.FMatrixRMaj) Point2D_F64(georegression.struct.point.Point2D_F64) Estimate1ofEpipolar(boofcv.abst.geo.Estimate1ofEpipolar) ArrayList(java.util.ArrayList) DMatrixRMaj(org.ejml.data.DMatrixRMaj) PixelTransform2_F32(boofcv.struct.distort.PixelTransform2_F32)

Example 34 with AssociatedPair

use of boofcv.struct.geo.AssociatedPair in project BoofCV by lessthanoptimal.

the class TestTldAdjustRegion method process.

@Test
public void process() {
    ScaleTranslate2D motion = new ScaleTranslate2D(1.5, 2, 3);
    FastQueue<AssociatedPair> pairs = new FastQueue<>(AssociatedPair.class, true);
    for (int i = 0; i < 200; i++) {
        AssociatedPair p = pairs.grow();
        p.p1.x = rand.nextGaussian() * 2;
        p.p1.y = rand.nextGaussian() * 2;
        p.p2.x = p.p1.x * motion.scale + motion.transX;
        p.p2.y = p.p1.y * motion.scale + motion.transY;
    }
    Rectangle2D_F64 rect = new Rectangle2D_F64(10, 20, 30, 40);
    TldAdjustRegion alg = new TldAdjustRegion(30);
    alg.init(300, 400);
    assertTrue(alg.process(pairs, rect));
    assertEquals(17, rect.p0.x, 1e-8);
    assertEquals(33, rect.p0.y, 1e-8);
    assertEquals(47, rect.p1.x, 1e-8);
    assertEquals(63, rect.p1.y, 1e-8);
}
Also used : AssociatedPair(boofcv.struct.geo.AssociatedPair) Rectangle2D_F64(georegression.struct.shapes.Rectangle2D_F64) FastQueue(org.ddogleg.struct.FastQueue) ScaleTranslate2D(boofcv.struct.sfm.ScaleTranslate2D) Test(org.junit.Test)

Example 35 with AssociatedPair

use of boofcv.struct.geo.AssociatedPair in project BoofCV by lessthanoptimal.

the class ExampleImageStitching method stitch.

/**
 * Given two input images create and display an image where the two have been overlayed on top of each other.
 */
public static <T extends ImageGray<T>> void stitch(BufferedImage imageA, BufferedImage imageB, Class<T> imageType) {
    T inputA = ConvertBufferedImage.convertFromSingle(imageA, null, imageType);
    T inputB = ConvertBufferedImage.convertFromSingle(imageB, null, imageType);
    // Detect using the standard SURF feature descriptor and describer
    DetectDescribePoint detDesc = FactoryDetectDescribe.surfStable(new ConfigFastHessian(1, 2, 200, 1, 9, 4, 4), null, null, imageType);
    ScoreAssociation<BrightFeature> scorer = FactoryAssociation.scoreEuclidean(BrightFeature.class, true);
    AssociateDescription<BrightFeature> associate = FactoryAssociation.greedy(scorer, 2, true);
    // fit the images using a homography.  This works well for rotations and distant objects.
    ModelMatcher<Homography2D_F64, AssociatedPair> modelMatcher = FactoryMultiViewRobust.homographyRansac(null, new ConfigRansac(60, 3));
    Homography2D_F64 H = computeTransform(inputA, inputB, detDesc, associate, modelMatcher);
    renderStitching(imageA, imageB, H);
}
Also used : DetectDescribePoint(boofcv.abst.feature.detdesc.DetectDescribePoint) AssociatedPair(boofcv.struct.geo.AssociatedPair) BrightFeature(boofcv.struct.feature.BrightFeature) ConfigFastHessian(boofcv.abst.feature.detect.interest.ConfigFastHessian) ConfigRansac(boofcv.factory.geo.ConfigRansac) Homography2D_F64(georegression.struct.homography.Homography2D_F64)

Aggregations

AssociatedPair (boofcv.struct.geo.AssociatedPair)110 Test (org.junit.Test)32 Point2D_F64 (georegression.struct.point.Point2D_F64)28 ArrayList (java.util.ArrayList)27 DMatrixRMaj (org.ejml.data.DMatrixRMaj)22 Se3_F64 (georegression.struct.se.Se3_F64)17 Point3D_F64 (georegression.struct.point.Point3D_F64)12 ScaleTranslate2D (boofcv.struct.sfm.ScaleTranslate2D)7 DetectDescribePoint (boofcv.abst.feature.detdesc.DetectDescribePoint)6 Estimate1ofEpipolar (boofcv.abst.geo.Estimate1ofEpipolar)5 Point2Transform2_F64 (boofcv.struct.distort.Point2Transform2_F64)4 AssociatedIndex (boofcv.struct.feature.AssociatedIndex)4 ScaleTranslateRotate2D (boofcv.struct.sfm.ScaleTranslateRotate2D)4 ClosestPoint3D_F64 (georegression.metric.ClosestPoint3D_F64)4 ConfigFastHessian (boofcv.abst.feature.detect.interest.ConfigFastHessian)3 TriangulateTwoViewsCalibrated (boofcv.abst.geo.TriangulateTwoViewsCalibrated)3 AssociationPanel (boofcv.gui.feature.AssociationPanel)3 BrightFeature (boofcv.struct.feature.BrightFeature)3 Homography2D_F64 (georegression.struct.homography.Homography2D_F64)3 Ransac (org.ddogleg.fitting.modelset.ransac.Ransac)3