From 989e56a4835b03ffc15cc7780573cfc7f333ab3a Mon Sep 17 00:00:00 2001 From: RobinSchmid7 Date: Wed, 16 Aug 2023 12:41:01 +0200 Subject: [PATCH 1/2] Fix instance detection ros image --- .../src/wild_visual_navigation_ros/ros_converter.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/wild_visual_navigation_ros/src/wild_visual_navigation_ros/ros_converter.py b/wild_visual_navigation_ros/src/wild_visual_navigation_ros/ros_converter.py index d1de3ba4..c2c0b7b0 100644 --- a/wild_visual_navigation_ros/src/wild_visual_navigation_ros/ros_converter.py +++ b/wild_visual_navigation_ros/src/wild_visual_navigation_ros/ros_converter.py @@ -106,10 +106,10 @@ def ros_tf_to_torch(tf_pose, device="cpu"): def ros_image_to_torch(ros_img, desired_encoding="rgb8", device="cpu"): - if isinstance(ros_img, Image): + if type(ros_img).__name__ is "_sensor_msgs__Image": np_image = CV_BRIDGE.imgmsg_to_cv2(ros_img, desired_encoding=desired_encoding) - elif isinstance(ros_img, CompressedImage): + elif type(ros_img).__name__ is "_sensor_msgs__CompressedImage": np_arr = np.fromstring(ros_img.data, np.uint8) np_image = cv2.imdecode(np_arr, cv2.IMREAD_COLOR) if "bgr" in ros_img.format: From 7f9b2b3cdbad255d925879e85d8db591f300a419 Mon Sep 17 00:00:00 2001 From: RobinSchmid7 Date: Wed, 23 Aug 2023 11:26:13 +0200 Subject: [PATCH 2/2] Added both options --- .../src/wild_visual_navigation_ros/ros_converter.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/wild_visual_navigation_ros/src/wild_visual_navigation_ros/ros_converter.py b/wild_visual_navigation_ros/src/wild_visual_navigation_ros/ros_converter.py index c2c0b7b0..ec88906f 100644 --- a/wild_visual_navigation_ros/src/wild_visual_navigation_ros/ros_converter.py +++ b/wild_visual_navigation_ros/src/wild_visual_navigation_ros/ros_converter.py @@ -106,6 +106,7 @@ def ros_tf_to_torch(tf_pose, device="cpu"): def ros_image_to_torch(ros_img, desired_encoding="rgb8", device="cpu"): + # Use for replaying bag with BagTfTransformer package if type(ros_img).__name__ is "_sensor_msgs__Image": np_image = CV_BRIDGE.imgmsg_to_cv2(ros_img, desired_encoding=desired_encoding) @@ -114,6 +115,17 @@ def ros_image_to_torch(ros_img, desired_encoding="rgb8", device="cpu"): np_image = cv2.imdecode(np_arr, cv2.IMREAD_COLOR) if "bgr" in ros_img.format: np_image = cv2.cvtColor(np_image, cv2.COLOR_BGR2RGB) + + # Used for replaying with rosbags via terminal + elif isinstance(ros_img, Image): + np_image = CV_BRIDGE.imgmsg_to_cv2(ros_img, desired_encoding=desired_encoding) + + elif isinstance(ros_img, CompressedImage): + np_arr = np.fromstring(ros_img.data, np.uint8) + np_image = cv2.imdecode(np_arr, cv2.IMREAD_COLOR) + if "bgr" in ros_img.format: + np_image = cv2.cvtColor(np_image, cv2.COLOR_BGR2RGB) + return TO_TENSOR(np_image).to(device)