转换
小技巧
我们的网络研讨会 Getting your point cloud ready for your application (为您的应用准备好点云)部分涵盖了转换的相关内容。
介绍
本文介绍了点云转换的背景,如何转换Zivid点云以及为什么这是一个有价值的功能。最后,文章还提供了一个带有代码示例的教程。
Zivid点云是基于 Zivid 相机坐标系 给出的。由于各种原因,不同的应用需要将整个点云或其片段(例如ROI或拾取点)从相机坐标系转换到另一个坐标系。
问题 |
点云是基于相机坐标系的,但应用需要在另一个坐标系中使用点云数据。 |
解决方案 |
将Zivid点云转换到另一个坐标系。 |
Transform in API
A rigid transformation is defined by a 4×4 homogeneous transformation matrix that describes the pose of one coordinate system relative to another. Once the transformation matrix is known, we can use Zivid SDK to transform the point cloud from the camera coordinate system to the desired coordinate system.
小技巧
Zivid SDK允许所有 仿射变换(在欧几里得几何中,仿射变换是保留点、直线和平面的几何变换),包括非刚性变换。这里有一个非刚性变换的例子 通过将点云从mm转换为m来缩放点云。
As an example, say you have detected the Zivid calibration board and estimated its pose.
std::cout << "Detecting and estimating pose of the Zivid checkerboard in the camera frame" << std::endl;
const auto detectionResult = Zivid::Calibration::detectCalibrationBoard(frame);
const auto cameraToCheckerboardTransform = detectionResult.pose().toMatrix();
std::cout << "Camera pose in checkerboard frame:" << std::endl;
const auto checkerboardToCameraTransform = cameraToCheckerboardTransform.inverse();
Console.WriteLine("Detecting and estimating pose of the Zivid checkerboard in the camera frame");
var detectionResult = Detector.DetectCalibrationBoard(frame);
var cameraToCheckerboardTransform = new Zivid.NET.Matrix4x4(detectionResult.Pose().ToMatrix());
Console.WriteLine("Camera pose in checkerboard frame:");
var checkerboardToCameraTransform = cameraToCheckerboardTransform.Inverse();
print("Detecting and estimating pose of the Zivid checkerboard in the camera frame")
detection_result = zivid.calibration.detect_calibration_board(frame)
if not detection_result.valid():
raise RuntimeError(f"No Checkerboard detected. {detection_result.status_description()}")
camera_to_checkerboard_transform = detection_result.pose().to_matrix()
print("Camera pose in checkerboard frame:")
checkerboard_to_camera_transform = np.linalg.inv(camera_to_checkerboard_transform)
This transformation matrix can then be used to transform the point cloud to the checkerboard coordinate system.
std::cout << "Transforming point cloud from camera frame to checkerboard frame" << std::endl;
pointCloud.transform(checkerboardToCameraTransform);
You can save the transformation matrix to file, and also load it from file.
const auto transformFile = "CheckerboardToCameraTransform.yaml";
std::cout << "Saving camera pose in checkerboard frame to file: " << transformFile << std::endl;
checkerboardToCameraTransform.save(transformFile);
The point cloud is transformed in-place, meaning you can save the transformed point cloud to file from the frame.
const auto checkerboardTransformedFile = "CalibrationBoardInCheckerboardOrigin.zdf";
std::cout << "Saving transformed point cloud to file: " << checkerboardTransformedFile << std::endl;
frame.save(checkerboardTransformedFile);
Similarly, you can also load a transformed point cloud. To recover the original point cloud, you can read out the applied transformation matrix to transform it back again.
std::cout << "Reading applied transformation matrix to the point cloud:" << std::endl;
const auto transformationMatrix = pointCloud.transformationMatrix();
std::cout << transformationMatrix << std::endl;
备注
Zivid SDK中转换API的处理速度非常快,因为它是在GPU中并行完成的,而点云数据此时仍在GPU内存内。使用第三方库计算法线可能更耗时:因为CPU计算通常要慢得多,而GPU计算则需要多出一次数据复制过程。查看 点云捕获过程 了解更多信息。
小技巧
For better performance, use the transform API together with the downsample and normals APIs. This ensures that all computations are performed by the GPU while the point cloud data remains in GPU memory.
为了最快地完成数据处理,可以先对点云进行降采样,然后对其进行转换。
在转换点云后计算法线,使得法线与点云在同一坐标系中。
如需了解更多有关位姿和转换的信息,请查看 位置、方向和坐标变换.
Transform in Zivid Studio
You can also apply transformations to the point clouds in Zivid Studio. After having captured, navigate to the Transform drop-down at the top of the current view. Among others, you can load a transformation matrix from file, set it to the coordinate system of the chosen ROI Box, and save the transformation matrix to file.

Transform drop-down menu in Zivid Studio
This allows you to visualize transformed point clouds in Zivid Studio, which can be useful when evaluating the point cloud quality. It also allows you to transform the point cloud to a chosen coordinate system, and save or export the transformed point cloud to file.
Point clouds are by default given in the camera coordinate system as in (a), but you can transform the point cloud to a more suitable coordinate system as in (b).
应用中的转换
本节将介绍使用点云转换功能的Zivid相机和机器人的应用。这里说明了这些应用中的典型坐标系以及为什么要将点云转换到这些坐标系里。
抓取
为了让机器人能够拾取在点云中检测到的物体,点云的坐标必须从相机坐标系转换到机器人可以理解的坐标系。
机器人坐标系
我们通常希望将对象坐标或整个点云转换到机器人基础坐标系。您可以从这篇文章了解详细说明 如何使用手眼标定的结果.

平面坐标系
相机通常与抓取面不平行。转换点云使点云z轴与平面z轴匹配有助于我们更好地理解和解析点云数据。因此,通常会将点云转换到抓取面所在的坐标系,例如料箱底层或传送带。

料箱坐标系
还有一个步骤可以帮助我们更好地理解点云数据并评估抓取表现。即将点云的x轴和y轴与料箱的x轴和y轴对齐。

感兴趣区域
相机视野通常大于我们的感兴趣区域 (ROI),例如料箱。因此,将料箱轴与点云轴对齐的另一个原因是它可以让我们在料箱周围设置一个ROI盒。然后,我们可以根据ROI裁剪点云,以仅获取料箱范围内的点。
小技巧
点云越小,捕获速度越快,从而可以加快检测速度并缩短总拾取周期时间。

如需了解实施示例,请查看 通过棋盘格定义的ROI盒 。该教程展示了如何使用 Zivid calibration board 根据相对于棋盘格给定的ROI盒来过滤点云。
我们还有一个 通过ArUco标记定义的ROI盒 教程,它使用了ArUco标记来代替棋盘格。
拼接
点云拼接通常涉及将点云转换到不同的坐标系。
多个固定安装的相机
Zivid 多相机标定 能够将来自多个相机的点云转换到其中一台相机(主相机)的坐标系中。在多相机标定中,我们通常希望将拼接后的点云转换到一个不同的坐标系中,比如对象坐标系。

单个手臂安装的相机
通过相机安装在手臂上的配置,您可以使用同一相机从多个角度拍摄多个点云用于拼接。一旦点云在主相机坐标系中完成拼接后,就可以方便地将其转换到对象坐标系。

单相机和转盘
如果我们知道转盘相对于相机的位姿,我们可以拼接点云并将它们转换到转盘坐标系。

位姿估计
获取相机相对于机器人基坐标系的位姿是通过 手眼标定 实现的。如果我们需要相对于任意用户定义的坐标系的位姿,我们可以在场景中放置标定对象,例如基准标记和棋盘格。由于我们知道它们的几何形状,因此估计它们的位姿相对简单。
关于实现该功能的示例,请查看 基于棋盘格的坐标转换。该教程说明了如何估计棋盘格的位姿并使用4x4齐次变换矩阵将点云转换到棋盘格坐标系。我们还有 基于ArUco标记的坐标转换 教程,该教程使用了ArUco标记代替棋盘格。
版本历史
SDK |
变更 |
---|---|
2.15.0 |
Transform in Zivid Studio is added, with API for getting the currently applied transformation matrix. |
2.0.0 |
添加了转换API。 |