use of boofcv.struct.distort.PixelTransform2_F32 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.distort.PixelTransform2_F32 in project BoofCV by lessthanoptimal.
the class TestBinaryEllipseDetector method distortedImage.
/**
* Input image is distorted
*/
@Test
public void distortedImage() {
List<EllipseRotated_F64> original = new ArrayList<>();
original.add(new EllipseRotated_F64(50, 65, 20, 10, 0.5));
original.add(new EllipseRotated_F64(90, 100, 25, 25, 0));
GrayU8 image = TestBinaryEllipseDetectorPixel.renderEllipses_F64(200, 210, original, 0);
GrayU8 binary = image.createSameShape();
ThresholdImageOps.threshold(image, binary, 30, true);
BinaryEllipseDetector<GrayU8> alg = create();
PixelTransform2_F32 distToUndist = new PixelTransformAffine_F32(new Affine2D_F32(1, 0, 0, 1, 5, 8));
PixelTransform2_F32 undistToDist = new PixelTransformAffine_F32(new Affine2D_F32(1, 0, 0, 1, -5, -8));
alg.setLensDistortion(distToUndist, undistToDist);
alg.process(image, binary);
// adjust the ellipses using the transform
List<EllipseRotated_F64> expected = new ArrayList<>();
for (EllipseRotated_F64 o : original) {
EllipseRotated_F64 e = new EllipseRotated_F64(o);
e.center.x += 5;
e.center.y += 8;
expected.add(e);
}
List<EllipseRotated_F64> found = alg.getFoundEllipses(null);
TestBinaryEllipseDetectorPixel.checkEquals_F64(expected, found, 1.0, 0.1);
}
use of boofcv.struct.distort.PixelTransform2_F32 in project BoofCV by lessthanoptimal.
the class TestDetectPolygonBinaryGrayRefine method checkDetected_LensDistortion.
private void checkDetected_LensDistortion(Class imageType, double tol) {
renderDistortedRectangles(true, imageType);
Affine2D_F32 a = new Affine2D_F32();
UtilAffine.convert(transform, a);
PixelTransform2_F32 tranFrom = new PixelTransformAffine_F32(a);
PixelTransform2_F32 tranTo = new PixelTransformAffine_F32(a.invert(null));
int numberOfSides = 4;
DetectPolygonBinaryGrayRefine alg = createAlg(imageType, numberOfSides, numberOfSides);
alg.setLensDistortion(image.width, image.height, tranTo, tranFrom);
alg.process(image, binary);
List<DetectPolygonFromContour.Info> found = alg.getPolygonInfo();
assertEquals(rectangles.size(), found.size());
for (int i = 0; i < found.size(); i++) {
Polygon2D_F64 p = found.get(i).polygon;
assertEquals(1, findMatchesOriginal(p, tol));
assertEquals(black, found.get(i).edgeInside, 3);
assertEquals(white, found.get(i).edgeOutside, white * 0.05);
}
// ----------- see if distortion is cleared properly
alg.clearLensDistortion();
alg.process(image, binary);
found = alg.getPolygonInfo();
assertEquals(rectangles.size(), found.size());
// nothing should match now
for (int i = 0; i < found.size(); i++) {
Polygon2D_F64 p = found.get(i).polygon;
assertEquals(0, findMatchesOriginal(p, tol));
}
}
use of boofcv.struct.distort.PixelTransform2_F32 in project BoofCV by lessthanoptimal.
the class TestFDistort method setBorderChange.
/**
* Makes sure that border recycling doesn't mess things up
*/
@Test
public void setBorderChange() {
ImageMiscOps.fillUniform(input, rand, 0, 200);
GrayU8 found = new GrayU8(width / 2, height / 2);
GrayU8 expected = new GrayU8(width / 2, height / 2);
FDistort alg = new FDistort();
alg.init(input, found).scaleExt().apply();
ImageDistort distorter = alg.distorter;
InterpolatePixel interp = alg.interp;
;
PixelTransform2_F32 outputToInput = alg.outputToInput;
// Set it to the default border, nothing should change
expected.setTo(found);
alg.border(BorderType.EXTENDED).apply();
assertTrue(distorter == alg.distorter);
assertTrue(interp == alg.interp);
assertTrue(outputToInput == alg.outputToInput);
BoofTesting.assertEquals(expected, found, 1e-4);
// change border now a fixed value
alg.border(10).apply();
new FDistort(input, expected).scale().border(10).apply();
BoofTesting.assertEquals(expected, found, 1e-4);
// change value
alg.border(1).apply();
new FDistort(input, expected).scale().border(1).apply();
BoofTesting.assertEquals(expected, found, 1e-4);
}
use of boofcv.struct.distort.PixelTransform2_F32 in project BoofCV by lessthanoptimal.
the class TestFDistort method affine.
@Test
public void affine() {
ImageMiscOps.fillUniform(input, rand, 0, 200);
Affine2D_F32 affine = new Affine2D_F32(2, 0.1f, -0.2f, 1.1f, 3, 4.5f);
PixelTransform2_F32 transform = new PixelTransformAffine_F32(affine.invert(null));
new FDistort(input, output).affine(2, 0.1f, -0.2f, 1.1f, 3, 4.5f).borderExt().apply();
InterpolatePixelS<GrayU8> interp = FactoryInterpolation.bilinearPixelS(input, null);
interp.setBorder(FactoryImageBorderAlgs.extend(input));
interp.setImage(input);
if (input.getDataType().isInteger()) {
for (int y = 0; y < output.height; y++) {
for (int x = 0; x < output.width; x++) {
transform.compute(x, y);
float val = interp.get(transform.distX, transform.distY);
assertEquals((int) val, output.get(x, y), 1e-4);
}
}
} else {
for (int y = 0; y < output.height; y++) {
for (int x = 0; x < output.width; x++) {
transform.compute(x, y);
float val = interp.get(transform.distX, transform.distY);
assertEquals(val, output.get(x, y), 1e-4);
}
}
}
}
Aggregations