Transform Point Cloud from Millimeters to Meters
This tutorial demonstrates how to transform point cloud data from millimeters to meters using a 4x4 homogeneous transformation matrix.
First, we load a point cloud.
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()
We then create a 4x4 transformation matrix with 0.001 scaling.
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
)
Then, we transform the point cloud using this transformation matrix.
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)
Finally, save the transformed point cloud.
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)