Skip to content

Instantly share code, notes, and snippets.

@Kyungpyo-Kim
Created April 30, 2018 06:07
Show Gist options
  • Save Kyungpyo-Kim/b0cd1528913cb36bab6779a384dd2021 to your computer and use it in GitHub Desktop.
Save Kyungpyo-Kim/b0cd1528913cb36bab6779a384dd2021 to your computer and use it in GitHub Desktop.
PCL, ROS, sensor_msgs::PointCloud2 to PCL type
#include <pcl_conversions/pcl_conversions.h>
#include <pcl/point_types.h>
#include <pcl/PCLPointCloud2.h>
#include <pcl/conversions.h>
#include <pcl_ros/transforms.h>
void cloud_cb(const boost::shared_ptr<const sensor_msgs::PointCloud2>& input){
pcl::PCLPointCloud2 pcl_pc2;
pcl_conversions::toPCL(*input,pcl_pc2);
pcl::PointCloud<pcl::PointXYZ>::Ptr temp_cloud(new pcl::PointCloud<pcl::PointXYZ>);
pcl::fromPCLPointCloud2(pcl_pc2,*temp_cloud);
//do stuff with temp_cloud here
}
// Reference
/*
/* https://answers.ros.org/question/136916/conversion-from-sensor_msgspointcloud2-to-pclpointcloudt/
*/
@aaryanmurgunde
Copy link

Is there a way that you know in which I can merge 2 ordered sensor_msgs::PointCloud2, what I'm trying to do is merge 2 camera depth streams to form a superPointCloud that I can generate octomap from

@Pran-Seven
Copy link

@aaryanmurgunde did you find a solution? I am trying to do the same

@aaryanmurgunde
Copy link

@Pran-Seven simple solution would be to connect all of them to a base link, use the approximate sync message filter to sync the pointclouds and then use PCL function to convert the pointclouds from the cams frame to base link frame and publish a message.
This is what I'am currently trying to do

@Pran-Seven
Copy link

I was able to do that, but the resulting pointcloud is unordered and I would need an ordered pointcloud for further processing after the merge.

@aaryanmurgunde
Copy link

aaryanmurgunde commented Oct 10, 2022

@Pran-Seven can you share the code
also what is it that you are trying to after the merge

@Pran-Seven
Copy link

Hey, my code is loosely based on this very good nodelet, to match my exact needs I modified it to include PCL ICP iterations after transforming the pointclouds to the base link and then adding/concatenating the resultant aligned pointcloud and the original other pointcloud. Would be happy to correspond more over this via a different medium, perhaps mail?

@aaryanmurgunde
Copy link

@Pran-Seven Try out my repository and see if you get the expected result https://github.com/aaryanmurgunde/pointcloud2_merge

Here in the main branch launch file just change the topic names that you are getting pointclouds from and the frame that you want them in.
It supports 2 - 8 pointcloud merge

@Pran-Seven
Copy link

Hey, thanks a lot for the repo, but I need pointcloud stitching to be specfic and not just merge. My code works as expected only issue being the point cloud becomes unordered in the end leading to difficulties in using various pcl algorithms, trying to find workarounds for that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment