My understanding of communication between ROS (both 1 & 2) and DeepStream (python, really…not DS directly) has evolved a good bit since I originally posted here. My main goal was to be able to communicate object detection messages from DS to ROS1, but the only solid examples of DS-to-ROS communication I’d found were the ros2_deepstream repo.
The main difference between python / DS comms with ROS1 & ROS2 seems to be the use of either “rospy” or “rclpy”.
I’ve successfully tested basic communication between a ROS node & my own python code.
I’d already had DS python bindings-based code to run my object detection model. Based on parts of this function (ros2_deepstream/single_stream_class.py at main · NVIDIA-AI-IOT/ros2_deepstream · GitHub), I modified my code to send the {class, bounding box info, confidence} inference results to ROS1 using the “rospy” package. I believe the code is mostly correct (assuming the example linked above works…), but haven’t tested it yet due to the lack of having a container with both ROS1 & DS.
I just pulled the dustynv/ros:humble-ros-base-deepstream-l4t-r35.1.0 container and attempted to run an example from the ros2_deepstream repo.
Here is the input (as per directions here: GitHub - NVIDIA-AI-IOT/ros2_deepstream: ROS 2 package for NVIDIA DeepStream applications on Jetson Platforms) & output from inside the container:
mkdir -p ~/ros2_ws/src
cd ~/ros2_ws/src
git clone GitHub - NVIDIA-AI-IOT/ros2_deepstream: ROS 2 package for NVIDIA DeepStream applications on Jetson Platforms
colcon build
source /opt/ros/humble/install/setup.bash
. install/setup.bash
ros2 run single_stream_pkg single_stream --ros-args -p input_source:=“/dev/video0”
Traceback (most recent call last):
File “/root/ros2_ws/src/install/single_stream_pkg/lib/single_stream_pkg/single_stream”, line 33, in
sys.exit(load_entry_point(‘single-stream-pkg==0.0.0’, ‘console_scripts’, ‘single_stream’)())
File “/root/ros2_ws/src/install/single_stream_pkg/lib/single_stream_pkg/single_stream”, line 25, in importlib_load_entry_point
return next(matches).load()
File “/usr/lib/python3.8/importlib/metadata.py”, line 77, in load
module = import_module(match.group(‘module’))
File “/usr/lib/python3.8/importlib/init.py”, line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File “”, line 1014, in _gcd_import
File “”, line 991, in _find_and_load
File “”, line 975, in _find_and_load_unlocked
File “”, line 671, in _load_unlocked
File “”, line 848, in exec_module
File “”, line 219, in _call_with_frames_removed
File “/root/ros2_ws/src/install/single_stream_pkg/lib/python3.8/site-packages/single_stream_pkg/single_stream.py”, line 24, in
from single_stream_pkg.single_stream_class import InferencePublisher
File “/root/ros2_ws/src/install/single_stream_pkg/lib/python3.8/site-packages/single_stream_pkg/single_stream_class.py”, line 29, in
from vision_msgs.msg import Classification2D, ObjectHypothesis, ObjectHypothesisWithPose, BoundingBox2D, Detection2D, Detection2DArray
ImportError: cannot import name ‘Classification2D’ from ‘vision_msgs.msg’ (/opt/ros/humble/install/lib/python3.8/site-packages/vision_msgs/msg/init.py)
[ros2run]: Process exited with failure 1
So it appears that “vision_msgs” is installed, it just doesn’t contain the “Classification2D” name. I checked inside ptpython and these are the names available in vision_msgs:
BoundingBox2D
Detection2DArray
Pose2D
_bounding_box2_d
_detection2_d_array
_pose2_d
BoundingBox2DArray
Detection3D
VisionInfo
_bounding_box2_d_array
_detection3_d
_vision_info
BoundingBox3D
Detection3DArray
doc
_bounding_box3_d
_detection3_d_array
BoundingBox3DArray
ObjectHypothesis
file
_bounding_box3_d_array
_object_hypothesis
Classification
ObjectHypothesisWithPose
name
_classification
_object_hypothesis_with_pose
Detection2D
Point2D
package
_detection2_d
_point2_d
I attempted to upgrade the “vision_msgs” python package, but it was already up to date, so I’m not sure how to fix this issue…