pypcd
pypcd copied to clipboard
ROS2 supported?
I'm try to use 'pypcd' from ROS2 (colcon build passes with small modifications)
However I got the following error in 'numpy_pc2.py' (see below for details) when trying to run a simple ROS2 python file 'xxx.py' (included below)
TypeError: fromstring() argument 1 must be read-only bytes-like object, not array.array
I'm using the ascii/binary (not compressed) pcd data from here : https://drive.google.com/drive/folders/11PkiTw2ZXh1KaXzBlsjYgT4chPIcsOgJ
Any ideas what the problem could be? thanks in advance for any/all help.
run
root@jupiter:~/rosbag_to_pcd# python3 xxx.py
<class 'sensor_msgs.msg._point_cloud2.PointCloud2'>
Traceback (most recent call last):
File "xxx.py", line 20, in <module>
npc = pypcd.PointCloud.from_msg(msg)
File "/root/rosbag_to_pcd/ros2_ws/install/pypcd/lib/python3.8/site-packages/pypcd/pypcd.py", line 827, in from_msg
pc_array = numpy_pc2.pointcloud2_to_array(msg)
File "/root/rosbag_to_pcd/ros2_ws/install/pypcd/lib/python3.8/site-packages/pypcd/numpy_pc2.py", line 134, in pointcloud2_to_array
cloud_arr = np.fromstring(cloud_msg.data, dtype_list)
TypeError: fromstring() argument 1 must be read-only bytes-like object, not array.array
root@jupiter:~/rosbag_to_pcd#
file: xxx.py
import pypcd
from pypcd import pypcd
import rclpy
from rclpy.node import Node
from rclpy.qos import QoSProfile
from sensor_msgs.msg import PointCloud2
rclpy.init()
qos_profile = QoSProfile(depth=10)
node = Node("msg_publisher")
pub = node.create_publisher(PointCloud2, "/to_pcd", qos_profile=qos_profile)
fn = "foo.pcd"
fn = "x.data/pcd_files/0000000040_ascii.pcd"
out_fn = f"{fn}.msg.pcd"
pc =pypcd.PointCloud.from_path(fn)
msg = pc.to_msg()
print(type(msg))
npc = pypcd.PointCloud.from_msg(msg)
npc.save(out_fn)
print(type(npc))
if 0 :
pub.publish(msg)
rclpy.spin(node)
node.destroy_node()
rclpy.shutdown()
I could fixed the problem above as follows :
numpy_pc2.py:134
before (NG) :
cloud_arr = np.fromstring(cloud_msg.data, dtype_list)
after (OK) :
cloud_arr = np.fromstring(cloud_msg.data.tobytes(), dtype_list)
Can you explain this script, what do you do here?
Im just looking for a snippet that makes pointcloud to bag file so I was wondering if you use pcd data and turn it to bag file here