简体   繁体   中英

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> .

The problem is that pcl::PointXYZ consists of 4 floats (x, y, z, padding) while cv::Point3f only has 3 floats (x, y, z). If they were both just 3 floats I could do a simple pointer cast of the data buffer.

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)?

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:

std::vector<cv::Point3f> points;

for (const auto& point : cloud) {
    points.push_back(cv::Point3f(point.x, point.y, point.z));
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM