Search in sources :

Example 1 with Point3D_F64

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);
        }
    }
}
Also used : Point3D_F64(georegression.struct.point.Point3D_F64) Point2D_F64(georegression.struct.point.Point2D_F64)

Example 2 with Point3D_F64

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);
        }
    }
}
Also used : Point3D_F64(georegression.struct.point.Point3D_F64) Point2D_F64(georegression.struct.point.Point2D_F64) Line2D(java.awt.geom.Line2D)

Example 3 with Point3D_F64

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);
}
Also used : Point3D_F64(georegression.struct.point.Point3D_F64) WorldToCameraToPixel(boofcv.alg.geo.WorldToCameraToPixel) Line2D(java.awt.geom.Line2D) Point2D_F64(georegression.struct.point.Point2D_F64)

Example 4 with Point3D_F64

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);
}
Also used : Point3D_F64(georegression.struct.point.Point3D_F64) Test(org.junit.Test)

Example 5 with Point3D_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);
}
Also used : Point3D_F64(georegression.struct.point.Point3D_F64) Vector3D_F64(georegression.struct.point.Vector3D_F64) Point2D_F64(georegression.struct.point.Point2D_F64) Se3_F64(georegression.struct.se.Se3_F64) Test(org.junit.Test)

Aggregations

Point3D_F64 (georegression.struct.point.Point3D_F64)174 Point2D_F64 (georegression.struct.point.Point2D_F64)85 Test (org.junit.Test)77 Se3_F64 (georegression.struct.se.Se3_F64)74 DMatrixRMaj (org.ejml.data.DMatrixRMaj)46 ArrayList (java.util.ArrayList)17 Vector3D_F64 (georegression.struct.point.Vector3D_F64)15 Point2D3D (boofcv.struct.geo.Point2D3D)13 AssociatedPair (boofcv.struct.geo.AssociatedPair)12 GrayU8 (boofcv.struct.image.GrayU8)9 FastQueue (org.ddogleg.struct.FastQueue)9 CameraPinholeRadial (boofcv.struct.calib.CameraPinholeRadial)8 Point2Transform2_F64 (boofcv.struct.distort.Point2Transform2_F64)7 MotionTransformPoint (georegression.fitting.MotionTransformPoint)7 UtilPoint3D_F64 (georegression.geometry.UtilPoint3D_F64)7 PointTrack (boofcv.abst.feature.tracker.PointTrack)5 StereoParameters (boofcv.struct.calib.StereoParameters)5 TrifocalTensor (boofcv.struct.geo.TrifocalTensor)5 GrayU16 (boofcv.struct.image.GrayU16)5 Stereo2D3D (boofcv.struct.sfm.Stereo2D3D)5