ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange |
1 | initial version |
You need to set the header of your image message as shown below. The original code taken from your shared reference.
self.depth_pub.publish(self.bridge.cv2_to_imgmsg(cv_depth, encoding="16UC1", header=depth_data.header))
Once you set the header, please confirm it by executing the following command:
rostopic echo -n 1 /camera/aligned_depth_to_color/image_converted | head
Furthermore, please ensure the header values, such as frame_id
, etc., in the converted image are the same as in the raw image. For example, you can use the following command to see the header for the raw image:
rostopic echo -n 1 /camera/aligned_depth_to_color/image_raw | head
2 | No.2 Revision |
You need to set the header of your image message as shown below. The original code taken from your shared reference.
self.depth_pub.publish(self.bridge.cv2_to_imgmsg(cv_depth, encoding="16UC1", header=depth_data.header))
...
self.depth_sub = rospy.Subscriber("/camera/aligned_depth_to_color/image_raw", Image, self.callback)
def callback(self, depth_data):
try:
cv_depth = self.bridge.imgmsg_to_cv2(depth_data, "16UC1")
except CvBridgeError as e:
print(e)
(rows, cols) = cv_depth.shape
cv_depth[0:int(rows/2), 0:int(cols/2)] = 0
try:
updated_depth_msg = self.bridge.cv2_to_imgmsg(cv_depth, "16UC1")
updated_depth_msg.header = depth_data.header
except CvBridgeError as e:
print(e)
else:
self.depth_pub.publish(updated_depth_msg)
Once you set the header, please confirm it by executing the following command:
rostopic echo -n 1 /camera/aligned_depth_to_color/image_converted | head
Furthermore, please ensure the header values, such as frame_id
, etc., in the converted image are the same as in the raw image. For example, you can use the following command to see the header for the raw image:
rostopic echo -n 1 /camera/aligned_depth_to_color/image_raw | head