use of georegression.struct.affine.Affine2D_F32 in project BoofCV by lessthanoptimal.
the class FDistort method affine.
/**
* Affine transform from input to output
*/
public FDistort affine(double a11, double a12, double a21, double a22, double dx, double dy) {
PixelTransformAffine_F32 transform;
if (outputToInput != null && outputToInput instanceof PixelTransformAffine_F32) {
transform = (PixelTransformAffine_F32) outputToInput;
} else {
transform = new PixelTransformAffine_F32();
}
Affine2D_F32 m = new Affine2D_F32();
m.a11 = (float) a11;
m.a12 = (float) a12;
m.a21 = (float) a21;
m.a22 = (float) a22;
m.tx = (float) dx;
m.ty = (float) dy;
m.invert(transform.getModel());
return transform(transform);
}
use of georegression.struct.affine.Affine2D_F32 in project BoofCV by lessthanoptimal.
the class TestRefinePolygonToGrayLine method fit_perfect_transform.
public void fit_perfect_transform(boolean black, Affine2D_F64 regToDist, Class imageType) {
this.transform.set(regToDist);
renderDistortedRectangles(black, imageType);
RefinePolygonToGrayLine alg = createAlg(4, imageType);
Polygon2D_F64 input = createFromSquare(null);
Polygon2D_F64 expected = input.copy();
Polygon2D_F64 found = new Polygon2D_F64(4);
alg.setImage(image);
// fail without the transform
assertFalse(alg.refine(input, found));
// work when the transform is applied
PixelTransformAffine_F32 transform = new PixelTransformAffine_F32();
Affine2D_F32 regToDist_F32 = new Affine2D_F32();
ConvertFloatType.convert(regToDist, regToDist_F32);
transform.set(regToDist_F32);
alg.setTransform(transform);
alg.setImage(image);
assertTrue(alg.refine(input, found));
// should be close to the expected
assertTrue(expected.isIdentical(found, 0.3));
}
use of georegression.struct.affine.Affine2D_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 georegression.struct.affine.Affine2D_F32 in project BoofCV by lessthanoptimal.
the class TestBinaryEllipseDetectorPixel method undistortContour_WithDistortion.
/**
* Undistort the image when distortion model is provided
*/
@Test
public void undistortContour_WithDistortion() {
List<Point2D_I32> input = new ArrayList<>();
FastQueue<Point2D_F64> output = new FastQueue<>(Point2D_F64.class, true);
for (int i = 0; i < 10; i++) {
input.add(new Point2D_I32(i, i));
}
BinaryEllipseDetectorPixel alg = new BinaryEllipseDetectorPixel();
alg.setLensDistortion(new PixelTransformAffine_F32(new Affine2D_F32(1, 0, 0, 1, 10.0f, 0)));
alg.undistortContour(input, output);
assertEquals(input.size(), output.size);
for (int i = 0; i < input.size(); i++) {
Point2D_I32 p = input.get(i);
assertEquals(p.x + 10, output.get(i).x, 1e-8);
assertEquals(p.y, output.get(i).y, 1e-8);
}
}
use of georegression.struct.affine.Affine2D_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));
}
}
Aggregations