use of boofcv.visualize.PointCloudViewer in project BoofCV by lessthanoptimal.
the class TestMultiViewStereoFromKnownSceneStructure method visualizeResults.
private void visualizeResults(MultiViewStereoFromKnownSceneStructure<GrayF32> alg) {
for (int i = 0; i < pairs.vertexes.size(); i++) {
GrayF32 gray = new GrayF32(1, 1);
new SimulatedLookUp().loadImage("id=" + i, gray);
ShowImages.showWindow(gray, "ID=" + i);
}
System.out.println("Cloud.size=" + alg.getCloud().size());
PointCloudViewer pcv = VisualizeData.createPointCloudViewer();
pcv.setCameraHFov(UtilAngle.radian(90));
pcv.setTranslationStep(0.2);
pcv.addCloud(alg.getCloud());
pcv.setColorizer(new TwoAxisRgbPlane.Z_XY(1.0).fperiod(1.0));
JComponent component = pcv.getComponent();
component.setPreferredSize(new Dimension(400, 400));
ShowImages.showBlocking(component, "Cloud", 60_000);
}
use of boofcv.visualize.PointCloudViewer in project BoofCV by lessthanoptimal.
the class ExampleStereoDisparity3D method computeAndShowCloud.
/**
* Given already computed rectified images and known stereo parameters, create a 3D cloud and visualize it
*/
public static JComponent computeAndShowCloud(StereoParameters param, GrayU8 rectLeft, RectifyCalibrated rectAlg, GrayF32 disparity) {
// The point cloud will be in the left cameras reference frame
DMatrixRMaj rectK = rectAlg.getCalibrationMatrix();
DMatrixRMaj rectR = rectAlg.getRectifiedRotation();
// Put all the disparity parameters into one data structure
var disparityParameters = new DisparityParameters();
disparityParameters.baseline = param.getBaseline();
disparityParameters.disparityMin = disparityMin;
disparityParameters.disparityRange = disparityRange;
disparityParameters.rotateToRectified.setTo(rectR);
PerspectiveOps.matrixToPinhole(rectK, rectLeft.width, rectLeft.height, disparityParameters.pinhole);
// Iterate through each pixel in disparity image and compute its 3D coordinate
PointCloudViewer pcv = VisualizeData.createPointCloudViewer();
pcv.setTranslationStep(param.getBaseline() * 0.1);
// Next create the 3D point cloud. The function below will handle conversion from disparity into
// XYZ, then transform from rectified into normal camera coordinate system. Feel free to glance at the
// source code to understand exactly what it's doing
MultiViewStereoOps.disparityToCloud(disparity, disparityParameters, null, (pixX, pixY, x, y, z) -> {
// look up the gray value. Then convert it into RGB
int v = rectLeft.unsafe_get(pixX, pixY);
pcv.addPoint(x, y, z, v << 16 | v << 8 | v);
});
// Configure the display
// pcv.setFog(true);
// pcv.setClipDistance(baseline*45);
// PeriodicColorizer colorizer = new TwoAxisRgbPlane.Z_XY(4.0);
// colorizer.setPeriod(baseline*5);
// pcv.setColorizer(colorizer); // sometimes pseudo color can be easier to view
pcv.setDotSize(1);
pcv.setCameraHFov(PerspectiveOps.computeHFov(param.left));
// pcv.setCameraToWorld(cameraToWorld);
JComponent viewer = pcv.getComponent();
viewer.setPreferredSize(new Dimension(600, 600 * param.left.height / param.left.width));
return viewer;
}
use of boofcv.visualize.PointCloudViewer in project BoofCV by lessthanoptimal.
the class ExampleStereoTwoViewsOneCamera method showPointCloud.
/**
* Show results as a point cloud
*/
public static void showPointCloud(ImageGray disparity, BufferedImage left, Se3_F64 motion, DMatrixRMaj rectifiedK, DMatrixRMaj rectifiedR, int disparityMin, int disparityRange) {
DisparityToColorPointCloud d2c = new DisparityToColorPointCloud();
PointCloudWriter.CloudArraysF32 cloud = new PointCloudWriter.CloudArraysF32();
double baseline = motion.getT().norm();
d2c.configure(baseline, rectifiedK, rectifiedR, new DoNothing2Transform2_F64(), disparityMin, disparityRange);
d2c.process(disparity, UtilDisparitySwing.wrap(left), cloud);
CameraPinhole rectifiedPinhole = PerspectiveOps.matrixToPinhole(rectifiedK, disparity.width, disparity.height, null);
// skew the view to make the structure easier to see
Se3_F64 cameraToWorld = SpecialEuclideanOps_F64.eulerXyz(-baseline * 5, 0, 0, 0, 0.2, 0, null);
PointCloudViewer pcv = VisualizeData.createPointCloudViewer();
pcv.setCameraHFov(PerspectiveOps.computeHFov(rectifiedPinhole));
pcv.setCameraToWorld(cameraToWorld);
pcv.setTranslationStep(baseline / 3);
pcv.addCloud(cloud.cloudXyz, cloud.cloudRgb);
pcv.setDotSize(1);
pcv.setTranslationStep(baseline / 10);
pcv.getComponent().setPreferredSize(new Dimension(left.getWidth(), left.getHeight()));
ShowImages.showWindow(pcv.getComponent(), "Point Cloud", true);
}
use of boofcv.visualize.PointCloudViewer in project BoofCV by lessthanoptimal.
the class ExampleViewPointCloud method main.
public static void main(String[] args) throws IOException {
String filePath = UtilIO.pathExample("mvs/stone_sign.ply");
// Load the PLY file
var cloud = new DogArray<>(Point3dRgbI_F32::new);
PointCloudIO.load(PointCloudIO.Format.PLY, new FileInputStream(filePath), PointCloudWriter.wrapF32RGB(cloud));
System.out.println("Total Points " + cloud.size);
// Create the 3D viewer as a Swing panel that will have some minimal controls for adjusting the clouds
// appearance. Since a software render is used it will get a bit sluggish (on my computer)
// around 1,000,000 points
PointCloudViewerPanel viewerPanel = new PointCloudViewerPanel();
viewerPanel.setPreferredSize(new Dimension(800, 600));
PointCloudViewer viewer = viewerPanel.getViewer();
// Change the camera's Field-of-View
viewer.setCameraHFov(UtilAngle.radian(60));
// So many formats to store a 3D point and color that a functional API is used here
viewer.addCloud((idx, p) -> ConvertFloatType.convert(cloud.get(idx), p), (idx) -> cloud.get(idx).rgb, cloud.size);
// There are a ton of options for the viewer, but we will let the GUI handle most of them
// Alternatively, you could use VisualizeData.createPointCloudViewer(). No controls are
// provided if you use that.
SwingUtilities.invokeLater(() -> {
viewerPanel.handleControlChange();
viewerPanel.repaint();
ShowImages.showWindow(viewerPanel, "Point Cloud", true);
});
}
use of boofcv.visualize.PointCloudViewer in project BoofCV by lessthanoptimal.
the class ExampleMultiViewSparseReconstruction method visualizeSparseCloud.
/**
* To visualize the results we will render a sparse point cloud along with the location of each camera in the
* scene.
*/
public void visualizeSparseCloud() {
checkTrue(scene.isHomogenous());
List<Point3D_F64> cloudXyz = new ArrayList<>();
Point4D_F64 world = new Point4D_F64();
// NOTE: By default the colors found below are not used. Look before to see why and how to turn them on.
//
// Colorize the cloud by reprojecting the images. The math is straight forward but there's a lot of book
// keeping that needs to be done due to the scene data structure. A class is provided to make this process easy
var imageLookup = new LookUpImageFilesByIndex(imageFiles);
var colorize = new ColorizeMultiViewStereoResults<>(new LookUpColorRgbFormats.PL_U8(), imageLookup);
DogArray_I32 rgb = new DogArray_I32();
rgb.resize(scene.points.size);
colorize.processScenePoints(scene, // String encodes the image's index
(viewIdx) -> viewIdx + "", // Assign the RGB color
(pointIdx, r, g, b) -> rgb.set(pointIdx, (r << 16) | (g << 8) | b));
// Convert the structure into regular 3D points from homogenous
for (int i = 0; i < scene.points.size; i++) {
scene.points.get(i).get(world);
// array would be out of sync. Let's just throw it far far away then.
if (world.w == 0.0)
cloudXyz.add(new Point3D_F64(0, 0, Double.MAX_VALUE));
else
cloudXyz.add(new Point3D_F64(world.x / world.w, world.y / world.w, world.z / world.w));
}
PointCloudViewer viewer = VisualizeData.createPointCloudViewer();
viewer.setFog(true);
// We just did a bunch of work to look up the true color of points, however for sparse data it's easy to see
// the structure with psuedo color. Comment out the line below to see the true color.
viewer.setColorizer(new TwoAxisRgbPlane.Z_XY(1.0).fperiod(40));
viewer.setDotSize(1);
viewer.setTranslationStep(0.15);
viewer.addCloud((idx, p) -> p.setTo(cloudXyz.get(idx)), rgb::get, rgb.size);
viewer.setCameraHFov(UtilAngle.radian(60));
SwingUtilities.invokeLater(() -> {
// Show where the cameras are
BoofSwingUtil.visualizeCameras(scene, viewer);
// Size the window and show it to the user
viewer.getComponent().setPreferredSize(new Dimension(600, 600));
ShowImages.showWindow(viewer.getComponent(), "Refined Scene", true);
var copy = new DogArray<>(Point3dRgbI_F64::new);
viewer.copyCloud(copy);
try (var out = new FileOutputStream("saved_cloud.ply")) {
PointCloudIO.save3D(PointCloudIO.Format.PLY, PointCloudReader.wrapF64RGB(copy.toList()), true, out);
} catch (IOException e) {
e.printStackTrace();
}
});
}
Aggregations