use of georegression.struct.point.Point3D_F64 in project BoofCV by lessthanoptimal.
the class Polygon3DSequenceViewer method renderPolygons.
private void renderPolygons(Graphics2D g2) {
for (Poly poly : polygons) {
SePointOps_F64.transform(worldToCamera, poly.pts[0], p1);
GeometryMath_F64.mult(K, p1, x1);
// don't render what's behind the camera
if (p1.z < 0)
continue;
g2.setColor(poly.color);
boolean skip = false;
for (int i = 1; i < poly.pts.length; i++) {
SePointOps_F64.transform(worldToCamera, poly.pts[i], p2);
GeometryMath_F64.mult(K, p2, x2);
if (p2.z < 0) {
skip = true;
break;
}
line.setLine(x1.x, x1.y, x2.x, x2.y);
g2.draw(line);
Point3D_F64 tempP = p1;
Point2D_F64 tempX = x1;
p1 = p2;
p2 = tempP;
x1 = x2;
x2 = tempX;
}
if (!skip) {
SePointOps_F64.transform(worldToCamera, poly.pts[0], p2);
GeometryMath_F64.mult(K, p2, x2);
line.setLine(x1.x, x1.y, x2.x, x2.y);
g2.draw(line);
}
}
}
use of georegression.struct.point.Point3D_F64 in project BoofCV by lessthanoptimal.
the class VisualizeFiducial method drawChessboard.
/**
* Renders a translucent chessboard pattern
* @param g2 Graphics object it's drawn in
* @param fiducialToPixel Coverts a coordinate from fiducial into pixel
* @param numRows Number of rows in the calibration grid
* @param numCols Number of columns in the calibration grid
* @param squareWidth Width of each square
*/
public static void drawChessboard(Graphics2D g2, WorldToCameraToPixel fiducialToPixel, int numRows, int numCols, double squareWidth) {
Point3D_F64 fidPt = new Point3D_F64();
Point2D_F64 pixel0 = new Point2D_F64();
Point2D_F64 pixel1 = new Point2D_F64();
Point2D_F64 pixel2 = new Point2D_F64();
Point2D_F64 pixel3 = new Point2D_F64();
Line2D.Double l = new Line2D.Double();
int[] polyX = new int[4];
int[] polyY = new int[4];
int alpha = 100;
Color red = new Color(255, 0, 0, alpha);
Color black = new Color(0, 0, 0, alpha);
for (int row = 0; row < numRows; row++) {
double y0 = -numRows * squareWidth / 2 + row * squareWidth;
for (int col = row % 2; col < numCols; col += 2) {
double x0 = -numCols * squareWidth / 2 + col * squareWidth;
fidPt.set(x0, y0, 0);
fiducialToPixel.transform(fidPt, pixel0);
fidPt.set(x0 + squareWidth, y0, 0);
fiducialToPixel.transform(fidPt, pixel1);
fidPt.set(x0 + squareWidth, y0 + squareWidth, 0);
fiducialToPixel.transform(fidPt, pixel2);
fidPt.set(x0, y0 + squareWidth, 0);
fiducialToPixel.transform(fidPt, pixel3);
polyX[0] = (int) (pixel0.x + 0.5);
polyX[1] = (int) (pixel1.x + 0.5);
polyX[2] = (int) (pixel2.x + 0.5);
polyX[3] = (int) (pixel3.x + 0.5);
polyY[0] = (int) (pixel0.y + 0.5);
polyY[1] = (int) (pixel1.y + 0.5);
polyY[2] = (int) (pixel2.y + 0.5);
polyY[3] = (int) (pixel3.y + 0.5);
g2.setColor(black);
g2.fillPolygon(polyX, polyY, 4);
g2.setColor(red);
drawLine(g2, l, pixel0.x, pixel0.y, pixel1.x, pixel1.y);
drawLine(g2, l, pixel1.x, pixel1.y, pixel2.x, pixel2.y);
drawLine(g2, l, pixel2.x, pixel2.y, pixel3.x, pixel3.y);
drawLine(g2, l, pixel3.x, pixel3.y, pixel0.x, pixel0.y);
}
}
}
use of georegression.struct.point.Point3D_F64 in project BoofCV by lessthanoptimal.
the class VisualizeFiducial method drawCube.
/**
* Draws a flat cube to show where the square fiducial is on the image
*/
public static void drawCube(Se3_F64 targetToCamera, CameraPinholeRadial intrinsic, double width, int lineThickness, Graphics2D g2) {
g2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE);
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
double r = width / 2.0;
double h = r;
Point3D_F64[] corners = new Point3D_F64[8];
corners[0] = new Point3D_F64(-r, -r, 0);
corners[1] = new Point3D_F64(r, -r, 0);
corners[2] = new Point3D_F64(r, r, 0);
corners[3] = new Point3D_F64(-r, r, 0);
corners[4] = new Point3D_F64(-r, -r, h);
corners[5] = new Point3D_F64(r, -r, h);
corners[6] = new Point3D_F64(r, r, h);
corners[7] = new Point3D_F64(-r, r, h);
Point2D_F64[] pixel = new Point2D_F64[8];
Point2D_F64 p = new Point2D_F64();
WorldToCameraToPixel transform = PerspectiveOps.createWorldToPixel(intrinsic, targetToCamera);
for (int i = 0; i < 8; i++) {
if (!transform.transform(corners[i], p))
throw new RuntimeException("Crap");
pixel[i] = p.copy();
}
Line2D.Double l = new Line2D.Double();
g2.setStroke(new BasicStroke(lineThickness));
g2.setColor(Color.RED);
drawLine(g2, l, pixel[0].x, pixel[0].y, pixel[1].x, pixel[1].y);
drawLine(g2, l, pixel[1].x, pixel[1].y, pixel[2].x, pixel[2].y);
drawLine(g2, l, pixel[2].x, pixel[2].y, pixel[3].x, pixel[3].y);
drawLine(g2, l, pixel[3].x, pixel[3].y, pixel[0].x, pixel[0].y);
g2.setColor(Color.BLACK);
drawLine(g2, l, pixel[0].x, pixel[0].y, pixel[4].x, pixel[4].y);
drawLine(g2, l, pixel[1].x, pixel[1].y, pixel[5].x, pixel[5].y);
drawLine(g2, l, pixel[2].x, pixel[2].y, pixel[6].x, pixel[6].y);
drawLine(g2, l, pixel[3].x, pixel[3].y, pixel[7].x, pixel[7].y);
g2.setColor(new Color(0x00, 0xFF, 0x00, 255));
drawLine(g2, l, pixel[4].x, pixel[4].y, pixel[5].x, pixel[5].y);
g2.setColor(new Color(0xC0, 0x10, 0xC0, 255));
drawLine(g2, l, pixel[5].x, pixel[5].y, pixel[6].x, pixel[6].y);
g2.setColor(new Color(0x00, 0xA0, 0xC0, 255));
drawLine(g2, l, pixel[6].x, pixel[6].y, pixel[7].x, pixel[7].y);
g2.setColor(Color.BLUE);
drawLine(g2, l, pixel[7].x, pixel[7].y, pixel[4].x, pixel[4].y);
}
use of georegression.struct.point.Point3D_F64 in project BoofCV by lessthanoptimal.
the class TestNarrowPixelToSphere_F64 method basic.
@Test
public void basic() {
NarrowPixelToSphere_F64 alg = new NarrowPixelToSphere_F64(new Dummy());
Point3D_F64 found = new Point3D_F64();
alg.compute(100, 120, found);
assertEquals(1.0, found.norm(), UtilEjml.TEST_F64);
assertEquals(100, found.x / found.z, UtilEjml.TEST_F64);
assertEquals(120, found.y / found.z, UtilEjml.TEST_F64);
}
use of georegression.struct.point.Point3D_F64 in project BoofCV by lessthanoptimal.
the class TestMultiViewOps method constraint_Trifocal_plp.
@Test
public void constraint_Trifocal_plp() {
Point3D_F64 X = new Point3D_F64(0.1, -0.05, 2);
computeLines(X, line1, line2, line3);
// When the tensor was constructed the first view was assumed to be [I|0], which
// is why normalized image coordinates are used for the first view
Point2D_F64 x1 = PerspectiveOps.renderPixel(new Se3_F64(), null, X);
Point2D_F64 x3 = PerspectiveOps.renderPixel(worldToCam3, K, X);
Vector3D_F64 found = MultiViewOps.constraint(tensor, x1, line2, x3, null);
assertEquals(0, found.x, 1e-12);
assertEquals(0, found.y, 1e-12);
assertEquals(0, found.z, 1e-12);
}
Aggregations