use of georegression.struct.shapes.Polygon2D_F64 in project BoofCV by lessthanoptimal.
the class TestDetectPolygonFromContour method determineCornersOnBorder.
@Test
public void determineCornersOnBorder() {
DetectPolygonFromContour alg = createDetector(GrayU8.class, 4, 4);
alg.getLabeled().reshape(width, height);
Polygon2D_F64 poly = new Polygon2D_F64(0, 0, 10, 0, 10, 10, 0, 10);
GrowQueue_B corners = new GrowQueue_B();
alg.determineCornersOnBorder(poly, corners);
assertEquals(4, corners.size());
assertEquals(true, corners.get(0));
assertEquals(true, corners.get(1));
assertEquals(false, corners.get(2));
assertEquals(true, corners.get(3));
}
use of georegression.struct.shapes.Polygon2D_F64 in project BoofCV by lessthanoptimal.
the class TestDetectPolygonFromContour method rejectShapes_triangle.
@Test
public void rejectShapes_triangle() {
BufferedImage work = new BufferedImage(200, 220, BufferedImage.TYPE_INT_RGB);
Graphics2D g2 = work.createGraphics();
g2.setColor(Color.WHITE);
g2.fillRect(0, 0, 200, 220);
g2.setColor(Color.BLACK);
g2.fillPolygon(new int[] { 10, 50, 30 }, new int[] { 10, 10, 40 }, 3);
GrayU8 gray = ConvertBufferedImage.convertFrom(work, (GrayU8) null);
binary.reshape(gray.width, gray.height);
inputToBinary_U8.process(gray, binary);
for (int i = 3; i <= 6; i++) {
DetectPolygonFromContour<GrayU8> alg = createDetector(GrayU8.class, i, i);
alg.process(gray, binary);
if (i == 3) {
assertEquals(1, alg.getFound().size());
Polygon2D_F64 found = alg.getFound().get(0).polygon;
checkPolygon(new double[] { 10, 10, 30, 40, 50, 10 }, found);
} else
assertEquals(0, alg.getFound().size());
}
}
use of georegression.struct.shapes.Polygon2D_F64 in project BoofCV by lessthanoptimal.
the class TestDetectPolygonFromContour method easyTestMultipleShapes.
@Test
public void easyTestMultipleShapes() {
List<Polygon2D_F64> polygons = new ArrayList<>();
polygons.add(new Polygon2D_F64(20, 20, 40, 50, 80, 20));
polygons.add(new Polygon2D_F64(20, 60, 20, 90, 40, 90, 40, 60));
for (Class imageType : imageTypes) {
checkDetectedMulti(imageType, polygons, 2.5);
}
}
use of georegression.struct.shapes.Polygon2D_F64 in project BoofCV by lessthanoptimal.
the class TestRefinePolygonToGrayLine method alignedSquare.
/**
* Fit a square which is alligned to the image axis. It should get a nearly perfect fit.
* Initial conditions are be a bit off.
*/
@Test
public void alignedSquare() {
rectangles.add(new Rectangle2D_I32(x0, y0, x1, y1));
Polygon2D_F64 original = new Polygon2D_F64(x0, y0, x0, y1, x1, y1, x1, y0);
for (Class imageType : imageTypes) {
for (int i = 0; i < 2; i++) {
boolean black = i == 0;
renderDistortedRectangles(black, imageType);
RefinePolygonToGrayLine alg = createAlg(original.size(), imageType);
for (int j = 0; j < 20; j++) {
Polygon2D_F64 input = original.copy();
addNoise(input, 2);
Polygon2D_F64 output = new Polygon2D_F64(original.size());
alg.setImage(image);
assertTrue(alg.refine(input, output));
assertTrue(original.isIdentical(output, 0.01));
}
}
}
}
use of georegression.struct.shapes.Polygon2D_F64 in project BoofCV by lessthanoptimal.
the class TestRefinePolygonToGrayLine method fit_noisy_affine.
public void fit_noisy_affine(boolean black, Affine2D_F64 affine, Class imageType) {
this.transform.set(affine);
renderDistortedRectangles(black, imageType);
RefinePolygonToGrayLine alg = createAlg(4, imageType);
Polygon2D_F64 input = createFromSquare(affine);
Polygon2D_F64 expected = input.copy();
Polygon2D_F64 found = new Polygon2D_F64(4);
for (int i = 0; i < 10; i++) {
// add some noise
input.set(expected);
addNoise(input, 2);
alg.setImage(image);
assertTrue(alg.refine(input, found));
// should be close to the expected
double before = computeMaxDistance(input, expected);
double after = computeMaxDistance(found, expected);
assertTrue(after < before);
assertTrue(expected.isIdentical(found, 0.5));
// ----- Reverse the order and it should still work
input.flip();
assertTrue(alg.refine(input, found));
found.flip();
after = computeMaxDistance(found, expected);
assertTrue(after < before);
assertTrue(expected.isIdentical(found, 0.5));
}
}
Aggregations