use of georegression.struct.shapes.Polygon2D_F64 in project BoofCV by lessthanoptimal.
the class TestRefinePolygonToGrayLine method fitWithEdgeOnBorder.
/**
* See if it handles lines along the image border correctly
*/
@Test
public void fitWithEdgeOnBorder() {
x0 = 0;
x1 = 100;
y0 = 100;
y1 = 200;
rectangles.add(new Rectangle2D_I32(x0, y0, x1, y1));
for (Class imageType : imageTypes) {
renderDistortedRectangles(true, imageType);
RefinePolygonToGrayLine alg = createAlg(4, imageType);
Polygon2D_F64 input = createFromSquare(null);
input.get(0).set(x0, y0 + 1.1);
input.get(1).set(x0, y1 - 1.1);
Polygon2D_F64 found = new Polygon2D_F64(4);
alg.setImage(image);
assertTrue(alg.refine(input, found));
Polygon2D_F64 expected = createFromSquare(null);
assertTrue(expected.isIdentical(found, 0.01));
}
}
use of georegression.struct.shapes.Polygon2D_F64 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.shapes.Polygon2D_F64 in project BoofCV by lessthanoptimal.
the class TestUtilShapePolygon method convert.
@Test
public void convert() {
Polygon2D_F64 orig = new Polygon2D_F64(10, 20, 30, 21, 19.5, -10, 8, -8);
LineGeneral2D_F64[] lines = new LineGeneral2D_F64[4];
lines[0] = UtilLine2D_F64.convert(orig.getLine(0, null), (LineGeneral2D_F64) null);
lines[1] = UtilLine2D_F64.convert(orig.getLine(1, null), (LineGeneral2D_F64) null);
lines[2] = UtilLine2D_F64.convert(orig.getLine(2, null), (LineGeneral2D_F64) null);
lines[3] = UtilLine2D_F64.convert(orig.getLine(3, null), (LineGeneral2D_F64) null);
Polygon2D_F64 found = new Polygon2D_F64(4);
assertTrue(UtilShapePolygon.convert(lines, found));
assertTrue(orig.isIdentical(found, 1e-8));
}
use of georegression.struct.shapes.Polygon2D_F64 in project BoofCV by lessthanoptimal.
the class TestSnapToLineEdge method fit_noisy_affine.
public void fit_noisy_affine(Affine2D_F64 affine, Class imageType) {
setup(affine, imageType);
double tol = 0.5;
SnapToLineEdge alg = new SnapToLineEdge(10, 2, imageType);
Polygon2D_F64 input = new Polygon2D_F64(4);
AffinePointOps_F64.transform(affine, new Point2D_F64(x0, y0), input.get(0));
AffinePointOps_F64.transform(affine, new Point2D_F64(x0, y1), input.get(1));
AffinePointOps_F64.transform(affine, new Point2D_F64(x1, y1), input.get(2));
AffinePointOps_F64.transform(affine, new Point2D_F64(x1, y0), input.get(3));
LineGeneral2D_F64[] found = new LineGeneral2D_F64[input.size()];
for (int i = 0; i < found.length; i++) {
found[i] = new LineGeneral2D_F64();
}
for (int i = 0; i < 10; i++) {
// add some noise
Polygon2D_F64 noisy = input.copy();
addNoise(noisy, 2);
alg.setImage(image);
for (int j = 0; j < noisy.size(); j++) {
LineSegment2D_F64 edge = noisy.getLine(j, null);
double slopeX = edge.slopeX();
double slopeY = edge.slopeY();
double r = Math.sqrt(slopeX * slopeX + slopeY * slopeY);
slopeX /= r;
slopeY /= r;
// shrink it slightly to avoid weirdness along the corner
edge.a.x += 2 * slopeX;
edge.a.y += 2 * slopeY;
edge.b.x -= 2 * slopeX;
edge.b.y -= 2 * slopeY;
// optimize it a few times to get a good solution
for (int k = 0; k < 5; k++) {
assertTrue(alg.refine(edge.a, edge.b, found[j]));
edge.a.set(ClosestPoint2D_F64.closestPoint(found[j], edge.a, null));
edge.b.set(ClosestPoint2D_F64.closestPoint(found[j], edge.b, null));
}
}
// compute the corners and see how it did
for (int j = 0; j < input.size(); j++) {
int k = (j + 1) % input.size();
Point2D_F64 c = new Point2D_F64();
Intersection2D_F64.intersection(found[j], found[k], c);
double d = c.distance(input.get(k));
assertTrue(d <= tol);
}
}
}
use of georegression.struct.shapes.Polygon2D_F64 in project BoofCV by lessthanoptimal.
the class CommonFitPolygonChecks method findMatchesOriginal.
/**
* Compare found rectangle against rectangles in the original undistorted image
*/
protected int findMatchesOriginal(Polygon2D_F64 found, double tol) {
int match = 0;
for (int i = 0; i < rectangles.size(); i++) {
Rectangle2D_I32 ri = rectangles.get(i);
Rectangle2D_F64 r = new Rectangle2D_F64(ri.x0, ri.y0, ri.x1, ri.y1);
Polygon2D_F64 p = new Polygon2D_F64(4);
UtilPolygons2D_F64.convert(r, p);
if (p.isCCW())
p.flip();
if (UtilPolygons2D_F64.isEquivalent(found, p, tol))
match++;
}
return match;
}
Aggregations