将点云从毫米转换为米
本教程展示了如何使用4x4齐次变换矩阵将点云数据从毫米转换为米。
首先,我们加载一个点云。
const auto dataFile = std::string(ZIVID_SAMPLE_DATA_DIR) + "/CalibrationBoardInCameraOrigin.zdf";
std::cout << "Reading " << dataFile << " point cloud" << std::endl;
auto frame = Zivid::Frame(dataFile);
auto pointCloud = frame.pointCloud();
var dataFile = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData)
+ "/Zivid/CalibrationBoardInCameraOrigin.zdf";
Console.WriteLine("Reading " + dataFile + " point cloud");
var frame = new Zivid.NET.Frame(dataFile);
var pointCloud = frame.PointCloud;
data_file = get_sample_data_path() / "CalibrationBoardInCameraOrigin.zdf"
print(f"Reading {data_file} point cloud")
frame = zivid.Frame(data_file)
point_cloud = frame.point_cloud()
然后我们创建一个0.001缩放比例的4x4变换矩阵。
const auto millimetersToMetersTransform =
Zivid::Matrix4x4{ { 0.001F, 0, 0, 0 }, { 0, 0.001F, 0, 0 }, { 0, 0, 0.001F, 0 }, { 0, 0, 0, 1 } };
var millimetersToMetersTransform =
new float[,] { { 0.001F, 0, 0, 0 }, { 0, 0.001F, 0, 0 }, { 0, 0, 0.001F, 0 }, { 0, 0, 0, 1 } };
transform_millimeters_to_meters = np.array(
[[0.001, 0, 0, 0], [0, 0.001, 0, 0], [0, 0, 0.001, 0], [0, 0, 0, 1]], dtype=np.float32
)
我们使用这个变换矩阵进行点云转换。
std::cout << "Transforming point cloud from mm to m" << std::endl;
pointCloud.transform(millimetersToMetersTransform);
Console.WriteLine("Transforming point cloud from mm to m");
pointCloud.Transform(millimetersToMetersTransform);
print("Transforming point cloud from mm to m")
point_cloud.transform(transform_millimeters_to_meters)
最后,保存转换后的点云。
const auto transformedFile = "FrameInMeters.zdf";
std::cout << "Saving transformed point cloud to file: " << transformedFile << std::endl;
frame.save(transformedFile);
var transformedFile = "FrameInMeters.zdf";
Console.WriteLine("Saving frame to file: " + transformedFile);
frame.Save(transformedFile);
transformed_file = "FrameInMeters.zdf"
print(f"Saving transformed point cloud to file: {transformed_file}")
frame.save(transformed_file)