Skip to main content

Tools for converting ROS messages to and from numpy arrays.

Project description

ros_numpy

Note: This is the same as the original ros_numpy package by eric-wieser just edited to be OS independent and installable using pip. Loosely tested, but works perfectly on Windows and Ubuntu for "numpifying" PointCloud2 and Image messages from bag files.

Install using:

pip install rosnumpy

Quick Start

PointCloud2 msg to Numpy array:

import ros_numpy
import sensor_msgs

def get_pc_from_ros_pc2_msg(msg):
    """ Returns point-cloud as a structured numpy array. 
    Note: can be used with any topic of message type 'sensor_msgs/PointCloud2'
    """
    msg.__class__ = sensor_msgs.msg.PointCloud2
    return ros_numpy.numpify(msg)

pc_array =  get_pc_from_pc2_msg(msg)

Image msg to Numpy array:

import ros_numpy
import sensor_msgs

def get_img_from_ros_image_msg(msg):
    """ Returns image as a numpy array. 
    Note: can be used with any topic of message type 'sensor_msgs/Image'
    """
    msg.__class__ = sensor_msgs.msg.Image
    return ros_numpy.numpify(msg)

img_array =  get_img_from_ros_image_msg(msg)

The (msg) in previous examples is coming from here:

import rosbag

bag_path = r'path to .bag file here'
bag = rosbag.Bag(bag_path)
for topic, msg, t in bag.read_messages(topics=['/PointCloud2_topic_here']):
    pc_array =  get_pc_from_pc2_msg(msg)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

rosnumpy-0.0.6.2.tar.gz (24.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

rosnumpy-0.0.6.2-py3-none-any.whl (24.3 kB view details)

Uploaded Python 3

File details

Details for the file rosnumpy-0.0.6.2.tar.gz.

File metadata

  • Download URL: rosnumpy-0.0.6.2.tar.gz
  • Upload date:
  • Size: 24.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.8.10

File hashes

Hashes for rosnumpy-0.0.6.2.tar.gz
Algorithm Hash digest
SHA256 17ff607c586c73e9f92c8c5d498a54223bc0dedb2df386b643a17c1a81e73efe
MD5 931ce949ece575f669723505f3bfe621
BLAKE2b-256 2787964fa875d47cd8e305498ad408af69cbf7b55accc2224a3fe1aae3aef84f

See more details on using hashes here.

File details

Details for the file rosnumpy-0.0.6.2-py3-none-any.whl.

File metadata

  • Download URL: rosnumpy-0.0.6.2-py3-none-any.whl
  • Upload date:
  • Size: 24.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.8.10

File hashes

Hashes for rosnumpy-0.0.6.2-py3-none-any.whl
Algorithm Hash digest
SHA256 94a8108f403a7c806eb7f0faec672c4c6a3045d0326e07c1b73cc7d39c9b55f8
MD5 fc03f0f33b1335b178d365749ce75822
BLAKE2b-256 7ecac6fe62b77f7d96ad6ddeafd6d179deb69a658c4398790e802bac0d792958

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page