当前位置:首页>自动驾驶>【Java深度学习】自动驾驶SLAM点云大佬 Open3D 加入到Java 大家庭 【AI Infra3.0】【PyTorch ON Java】

【Java深度学习】自动驾驶SLAM点云大佬 Open3D 加入到Java 大家庭 【AI Infra3.0】【PyTorch ON Java】

  • 2026-09-08 02:00:23
【Java深度学习】自动驾驶SLAM点云大佬 Open3D 加入到Java 大家庭 【AI Infra3.0】【PyTorch ON Java】
做过自动驾驶的都知道Open3D ,但是它现在只支持Python 和cpp ,虽然它后端是cpp写的,我之前曾给他们github 官方仓库提issue 希望他们支持java,但是他们很决绝的答复我:【java 从来不在我们的考虑范围之内!我们永远也不会开发java 的sdk ! 凭什么让我们来支持Java】 这大概就是java 的尴尬地位,但是我们有javacpp 这一杀手【贱】的存在,你不支持没关系,只要你的代码是开源且是cpp 写的,我就能让你被迫支持上java。这不 我们最近的实验就是使用javacpp 利用Claude 大模型,把Open3D 的底裤给扒下来了,从此我们在jvm 平台也可以用上 Open3D了,当然我们也很贱,又跑到Open3d 原issue 回复官方,我们已经让 Open3D的最新版本支持上了 Java!
未来希望更多的朋友能够使用javacpp 和claude 来把一些cpp 重要的工具转译到java 生态中,这种造轮子是值得提倡去做了,极大的丰富和对齐了java在一些高性能工具上的不足。
我们给大家看几个使用示例
1
Markdown
复制
```java
package org.open3d.examples;import org.open3d.*;import static org.open3d.global.Open3D.*;/** * Example 1: Read and Write Point Cloud * * Demonstrates loading a point cloud from a file (PLY/PCD/XYZ), * inspecting basic properties, and writing it back to a different format. */public class Example1_ReadWritePointCloud {public static void main(String[] args) {if (args.length < 1) {            System.out.println("Usage: Example1_ReadWritePointCloud <input_file> [output_file]");System.out.println("  Supported formats: .ply, .pcd, .xyz, .xyzn, .xyzrgb, .pts");System.out.println("\nExample:");System.out.println("  java Example1_ReadWritePointCloud bunny.ply output.pcd");return;}        String inputFile = args[0];String outputFile = args.length > 1 ? args[1] : "output.ply";System.out.println("=== Open3D JavaCPP - Read/Write Point Cloud ===");System.out.println("Input:  " + inputFile);System.out.println("Output: " + outputFile);// Read point cloud from filePointCloud pcd = new PointCloud();boolean readSuccess = ReadPointCloud(inputFile, pcd);if (!readSuccess) {            System.err.println("Failed to read point cloud from: " + inputFile);return;}// Print basic infoSystem.out.println("\n--- Point Cloud Info ---");System.out.println("Has points:  " + pcd.HasPoints());System.out.println("Has normals: " + pcd.HasNormals());System.out.println("Has colors:  " + pcd.HasColors());System.out.println("Is empty:    " + pcd.IsEmpty());// Get bounding boxdouble[] minBound = pcd.GetMinBound();double[] maxBound = pcd.GetMaxBound();System.out.printf("Min bound: [%.3f, %.3f, %.3f]%n", minBound[0], minBound[1], minBound[2]);System.out.printf("Max bound: [%.3f, %.3f, %.3f]%n", maxBound[0], maxBound[1], maxBound[2]);// Write point cloud to output fileboolean writeSuccess = WritePointCloud(outputFile, pcd);if (writeSuccess) {            System.out.println("\nPoint cloud written to: " + outputFile);} else {            System.err.println("\nFailed to write point cloud to: " + outputFile);}        System.out.println("\n=== Done ===");}}
```
Markdown
复制
```java
package org.open3d.examples;import org.open3d.*;import static org.open3d.global.Open3D.*;/** * Example 4: ICP Registration * * Demonstrates registering two point clouds using Iterative Closest Point (ICP). */public class Example4_ICPRegistration {public static void main(String[] args) {if (args.length < 2) {            System.out.println("Usage: Example4_ICPRegistration <source.ply> <target.ply>");System.out.println("  Registers the source point cloud to the target using ICP.");return;}        String sourceFile = args[0];String targetFile = args[1];System.out.println("=== Open3D JavaCPP - ICP Registration ===");System.out.println("Source: " + sourceFile);System.out.println("Target: " + targetFile);// Read source and target point cloudsPointCloud source = new PointCloud();PointCloud target = new PointCloud();boolean s1 = ReadPointCloud(sourceFile, source);boolean s2 = ReadPointCloud(targetFile, target);if (!s1 || !s2) {            System.err.println("Failed to read point clouds.");return;}        System.out.println("\n--- Source: has points = " + source.HasPoints());System.out.println("--- Target: has points = " + target.HasPoints());// Estimate normals (needed for point-to-plane ICP)KDTreeSearchParamKNN searchParam = new KDTreeSearchParamKNN(30);source.EstimateNormals(searchParam, true);target.EstimateNormals(searchParam, true);System.out.println("Normals estimated for both clouds.");double maxCorrespondenceDistance = 0.05;// Evaluate initial alignmentSystem.out.println("\n--- Evaluate Initial Alignment ---");RegistrationResult evalResult = EvaluateRegistration(source, target, maxCorrespondenceDistance);System.out.printf("Initial Fitness:     %.6f%n", evalResult.fitness_());System.out.printf("Initial Inlier RMSE: %.6f%n", evalResult.inlier_rmse_());// Point-to-point ICPSystem.out.println("\n--- Point-to-Point ICP ---");TransformationEstimationPointToPoint estimationP2P =                new TransformationEstimationPointToPoint(false);ICPConvergenceCriteria criteria =                new ICPConvergenceCriteria(1e-6, 1e-6, 30);RegistrationResult resultP2P = RegistrationICP(                source, target, maxCorrespondenceDistance,new double[]{1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1}, // identity 4x4estimationP2P, criteria);System.out.printf("P2P Fitness:     %.6f%n", resultP2P.fitness_());System.out.printf("P2P Inlier RMSE: %.6f%n", resultP2P.inlier_rmse_());// Point-to-plane ICPSystem.out.println("\n--- Point-to-Plane ICP ---");TransformationEstimationPointToPlane estimationP2L =                new TransformationEstimationPointToPlane();RegistrationResult resultP2L = RegistrationICP(                source, target, maxCorrespondenceDistance,new double[]{1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1},                estimationP2L, criteria);System.out.printf("P2L Fitness:     %.6f%n", resultP2L.fitness_());System.out.printf("P2L Inlier RMSE: %.6f%n", resultP2L.inlier_rmse_());System.out.println("\n=== Done ===");}}
```

最新文章

随机文章