[英]Quick conversion of pcl::PointCloud<PointXYZ> to std::vector<cv::Point3f> using no iteration
I'm looking for a quick way to convert a PCL point cloud of type pcl::PointCloud<PointXYZ>
to std::vector<cv::Point3f>
. 我正在寻找一种将
pcl::PointCloud<PointXYZ>
类型的PCL点云转换为std::vector<cv::Point3f>
。
The problem is that pcl::PointXYZ
consists of 4 floats (x, y, z, padding) while cv::Point3f
only has 3 floats (x, y, z). 问题在于
pcl::PointXYZ
包含4个浮点数(x,y,z,padding),而cv::Point3f
仅包含3个浮点数(x,y,z)。 If they were both just 3 floats I could do a simple pointer cast of the data buffer. 如果它们都是3个浮点数,我可以对数据缓冲区进行简单的指针转换。
So, the underlying question basically is: how to convert an array of structs with 4 floats into an array of structs with 3 floats without using iteration (ie for loops)? 因此,基本的问题基本上是:如何在不使用迭代的情况下(即for循环)将具有4个浮点数的结构数组转换为具有3个浮点数的结构数组?
If you have some point cloud pcl::PointCloud<pcl::PointXYZ> cloud
and you want to create a vector of points containing the OpenCV type cv::Point3f
just use range-based for loop like that: 如果您有一些点云
pcl::PointCloud<pcl::PointXYZ> cloud
并且您想创建一个包含OpenCV类型cv::Point3f
的点向量, cv::Point3f
可以使用基于范围的for循环,如下所示:
std::vector<cv::Point3f> points;
for (const auto& point : cloud) {
points.push_back(cv::Point3f(point.x, point.y, point.z));
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.