I am a newbie to point cloud processing. I am trying to align the lidar point cloud with the image data captured by a camera that has been synchronized to the lidar. As a first step, I would like to render my lidar pointcloud using script below but not update it. viewer-> spin() does not seem to be work. Any help will be appreciated.
typedef pcl::PointCloud<pcl::PointXYZ> PointCloud;
static const std::string OPENCV_WINDOW = "Image window";
using namespace sensor_msgs;
using namespace message_filters;
void callback(const ImageConstPtr& image1, 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);
pcl::visualization::CloudViewer viewer ("Simple Cloud Viewer");
viewer.showCloud(temp_cloud);
while (!viewer.wasStopped ())
{
}
}
int main(int argc, char** argv)
{
ros::init(argc, argv, "vision_node");
ros::NodeHandle nh;
message_filters::Subscriber<Image> image1_sub(nh, "/pylon_camera_node/image_rect_color", 1);
message_filters::Subscriber<sensor_msgs::PointCloud2> lidar_sub(nh, "/os1_cloud_node/points", 1);
typedef sync_policies::ApproximateTime<Image, PointCloud2> MySyncPolicy;
Synchronizer<MySyncPolicy> sync(MySyncPolicy(10), image1_sub, lidar_sub);
sync.registerCallback(boost::bind(&callback, _1, _2));
ros::spin();
return 0;
}
rostopic echo
? BTW, you are not showing the code where you subscribe to updates. In fact it seems that you are spinning inside the callback that should be called by the subscriber. If that is so, then you won't receive new data, because you are blocking. Can you add your subscriber code, then we can show you where to put the spin/while? – Christian Fritz