Search in sources :

Example 1 with WorldToCameraToPixel

use of boofcv.alg.geo.WorldToCameraToPixel 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 2 with WorldToCameraToPixel

use of boofcv.alg.geo.WorldToCameraToPixel in project BoofCV by lessthanoptimal.

the class GenericFiducialDetectorChecks method checkImageLocation.

@Test
public void checkImageLocation() {
    for (ImageType type : types) {
        ImageBase image = loadImage(type);
        FiducialDetector detector = createDetector(type);
        // It's not specified if the center should be undistorted or distorted. Just make it easier by
        // using undistorted
        LensDistortionNarrowFOV distortion = loadDistortion(false);
        detector.setLensDistortion(distortion, image.width, image.height);
        detector.detect(image);
        assertTrue(detector.totalFound() >= 1);
        assertTrue(detector.is3D());
        for (int i = 0; i < detector.totalFound(); i++) {
            Se3_F64 fidToCam = new Se3_F64();
            Point2D_F64 found = new Point2D_F64();
            detector.getFiducialToCamera(i, fidToCam);
            detector.getCenter(i, found);
            Point2D_F64 rendered = new Point2D_F64();
            WorldToCameraToPixel worldToPixel = PerspectiveOps.createWorldToPixel(distortion, fidToCam);
            worldToPixel.transform(new Point3D_F64(0, 0, 0), rendered);
            // see if the reprojected is near the pixel location
            assertTrue(rendered.distance(found) <= pixelAndProjectedTol);
        }
    }
}
Also used : Point3D_F64(georegression.struct.point.Point3D_F64) Point2D_F64(georegression.struct.point.Point2D_F64) LensDistortionNarrowFOV(boofcv.alg.distort.LensDistortionNarrowFOV) WorldToCameraToPixel(boofcv.alg.geo.WorldToCameraToPixel) ImageBase(boofcv.struct.image.ImageBase) ImageType(boofcv.struct.image.ImageType) Se3_F64(georegression.struct.se.Se3_F64) Test(org.junit.Test)

Example 3 with WorldToCameraToPixel

use of boofcv.alg.geo.WorldToCameraToPixel in project BoofCV by lessthanoptimal.

the class VisualizeFiducial method drawLabelCenter.

/**
 * Draws a flat cube to show where the square fiducial is on the image
 */
public static void drawLabelCenter(Se3_F64 targetToCamera, CameraPinholeBrown intrinsic, String label, Graphics2D g2, double scale) {
    // Computer the center of the fiducial in pixel coordinates
    Point2D_F64 p = new Point2D_F64();
    Point3D_F64 c = new Point3D_F64();
    WorldToCameraToPixel worldToPixel = PerspectiveOps.createWorldToPixel(intrinsic, targetToCamera);
    worldToPixel.transform(c, p);
    drawLabel(p, label, g2, scale);
}
Also used : Point3D_F64(georegression.struct.point.Point3D_F64) Point2D_F64(georegression.struct.point.Point2D_F64) WorldToCameraToPixel(boofcv.alg.geo.WorldToCameraToPixel)

Example 4 with WorldToCameraToPixel

use of boofcv.alg.geo.WorldToCameraToPixel 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, CameraPinholeBrown intrinsic, double width, double heightScale, int lineThickness, Graphics2D g2, double scale) {
    BoofSwingUtil.antialiasing(g2);
    double r = width / 2.0;
    double h = width * heightScale;
    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)) {
            System.err.println("Crap transform failed in drawCube!");
            return;
        }
        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, scale);
    drawLine(g2, l, pixel[1].x, pixel[1].y, pixel[2].x, pixel[2].y, scale);
    drawLine(g2, l, pixel[2].x, pixel[2].y, pixel[3].x, pixel[3].y, scale);
    drawLine(g2, l, pixel[3].x, pixel[3].y, pixel[0].x, pixel[0].y, scale);
    g2.setColor(Color.BLACK);
    drawLine(g2, l, pixel[0].x, pixel[0].y, pixel[4].x, pixel[4].y, scale);
    drawLine(g2, l, pixel[1].x, pixel[1].y, pixel[5].x, pixel[5].y, scale);
    drawLine(g2, l, pixel[2].x, pixel[2].y, pixel[6].x, pixel[6].y, scale);
    drawLine(g2, l, pixel[3].x, pixel[3].y, pixel[7].x, pixel[7].y, scale);
    g2.setColor(new Color(0x00, 0xFF, 0x00, 255));
    drawLine(g2, l, pixel[4].x, pixel[4].y, pixel[5].x, pixel[5].y, scale);
    g2.setColor(new Color(0xC0, 0x10, 0xC0, 255));
    drawLine(g2, l, pixel[5].x, pixel[5].y, pixel[6].x, pixel[6].y, scale);
    g2.setColor(new Color(0x00, 0xA0, 0xC0, 255));
    drawLine(g2, l, pixel[6].x, pixel[6].y, pixel[7].x, pixel[7].y, scale);
    g2.setColor(Color.BLUE);
    drawLine(g2, l, pixel[7].x, pixel[7].y, pixel[4].x, pixel[4].y, scale);
}
Also used : Point3D_F64(georegression.struct.point.Point3D_F64) Point2D_F64(georegression.struct.point.Point2D_F64) WorldToCameraToPixel(boofcv.alg.geo.WorldToCameraToPixel) Line2D(java.awt.geom.Line2D)

Example 5 with WorldToCameraToPixel

use of boofcv.alg.geo.WorldToCameraToPixel in project BoofCV by lessthanoptimal.

the class TestScaleSceneStructure method createProjectiveScene.

public static SceneObservations createProjectiveScene(SceneStructureMetric scene, long seed) {
    Random rand = new Random(seed);
    scene.initialize(2, 5, 20);
    SceneObservations observations = new SceneObservations();
    observations.initialize(scene.views.size);
    CameraPinhole camera0 = new CameraPinhole(500 + rand.nextDouble() * 10, 510 + rand.nextDouble() * 10, 0, 450, 400, 900, 800);
    // CameraPinhole camera1 = new CameraPinhole(456+rand.nextDouble()*10,510+rand.nextDouble()*10,0,420,410,900,800);
    scene.setCamera(0, false, camera0);
    for (int i = 0; i < scene.views.size; i++) {
        Se3_F64 worldToView = new Se3_F64();
        worldToView.T.x = i * 0.2 + rand.nextGaussian() * 0.1;
        worldToView.T.y = -i * 0.1 + rand.nextGaussian() * 0.1;
        worldToView.T.z = rand.nextGaussian() * 0.05;
        double rotX = rand.nextGaussian() * 0.05;
        double rotY = rand.nextGaussian() * 0.05;
        double rotZ = rand.nextGaussian() * 0.05;
        ConvertRotation3D_F64.eulerToMatrix(EulerType.XYZ, rotX, rotY, rotZ, worldToView.R);
        scene.setView(i, 0, false, worldToView);
    }
    WorldToCameraToPixel w2p = new WorldToCameraToPixel();
    for (int i = 0; i < scene.points.size; i++) {
        // Point in world frame
        Point3D_F64 X = new Point3D_F64(rand.nextGaussian(), rand.nextGaussian(), 3 + rand.nextGaussian());
        if (scene.homogenous) {
            scene.points.data[i].set(X.x, X.y, X.z, 1);
        } else {
            scene.points.data[i].set(X.x, X.y, X.z);
        }
        // Connect the point to views if it's visible inside of
        for (int viewIndex = 0; viewIndex < scene.views.size; viewIndex++) {
            // approximate by using the same camera
            w2p.configure(camera0, scene.getParentToView(viewIndex));
            Point2D_F64 pixel = w2p.transform(X);
            if (pixel != null && pixel.x >= 0 && pixel.y >= 0 && pixel.x < camera0.width && pixel.y < camera0.height) {
                scene.connectPointToView(i, viewIndex);
                observations.getView(viewIndex).add(i, (float) pixel.x, (float) pixel.y);
            }
        }
    }
    return observations;
}
Also used : Point3D_F64(georegression.struct.point.Point3D_F64) Random(java.util.Random) Point2D_F64(georegression.struct.point.Point2D_F64) WorldToCameraToPixel(boofcv.alg.geo.WorldToCameraToPixel) CameraPinhole(boofcv.struct.calib.CameraPinhole) Se3_F64(georegression.struct.se.Se3_F64)

Aggregations

WorldToCameraToPixel (boofcv.alg.geo.WorldToCameraToPixel)17 Point2D_F64 (georegression.struct.point.Point2D_F64)16 Point3D_F64 (georegression.struct.point.Point3D_F64)14 Se3_F64 (georegression.struct.se.Se3_F64)12 CameraPinhole (boofcv.struct.calib.CameraPinhole)6 Test (org.junit.jupiter.api.Test)5 LensDistortionNarrowFOV (boofcv.alg.distort.LensDistortionNarrowFOV)3 GrayF32 (boofcv.struct.image.GrayF32)3 ImageBase (boofcv.struct.image.ImageBase)2 ImageType (boofcv.struct.image.ImageType)2 Line2D (java.awt.geom.Line2D)2 Random (java.util.Random)2 DMatrixRMaj (org.ejml.data.DMatrixRMaj)2 LensDistortionBrown (boofcv.alg.distort.brown.LensDistortionBrown)1 BundlePinhole (boofcv.alg.geo.bundle.cameras.BundlePinhole)1 CameraPinholeBrown (boofcv.struct.calib.CameraPinholeBrown)1 Point2Transform2_F64 (boofcv.struct.distort.Point2Transform2_F64)1 PointIndex2D_F64 (boofcv.struct.geo.PointIndex2D_F64)1 UtilPoint3D_F64 (georegression.geometry.UtilPoint3D_F64)1 PlaneNormal3D_F64 (georegression.struct.plane.PlaneNormal3D_F64)1