Skip to content

Instantly share code, notes, and snippets.

@Martzi
Martzi / pcl_publisher.cpp
Created November 3, 2021 15:58
point cloud publisher
#include <ros/ros.h>
#include <cv_bridge/cv_bridge.h>
#include <image_transport/image_transport.h>
#include <sensor_msgs/Image.h>
#include <sensor_msgs/image_encodings.h>
#include <sensor_msgs/CameraInfo.h>
#include <sensor_msgs/PointCloud2.h>
def point_cloud_msg(points, parent_frame='base_link'):
ros_dtype = sensor_msgs.PointField.FLOAT32 # csak ezt eszi meg az rviz
dtype = np.float32
itemsize = np.dtype(dtype).itemsize
data = points.astype(dtype).tobytes()
fields = [sensor_msgs.PointField(
name=n, offset=i*itemsize, datatype=ros_dtype, count=1)