use of georegression.struct.shapes.Quadrilateral_F64 in project BoofCV by lessthanoptimal.
the class VisualizeSquareFiducial method process.
public void process(String nameImage, @Nullable String nameIntrinsic) {
CameraPinholeBrown intrinsic = nameIntrinsic == null ? null : (CameraPinholeBrown) CalibrationIO.load(nameIntrinsic);
GrayF32 input = Objects.requireNonNull(UtilImageIO.loadImage(nameImage, GrayF32.class));
GrayF32 undistorted = new GrayF32(input.width, input.height);
Detector detector = new Detector();
if (intrinsic != null) {
var paramUndist = new CameraPinholeBrown();
ImageDistort<GrayF32, GrayF32> undistorter = LensDistortionOps.changeCameraModel(AdjustmentType.EXPAND, BorderType.EXTENDED, intrinsic, new CameraPinhole(intrinsic), paramUndist, ImageType.single(GrayF32.class));
detector.configure(new LensDistortionBrown(paramUndist), paramUndist.width, paramUndist.height, false);
undistorter.apply(input, undistorted);
} else {
undistorted.setTo(input);
}
detector.process(undistorted);
System.out.println("Total Found: " + detector.squares.size());
DogArray<FoundFiducial> fiducials = detector.getFound();
int N = Math.min(20, detector.squares.size());
ListDisplayPanel squares = new ListDisplayPanel();
for (int i = 0; i < N; i++) {
squares.addImage(ConvertBufferedImage.convertTo(detector.squares.get(i), null), " " + i);
}
BufferedImage output = new BufferedImage(input.width, input.height, BufferedImage.TYPE_INT_RGB);
VisualizeBinaryData.renderBinary(detector.getBinary(), false, output);
Graphics2D g2 = output.createGraphics();
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g2.setColor(Color.RED);
g2.setStroke(new BasicStroke(2));
if (intrinsic != null) {
Point2Transform2_F64 add_p_to_p = LensDistortionFactory.narrow(intrinsic).distort_F64(true, true);
for (int i = 0; i < N; i++) {
// add back in lens distortion
Quadrilateral_F64 q = fiducials.get(i).distortedPixels;
apply(add_p_to_p, q.a, q.a);
apply(add_p_to_p, q.b, q.b);
apply(add_p_to_p, q.c, q.c);
apply(add_p_to_p, q.d, q.d);
VisualizeShapes.draw(q, g2);
}
}
BufferedImage outputGray = new BufferedImage(input.width, input.height, BufferedImage.TYPE_INT_RGB);
ConvertBufferedImage.convertTo(undistorted, outputGray);
g2 = outputGray.createGraphics();
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
for (int i = 0; i < N; i++) {
// add back in lens distortion
Quadrilateral_F64 q = fiducials.get(i).distortedPixels;
// g2.setStroke(new BasicStroke(2));
// VisualizeBinaryData.render(detector.getSquareDetector().getUsedContours(),Color.BLUE,outputGray);
VisualizeShapes.drawArrowSubPixel(q, 3, 1, g2);
}
ShowImages.showWindow(output, "Binary");
ShowImages.showWindow(outputGray, "Gray");
ShowImages.showWindow(squares, "Candidates");
}
use of georegression.struct.shapes.Quadrilateral_F64 in project BoofCV by lessthanoptimal.
the class TestStitchingFromMotion2D method getImageCorners.
@Test
void getImageCorners() {
HelperMotion motion = new HelperMotion();
HelperDistort distort = new HelperDistort();
StitchingTransform trans = FactoryStitchingTransform.createAffine_F64();
StitchingFromMotion2D<GrayF32, Affine2D_F64> alg = new StitchingFromMotion2D<>(motion, distort, trans, 0.3);
alg.configure(200, 300, null);
assertTrue(alg.process(image));
int w = 100, h = 150;
Quadrilateral_F64 corners = new Quadrilateral_F64();
alg.getImageCorners(w, h, corners);
assertEquals(-1, corners.a.x, 1e-5);
assertEquals(2, corners.a.y, 1e-5);
assertEquals(-1 + w, corners.b.x, 1e-5);
assertEquals(2, corners.b.y, 1e-5);
assertEquals(-1 + w, corners.c.x, 1e-5);
assertEquals(2 + h, corners.c.y, 1e-5);
assertEquals(-1, corners.d.x, 1e-5);
assertEquals(2 + h, corners.d.y, 1e-5);
}
use of georegression.struct.shapes.Quadrilateral_F64 in project BoofCV by lessthanoptimal.
the class Motion2DPanel method drawImageBounds.
private void drawImageBounds(Graphics2D g2, int tx, int ty, double scale) {
Quadrilateral_F64 c = corners;
Stroke originalStroke = g2.getStroke();
g2.setStroke(boundsStroke);
g2.setColor(Color.BLUE);
drawLine(g2, tx, ty, scale, c.a, c.b);
drawLine(g2, tx, ty, scale, c.b, c.c);
drawLine(g2, tx, ty, scale, c.c, c.d);
drawLine(g2, tx, ty, scale, c.d, c.a);
g2.setStroke(originalStroke);
}
use of georegression.struct.shapes.Quadrilateral_F64 in project BoofCV by lessthanoptimal.
the class TestDetectFiducialSquareGrid method simple.
/**
* Generate a fiducial and detect its corners. Fully visible.
*/
@Test
void simple() {
ConfigFiducialBinary configBinary = new ConfigFiducialBinary(1);
configBinary.gridWidth = 3;
long[] values = new long[] { 0, 1, 2, 3, 4, 5 };
BaseDetectFiducialSquare<GrayF32> detector = FactoryFiducial.squareBinary(configBinary, ConfigThreshold.fixed(125), GrayF32.class).getAlgorithm();
DetectFiducialSquareGrid<GrayF32> alg = new DetectFiducialSquareGrid<>(3, 2, values, detector);
RenderSquareBinaryGridFiducial render = new RenderSquareBinaryGridFiducial();
render.values = values;
GrayF32 image = render.generate(3, 2);
assertTrue(alg.detect(image));
List<DetectFiducialSquareGrid.Detection> detections = alg.detections.toList();
int[] foundIds = new int[6];
for (int i = 0; i < detections.size(); i++) {
DetectFiducialSquareGrid.Detection d = detections.get(i);
foundIds[d.gridIndex]++;
// see if the corners are in the right location. Order matters
Quadrilateral_F64 expected = render.expectedCorners.get(d.gridIndex);
Quadrilateral_F64 found = d.location;
for (int j = 0; j < 4; j++) {
assertTrue(expected.get(j).distance(found.get(j)) < 0.1);
}
}
// see if all the fiducials were found
for (int i = 0; i < foundIds.length; i++) {
assertEquals(1, foundIds[i]);
}
}
use of georegression.struct.shapes.Quadrilateral_F64 in project BoofCV by lessthanoptimal.
the class RenderSquareBinaryGridFiducial method generateSquare.
private void generateSquare(int x0, int y0, int width, int value, GrayF32 image) {
ImageMiscOps.fillRectangle(image, 0, x0, y0, width, width);
int innerWidth = (int) (width * (1.0 - border * 2) + 0.5);
int x1 = x0 + (width - innerWidth) / 2;
int y1 = y0 + (width - innerWidth) / 2;
expectedCorners.add(new Quadrilateral_F64(x0, y0, x0 + width, y0, x0 + width, y0 + width, x0, y0 + width));
int bit = 0;
for (int row = 0; row < binaryGrid; row++) {
int pixelY0 = y1 + innerWidth - (row + 1) * innerWidth / binaryGrid;
int pixelY1 = y1 + innerWidth - (row) * innerWidth / binaryGrid;
for (int col = 0; col < binaryGrid; col++) {
int pixelX0 = x1 + col * innerWidth / binaryGrid;
int pixelX1 = x1 + (col + 1) * innerWidth / binaryGrid;
boolean white;
if (row == 0 && col == 0)
white = false;
else if (row == 0 && col == binaryGrid - 1)
white = true;
else if (row == binaryGrid - 1 && col == binaryGrid - 1)
white = true;
else if (row == binaryGrid - 1 && col == 0)
white = true;
else {
white = ((value >> bit) & 0x01) == 0;
bit++;
}
if (white) {
ImageMiscOps.fillRectangle(image, 255, pixelX0, pixelY0, pixelX1 - pixelX0, pixelY1 - pixelY0);
}
}
}
}
Aggregations