简体   繁体   English

在 ROS 中使用 pcl 和 python

[英]Use pcl in ROS with python

I'm new to the ROS and i have a problem.我是 ROS 的新手,我有一个问题。

I'm trying to visualize a point cloud using pcl library.我正在尝试使用 pcl 库来可视化点云。 At first i start my ros-realsense camera typing in a terminal "roslaunch realsense2_camera rs_camera.launch filters:=pointcloud" Then, i have made a catkin package where i have a listener.py script where i subscribe to the realsense and i get the point cloud information that i want.首先,我开始我的 ros-realsense 相机,在终端中输入“roslaunch realsense2_camera rs_camera.launch filters:=pointcloud”然后,我制作了一个 catkin package,其中我有一个 listener.py 脚本,我订阅了 realsense,我得到了我想要的点云信息。 So far so good.到目前为止,一切都很好。 Now i want to visualize this point cloud using the PCL library but when i run my package "rosrun pcl listener.py" i get the error现在我想使用 PCL 库可视化这个点云但是当我运行我的 package “rosrun pcl listener.py”时我得到了错误

import pcl ImportError: No module named pcl

So my question is what do i miss?所以我的问题是我想念什么? How do i import the pcl in a ros package?如何在 ros package 中导入 pcl? Do i have to add something on the CMakeLists.txt or/and package.xml?我是否必须在 CMakeLists.txt 或/和 package.xml 上添加一些内容?

I include my listener.py script.我包括了我的 listener.py 脚本。

#!/usr/bin/env python
import rospy
import pcl
import ros_numpy
import sensor_msgs.point_cloud2 as pc2
from sensor_msgs.msg import PointCloud2

def callback_ptclud(ptcloud_data):
    pc = ros_numpy.numpify(data)
    points=np.zeros((pc.shape[0],3))
    points[:,0]=pc['x']
    points[:,1]=pc['y']
    points[:,2]=pc['z']
    p = pcl.PointCloud(np.array(points, dtype=np.float32))

def listener():
    rospy.Subscriber("/camera/depth/color/points", PointCloud2, callback_ptclud)
    rospy.spin()

if __name__ == '__main__':
    rospy.init_node("realsense_subscriber", anonymous=True)
    listener()

Thank you in advance Any help is appreciated提前谢谢您 任何帮助表示赞赏

About the pcl the most easiest way is to use it with C++.关于 pcl,最简单的方法是与 C++ 一起使用。 Its easy to install and there are a lot of documentations and examples.它易于安装,并且有很多文档和示例。 About the python_pcl for some reason its not easy to install (at least for me).关于 python_pcl 出于某种原因它不容易安装(至少对我来说)。 What i did to use it was to download the library, put it somewhere in my pc and when i want to use it in my scripts i just import the absolute path of pcl.我使用它所做的是下载库,将它放在我的电脑中的某个位置,当我想在我的脚本中使用它时,我只需导入 pcl 的绝对路径。

By downloading the python_pcl files i mean find and download the init.py, _pcl.py, _pcl.so and all the necessary files of the library.通过下载 python_pcl 文件,我的意思是找到并下载 init.py、_pcl.py、_pcl.so 和库的所有必要文件。

For example in my python scripts i use:例如,在我的 python 脚本中,我使用:

import sys
sys.path.append('~/path_to_downloaded_pcl') "it will find the __init__.py"
import pcl

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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