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;
}
}
}
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);
}
}
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) {}
}
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);
}
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);
}
Aggregations