Search in sources :

Example 16 with WorldToCameraToPixel

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

the class TestSimulatePlanarWorld method checkOrientation.

private void checkOrientation(int expectedAA, int expectedAB, int expectedBB, int expectedBA, double rotZ) {
    double markerZ = 2;
    double markerWidth = 0.5;
    CameraPinhole pinhole = new CameraPinhole(400, 400, 0, 300, 250, 600, 500);
    GrayF32 marker = new GrayF32(40, 30);
    GImageMiscOps.fill(marker, 255);
    // fill the top left corner so that we can tell the orientation
    GImageMiscOps.fillRectangle(marker, 100, 0, 0, 20, 15);
    Se3_F64 markerToWorld = eulerXyz(0, 0, markerZ, 0, Math.PI, rotZ, null);
    SimulatePlanarWorld alg = new SimulatePlanarWorld();
    alg.setCamera(pinhole);
    alg.addSurface(markerToWorld, markerWidth, marker);
    alg.render();
    GrayF32 image = alg.getOutput();
    // ShowImages.showWindow(image,"Adsasd");
    // try {
    // Thread.sleep(10000);
    // } catch (InterruptedException e) {
    // e.printStackTrace();
    // }
    // figure out where the marker was rendered
    Point2D_F64 p0 = new Point2D_F64();
    Point2D_F64 p1 = new Point2D_F64();
    double ratio = marker.height / (double) marker.width;
    WorldToCameraToPixel w2p = new WorldToCameraToPixel();
    w2p.configure(pinhole, markerToWorld);
    assertTrue(w2p.transform(new Point3D_F64(-markerWidth / 2, -ratio * markerWidth / 2, 0), p0));
    assertTrue(w2p.transform(new Point3D_F64(markerWidth / 2, ratio * markerWidth / 2, 0), p1));
    int x0 = (int) Math.min(p0.x, p1.x);
    int y0 = (int) Math.min(p0.y, p1.y);
    int x1 = (int) Math.max(p0.x, p1.x);
    int y1 = (int) Math.max(p0.y, p1.y);
    int xm = (x0 + x1) / 2;
    int ym = (y0 + y1) / 2;
    double regionAA = image.get((x0 + xm) / 2, (y0 + ym) / 2);
    double regionAB = image.get((x0 + xm) / 2, (ym + y1) / 2);
    double regionBB = image.get((xm + x1) / 2, (ym + y1) / 2);
    double regionBA = image.get((xm + x1) / 2, (y0 + ym) / 2);
    assertEquals(expectedAA, regionAA, 5);
    assertEquals(expectedAB, regionAB, 5);
    assertEquals(expectedBB, regionBB, 5);
    assertEquals(expectedBA, regionBA, 5);
}
Also used : Point3D_F64(georegression.struct.point.Point3D_F64) GrayF32(boofcv.struct.image.GrayF32) Point2D_F64(georegression.struct.point.Point2D_F64) WorldToCameraToPixel(boofcv.alg.geo.WorldToCameraToPixel) CameraPinhole(boofcv.struct.calib.CameraPinhole) Se3_F64(georegression.struct.se.Se3_F64)

Example 17 with WorldToCameraToPixel

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

the class TestQuadPoseEstimator method computeErrors.

@Test
void computeErrors() {
    LensDistortionNarrowFOV distortion = createDistortion();
    Se3_F64 fiducialToCamera = new Se3_F64();
    fiducialToCamera.getT().setTo(0.2, -0.15, 2);
    ConvertRotation3D_F64.eulerToMatrix(EulerType.XYZ, 0.05, 0.015, 0.001, fiducialToCamera.R);
    QuadPoseEstimator alg = new QuadPoseEstimator(1e-8, 200);
    alg.setLensDistoriton(distortion);
    double r = 1.5;
    alg.setFiducial(r, -r, r, r, -r, r, -r, -r);
    WorldToCameraToPixel worldToPixel = PerspectiveOps.createWorldToPixel(distortion, fiducialToCamera);
    for (int i = 0; i < 4; i++) {
        Point3D_F64 X = alg.points.get(i).location;
        alg.listObs.add(worldToPixel.transform(X));
    }
    // perfect
    assertEquals(0, alg.computeErrors(fiducialToCamera), 1e-8);
    // now with known errors
    for (int i = 0; i < 4; i++) {
        alg.listObs.get(i).x += 1.5;
        assertEquals(1.5, alg.computeErrors(fiducialToCamera), 1e-8);
        alg.listObs.get(i).x -= 1.5;
    }
}
Also used : Point3D_F64(georegression.struct.point.Point3D_F64) LensDistortionNarrowFOV(boofcv.alg.distort.LensDistortionNarrowFOV) WorldToCameraToPixel(boofcv.alg.geo.WorldToCameraToPixel) Se3_F64(georegression.struct.se.Se3_F64) Test(org.junit.jupiter.api.Test)

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