Search in sources :

Example 46 with CameraPinholeRadial

use of boofcv.struct.calib.CameraPinholeRadial in project BoofCV by lessthanoptimal.

the class CreateRgbPointCloudFileApp method main.

public static void main(String[] args) throws IOException {
    String baseDir = "log/";
    String nameRgb = baseDir + "rgb0000000.ppm";
    String nameDepth = baseDir + "depth0000000.depth";
    String nameCalib = baseDir + "intrinsic.yaml";
    CameraPinholeRadial param = CalibrationIO.load(nameCalib);
    GrayU16 depth = new GrayU16(1, 1);
    Planar<GrayU8> rgb = new Planar<>(GrayU8.class, 1, 1, 3);
    UtilImageIO.loadPPM_U8(nameRgb, rgb, null);
    UtilOpenKinect.parseDepth(nameDepth, depth, null);
    FastQueue<Point3D_F64> cloud = new FastQueue<Point3D_F64>(Point3D_F64.class, true);
    FastQueueArray_I32 cloudColor = new FastQueueArray_I32(3);
    VisualDepthOps.depthTo3D(param, rgb, depth, cloud, cloudColor);
    DataOutputStream file = new DataOutputStream(new FileOutputStream("kinect_pointcloud.txt"));
    file.write("# Kinect RGB Point cloud. Units: millimeters. Format: X Y Z R G B\n".getBytes());
    for (int i = 0; i < cloud.size; i++) {
        Point3D_F64 p = cloud.get(i);
        int[] color = cloudColor.get(i);
        String line = String.format("%.10f %.10f %.10f %d %d %d\n", p.x, p.y, p.z, color[0], color[1], color[2]);
        file.write(line.getBytes());
    }
    file.close();
    System.out.println("Total points = " + cloud.size);
}
Also used : Point3D_F64(georegression.struct.point.Point3D_F64) GrayU16(boofcv.struct.image.GrayU16) FastQueue(org.ddogleg.struct.FastQueue) DataOutputStream(java.io.DataOutputStream) FastQueueArray_I32(boofcv.struct.FastQueueArray_I32) CameraPinholeRadial(boofcv.struct.calib.CameraPinholeRadial) FileOutputStream(java.io.FileOutputStream) Planar(boofcv.struct.image.Planar) GrayU8(boofcv.struct.image.GrayU8)

Example 47 with CameraPinholeRadial

use of boofcv.struct.calib.CameraPinholeRadial in project BoofCV by lessthanoptimal.

the class DisplayKinectPointCloudApp method main.

public static void main(String[] args) throws IOException {
    String baseDir = UtilIO.pathExample("kinect/basket");
    String nameRgb = "basket_rgb.png";
    String nameDepth = "basket_depth.png";
    String nameCalib = "intrinsic.yaml";
    CameraPinholeRadial param = CalibrationIO.load(new File(baseDir, nameCalib));
    GrayU16 depth = UtilImageIO.loadImage(new File(baseDir, nameDepth), false, ImageType.single(GrayU16.class));
    Planar<GrayU8> rgb = UtilImageIO.loadImage(new File(baseDir, nameRgb), true, ImageType.pl(3, GrayU8.class));
    FastQueue<Point3D_F64> cloud = new FastQueue<Point3D_F64>(Point3D_F64.class, true);
    FastQueueArray_I32 cloudColor = new FastQueueArray_I32(3);
    VisualDepthOps.depthTo3D(param, rgb, depth, cloud, cloudColor);
    DMatrixRMaj K = PerspectiveOps.calibrationMatrix(param, (DMatrixRMaj) null);
    PointCloudViewer viewer = new PointCloudViewer(K, 10.0);
    viewer.setPreferredSize(new Dimension(rgb.width, rgb.height));
    for (int i = 0; i < cloud.size; i++) {
        Point3D_F64 p = cloud.get(i);
        int[] color = cloudColor.get(i);
        int c = (color[0] << 16) | (color[1] << 8) | color[2];
        viewer.addPoint(p.x, p.y, p.z, c);
    }
    ShowImages.showWindow(viewer, "Point Cloud", true);
    System.out.println("Total points = " + cloud.size);
// BufferedImage depthOut = VisualizeImageData.disparity(depth, null, 0, UtilOpenKinect.FREENECT_DEPTH_MM_MAX_VALUE, 0);
// ShowImages.showWindow(depthOut,"Depth Image", true);
}
Also used : Point3D_F64(georegression.struct.point.Point3D_F64) GrayU16(boofcv.struct.image.GrayU16) FastQueue(org.ddogleg.struct.FastQueue) DMatrixRMaj(org.ejml.data.DMatrixRMaj) FastQueueArray_I32(boofcv.struct.FastQueueArray_I32) CameraPinholeRadial(boofcv.struct.calib.CameraPinholeRadial) PointCloudViewer(boofcv.gui.d3.PointCloudViewer) GrayU8(boofcv.struct.image.GrayU8) File(java.io.File)

Example 48 with CameraPinholeRadial

use of boofcv.struct.calib.CameraPinholeRadial in project BoofCV by lessthanoptimal.

the class IntrinsicToDepthParameters method main.

public static void main(String[] args) {
    String baseDir = UtilIO.pathExample("kinect/basket");
    CameraPinholeRadial intrinsic = CalibrationIO.load(new File(baseDir, "intrinsic.yaml"));
    VisualDepthParameters depth = new VisualDepthParameters();
    depth.setVisualParam(intrinsic);
    depth.setMaxDepth(UtilOpenKinect.FREENECT_DEPTH_MM_MAX_VALUE);
    depth.setPixelNoDepth(UtilOpenKinect.FREENECT_DEPTH_MM_NO_VALUE);
    CalibrationIO.save(depth, baseDir + "visualdepth.yaml");
}
Also used : VisualDepthParameters(boofcv.struct.calib.VisualDepthParameters) CameraPinholeRadial(boofcv.struct.calib.CameraPinholeRadial) File(java.io.File)

Example 49 with CameraPinholeRadial

use of boofcv.struct.calib.CameraPinholeRadial in project BoofCV by lessthanoptimal.

the class UtilOpenCV method loadPinholeRadial.

/**
 * Loads a pinhole camera model with radian and tangential distortion in OpenCV format
 *
 * @param fileName path to file
 * @return CameraPinholeRadial
 */
public static CameraPinholeRadial loadPinholeRadial(String fileName) {
    FileStorage fs = new FileStorage(new File(fileName).getAbsolutePath(), FileStorage.READ);
    IntPointer width = new IntPointer(1);
    IntPointer height = new IntPointer(1);
    read(fs.get("image_width"), width, -1);
    read(fs.get("image_height"), height, -1);
    Mat K = new Mat();
    read(fs.get("camera_matrix"), K);
    Mat distortion = new Mat();
    read(fs.get("distortion_coefficients"), distortion);
    CameraPinholeRadial boof = new CameraPinholeRadial();
    boof.width = width.get();
    boof.height = height.get();
    DoubleRawIndexer indexerK = K.createIndexer();
    boof.fx = indexerK.get(0, 0);
    boof.skew = indexerK.get(0, 1);
    boof.fy = indexerK.get(1, 1);
    boof.cx = indexerK.get(0, 2);
    boof.cy = indexerK.get(1, 2);
    DoubleRawIndexer indexerD = distortion.createIndexer();
    if (distortion.rows() >= 5)
        boof.setRadial(indexerD.get(0, 0), indexerD.get(1, 0), indexerD.get(4, 0));
    else if (distortion.rows() >= 2)
        boof.setRadial(indexerD.get(0, 0), indexerD.get(1, 0));
    if (distortion.rows() >= 5)
        boof.fsetTangental(indexerD.get(2, 0), indexerD.get(3, 0));
    return boof;
}
Also used : CameraPinholeRadial(boofcv.struct.calib.CameraPinholeRadial) IntPointer(org.bytedeco.javacpp.IntPointer) DoubleRawIndexer(org.bytedeco.javacpp.indexer.DoubleRawIndexer) File(java.io.File)

Example 50 with CameraPinholeRadial

use of boofcv.struct.calib.CameraPinholeRadial in project BoofCV by lessthanoptimal.

the class TestUtilOpenCV method loadPinholeRadial.

@Test
public void loadPinholeRadial() {
    URL url = TestUtilOpenCV.class.getResource("pinhole_distorted.yml");
    CameraPinholeRadial model = UtilOpenCV.loadPinholeRadial(url.getFile());
    assertEquals(640, model.width);
    assertEquals(480, model.height);
    assertEquals(5.2626362816407709e+02, model.fx, 1e-8);
    assertEquals(0, model.skew, 1e-8);
    assertEquals(5.2830704330313858e+02, model.fy, 1e-8);
    assertEquals(3.1306715867053975e+02, model.cx, 1e-8);
    assertEquals(2.4747722332735930e+02, model.cy, 1e-8);
    assertEquals(3, model.radial.length);
    assertEquals(-3.7077854691489726e-01, model.radial[0], 1e-8);
    assertEquals(2.4308561956661329e-01, model.radial[1], 1e-8);
    assertEquals(-1.2351969388838037e-01, model.radial[2], 1e-8);
    assertEquals(4.4148972909019294e-04, model.t1, 1e-8);
    assertEquals(-6.0304229617877381e-04, model.t2, 1e-8);
}
Also used : CameraPinholeRadial(boofcv.struct.calib.CameraPinholeRadial) URL(java.net.URL) Test(org.junit.Test)

Aggregations

CameraPinholeRadial (boofcv.struct.calib.CameraPinholeRadial)81 Test (org.junit.Test)37 Se3_F64 (georegression.struct.se.Se3_F64)26 GrayF32 (boofcv.struct.image.GrayF32)19 Point2D_F64 (georegression.struct.point.Point2D_F64)16 File (java.io.File)15 ConvertBufferedImage (boofcv.io.image.ConvertBufferedImage)12 BufferedImage (java.awt.image.BufferedImage)12 DMatrixRMaj (org.ejml.data.DMatrixRMaj)12 Point2Transform2_F32 (boofcv.struct.distort.Point2Transform2_F32)10 LensDistortionRadialTangential (boofcv.alg.distort.radtan.LensDistortionRadialTangential)9 CameraPinhole (boofcv.struct.calib.CameraPinhole)9 Point3D_F64 (georegression.struct.point.Point3D_F64)8 ArrayList (java.util.ArrayList)7 SimulatePlanarWorld (boofcv.simulation.SimulatePlanarWorld)6 StereoParameters (boofcv.struct.calib.StereoParameters)6 Point2Transform2_F64 (boofcv.struct.distort.Point2Transform2_F64)6 Point2D_F32 (georegression.struct.point.Point2D_F32)5 FMatrixRMaj (org.ejml.data.FMatrixRMaj)5 GrayU8 (boofcv.struct.image.GrayU8)4