将点云的坐标转换为点云库中的另一个坐标,从而使地平面成为X-O-Y平面?

Transform point cloud's coordinates to another coordinates in Point Cloud Library, which makes the ground plane as the X-O-Y plane?

本文关键字:坐标 平面 X-O-Y 另一个 转换      更新时间:2023-10-16

我有一个来自kinect融合的点云,并使用点云库成功地分割了地平面(a x+by+c*z+d=0)(我在pcl::ModelCoefficients中得到了a,b,c,d)。现在我需要将笛卡尔坐标转换为新的笛卡尔坐标,使地平面成为 X-O-Y 平面(0*x+0*y+z=0)。我想我可以通过这个 API 做到这一点(但我不知道怎么做):http://docs.pointclouds.org/trunk/group__common.html#transformPointCloud

我的回答:看看这个 PCL api:http://docs.pointclouds.org/1.7.2/a02405.html#ga4375e99ec2ae368eec9379f506568611

我成功解决了这个问题!

我无法打开指向您的 API 的链接,但猜测您可以使用简单的转换来转换您的平面:

  1. 您应该添加到所有点向量 {a * d, b * d, c * d} -将您的点移动到平面 ax + x + cz = 0
  2. 然后你应该找到围绕轴的旋转矩阵 [{a, b, c} 十字{0, 0, 1}]在角度 [{a, b, c} 点 {0, 0, 1}] 上并变换您的此矩阵的点数http://www.euclideanspace.com/maths/geometry/rotations/conversions/angleToMatrix-在这里您可以看到如何从轴和角度找到旋转矩阵

此函数需要相机姿势,这是一个 4x4 矩阵,形式为

| R   t |
| 0   1 |
这里,R 是 3x3

旋转矩阵,t 是 3x1 平移向量,0 - 是 1x3 的零向量,1 是单位(标量)。

您应该以这样的方式设计此矩阵,即新坐标系中的 Z 轴将与平面的法线矢量共线。新的 X 轴和 Y 轴是任意的,唯一的限制是它们必须形成正交基。

此链接说明如何派生矩阵 R。

现在,我遇到了这个问题。我想将点云投影到 XY 平面、YZ 平面和 XZ 平面。最后,答案可以在此页面中找到:https://pcl.readthedocs.io/projects/tutorials/en/latest/project_inliers.html?highlight=ModelCoefficients:

在本教程中,我们将学习如何将点投影到参数化模型(例如,平面、球体等)上。参数模型通过一组系数给出 – 在平面的情况下,通过其方程:ax + by + cz + d = 0。避免页面丢失,复制代码如下:

#include <iostream>
#include <pcl/io/pcd_io.h>
#include <pcl/point_types.h>
#include <pcl/ModelCoefficients.h>
#include <pcl/filters/project_inliers.h>
int
 main (int argc, char** argv)
{
  pcl::PointCloud<pcl::PointXYZ>::Ptr cloud (new pcl::PointCloud<pcl::PointXYZ>);
  pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_projected (new pcl::PointCloud<pcl::PointXYZ>);
  // Fill in the cloud data
  //We then create the point cloud structure, fill in the respective values,        and display the content on screen.
  cloud->width  = 5;
  cloud->height = 1;
  cloud->points.resize (cloud->width * cloud->height);
  for (auto& point: *cloud)
  {
    point.x = 1024 * rand () / (RAND_MAX + 1.0f);
    point.y = 1024 * rand () / (RAND_MAX + 1.0f);
    point.z = 1024 * rand () / (RAND_MAX + 1.0f);
  }
  std::cerr << "Cloud before projection: " << std::endl;
  for (const auto& point: *cloud)
    std::cerr << "    " << point.x << " "
                        << point.y << " "
                        << point.z << std::endl;
  // Create a set of planar coefficients with X=Y=0,Z=1
  //We fill in the ModelCoefficients values. In this case, we use a plane model, with ax+by+cz+d=0, where a=b=d=0, and c=1, or said differently, the X-Y plane.
  pcl::ModelCoefficients::Ptr coefficients (new pcl::ModelCoefficients ());
  coefficients->values.resize (4);
  coefficients->values[0] = coefficients->values[1] = 0;
  coefficients->values[2] = 1.0;
  coefficients->values[3] = 0;
  // Create the filtering object
  //We create the ProjectInliers object and use the ModelCoefficients defined above as the model to project onto.
  pcl::ProjectInliers<pcl::PointXYZ> proj;
  proj.setModelType (pcl::SACMODEL_PLANE);
  proj.setInputCloud (cloud);
  proj.setModelCoefficients (coefficients);
  proj.filter (*cloud_projected);
  std::cerr << "Cloud after projection: " << std::endl;
  for (const auto& point: *cloud_projected)
    std::cerr << "    " << point.x << " "
                        << point.y << " "
                        << point.z << std::endl;
  return (0);
}

以上代码来自PCL网站。