use of georegression.struct.shapes.Polygon2D_F64 in project BoofCV by lessthanoptimal.
the class CommonFitPolygonChecks method renderDistortedRectangles.
public void renderDistortedRectangles(boolean blackShape, Class imageType) {
orig = GeneralizedImageOps.createSingleBand(imageType, width, height);
image = GeneralizedImageOps.createSingleBand(imageType, width, height);
int white = blackShape ? this.white : this.black;
int black = blackShape ? this.black : this.white;
GImageMiscOps.fill(orig, white);
GImageMiscOps.fill(image, white);
distorted.clear();
for (Rectangle2D_I32 q : rectangles) {
if (fittingToBinaryImage)
GImageMiscOps.fillRectangle(orig, black, q.x0, q.y0, q.x1 - q.x0 + 1, q.y1 - q.y0 + 1);
else
GImageMiscOps.fillRectangle(orig, black, q.x0, q.y0, q.x1 - q.x0, q.y1 - q.y0);
Polygon2D_F64 tran = new Polygon2D_F64(4);
AffinePointOps_F64.transform(transform, q.x0, q.y0, tran.get(0));
AffinePointOps_F64.transform(transform, q.x0, q.y1, tran.get(1));
AffinePointOps_F64.transform(transform, q.x1, q.y1, tran.get(2));
AffinePointOps_F64.transform(transform, q.x1, q.y0, tran.get(3));
distorted.add(tran);
}
new FDistort(orig, image).border(white).affine(transform).apply();
if (showRendered) {
ListDisplayPanel panel = new ListDisplayPanel();
panel.addImage(orig, "Original");
panel.addImage(image, "Image");
ShowImages.showWindow(panel, "Rendered");
try {
Thread.sleep(4000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
use of georegression.struct.shapes.Polygon2D_F64 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 georegression.struct.shapes.Polygon2D_F64 in project BoofCV by lessthanoptimal.
the class TestDetectPolygonBinaryGrayRefine method checkSolutions.
private void checkSolutions(double tolerance, List<DetectPolygonFromContour.Info> found) {
for (int i = 0; i < found.size(); i++) {
Polygon2D_F64 p = found.get(i).polygon;
assertEquals(1, findMatches(p, tolerance));
assertEquals(black, found.get(i).edgeInside, 4);
assertEquals(white, found.get(i).edgeOutside, white * 0.1);
}
}
use of georegression.struct.shapes.Polygon2D_F64 in project BoofCV by lessthanoptimal.
the class TestEdgeIntensityPolygon method checkIntensity.
@Test
public void checkIntensity() {
GrayU8 image = new GrayU8(400, 500);
int value = 200;
ImageMiscOps.fillRectangle(image, value, 20, 30, 40, 40);
EdgeIntensityPolygon<GrayU8> alg = new EdgeIntensityPolygon<>(2, 2, 10, GrayU8.class);
Polygon2D_F64 polygon = new Polygon2D_F64(4);
UtilPolygons2D_F64.convert(new Rectangle2D_F64(20, 30, 60, 70), polygon);
alg.setImage(image);
assertTrue(alg.computeEdge(polygon, polygon.isCCW()));
assertTrue(alg.checkIntensity(false, 50));
assertFalse(alg.checkIntensity(true, 50));
}
use of georegression.struct.shapes.Polygon2D_F64 in project BoofCV by lessthanoptimal.
the class AssistedCalibration method renderFillPolygons.
private void renderFillPolygons() {
if (regions.size() == 0)
return;
g2.setColor(new Color(0, 255, 255, 50));
int N = regions.get(0).size();
int[] polyX = new int[N];
int[] polyY = new int[N];
for (int i = 0; i < regions.size(); i++) {
Polygon2D_F64 poly = regions.get(i);
for (int j = 0; j < poly.size(); j++) {
Point2D_F64 p = poly.get(j);
polyX[j] = (int) (p.x + 0.5);
polyY[j] = (int) (p.y + 0.5);
}
g2.fillPolygon(polyX, polyY, poly.size());
}
}
Aggregations