use of georegression.struct.point.Point2D_F64 in project BoofCV by lessthanoptimal.
the class VisualizeShapes method drawPolygon.
/**
* Draws a polygon
*
* @param polygon The polygon
* @param loop true if the end points are connected, forming a loop
* @param g2 Graphics object it's drawn to
*/
public static void drawPolygon(Polygon2D_F64 polygon, boolean loop, Graphics2D g2) {
for (int i = 0; i < polygon.size() - 1; i++) {
Point2D_F64 p0 = polygon.get(i);
Point2D_F64 p1 = polygon.get(i + 1);
g2.drawLine((int) (p0.x + 0.5), (int) (p0.y + 0.5), (int) (p1.x + 0.5), (int) (p1.y + 0.5));
}
if (loop && polygon.size() > 0) {
Point2D_F64 p0 = polygon.get(0);
Point2D_F64 p1 = polygon.get(polygon.size() - 1);
g2.drawLine((int) (p0.x + 0.5), (int) (p0.y + 0.5), (int) (p1.x + 0.5), (int) (p1.y + 0.5));
}
}
use of georegression.struct.point.Point2D_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.Point2D_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.Point2D_F64 in project BoofCV by lessthanoptimal.
the class ImageZoomPanel method pixelToPoint.
public Point2D_F64 pixelToPoint(int x, int y) {
Point2D_F64 ret = new Point2D_F64();
ret.x = x / scale;
ret.y = y / scale;
return ret;
}
use of georegression.struct.point.Point2D_F64 in project BoofCV by lessthanoptimal.
the class RadialDistortionEstimateLinear method setupA_and_B.
private void setupA_and_B(DMatrixRMaj K, List<DMatrixRMaj> homographies, List<CalibrationObservation> observations) {
final int N = observations.size();
// image center in pixels
// image center x-coordinate
double u0 = K.get(0, 2);
// image center y-coordinate
double v0 = K.get(1, 2);
// projected predicted
Point2D_F64 projCalibrated = new Point2D_F64();
Point2D_F64 projPixel = new Point2D_F64();
int pointIndex = 0;
for (int indexObs = 0; indexObs < N; indexObs++) {
DMatrixRMaj H = homographies.get(indexObs);
CalibrationObservation set = observations.get(indexObs);
for (int i = 0; i < set.size(); i++) {
int gridIndex = set.get(i).index;
Point2D_F64 obsPixel = set.get(i);
// location of grid point in world coordinate (x,y,0) assume z=0
Point2D_F64 gridPt = worldPoints.get(gridIndex);
// compute the predicted location of the point in calibrated units
GeometryMath_F64.mult(H, gridPt, projCalibrated);
// compute the predicted location in (uncalibrated) pixels
GeometryMath_F64.mult(K, projCalibrated, projPixel);
// construct the matrices
double r2 = projCalibrated.x * projCalibrated.x + projCalibrated.y * projCalibrated.y;
double a = 1.0;
for (int j = 0; j < X.numRows; j++) {
a *= r2;
A.set(pointIndex * 2 + 0, j, (projPixel.x - u0) * a);
A.set(pointIndex * 2 + 1, j, (projPixel.y - v0) * a);
}
// observed location
B.set(pointIndex * 2 + 0, 0, obsPixel.x - projPixel.x);
B.set(pointIndex * 2 + 1, 0, obsPixel.y - projPixel.y);
pointIndex++;
}
}
}
Aggregations