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);
}
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);
}
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");
}
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;
}
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);
}
Aggregations