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) + "/ArucoMarkerInCameraOrigin.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/ArucoMarkerInCameraOrigin.zdf";
Console.WriteLine("Reading " + dataFile + " point cloud");
var frame = new Zivid.NET.Frame(dataFile);
var pointCloud = frame.PointCloud;
We then create a 4x4 transformation matrix with 0.001 scaling.
const auto transformMillimetersToMeters =
Zivid::Matrix4x4{ { 0.001F, 0, 0, 0 }, { 0, 0.001F, 0, 0 }, { 0, 0, 0.001F, 0 }, { 0, 0, 0, 1 } };
var transformMillimetersToMeters =
new float[,] { { 0.001F, 0, 0, 0 }, { 0, 0.001F, 0, 0 }, { 0, 0, 0.001F, 0 }, { 0, 0, 0, 1 } };
Then, we transform the point cloud using this transformation matrix.
std::cout << "Transforming point cloud from mm to m" << std::endl;
pointCloud.transform(transformMillimetersToMeters);
Console.WriteLine("Transforming point cloud from mm to m");
pointCloud.Transform(transformMillimetersToMeters);
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);