ROS2:Image topic has published but not receive
I am new to ROS2. I am doing a small demo that publishes an image captured by cv2 and subscribe to the topic in another terminal of the same machine. It worked well on my laptop but did not work on my IPC.
I am using ROS2 dashing. Below is the publisher node:
class ImagePublisher(Node):
def __init__(self, name):
super().__init__(name)
self.publisher_ = self.create_publisher(Image, "image_raw", 10)
self.timer = self.create_timer(0.1, self.timer_callback)
self.cap = cv2.VideoCapture(0)
self.cv_bridge = CvBridge()
def timer_callback(self):
ret, frame = self.cap.read()
if ret == True:
self.publisher_.publish(self.cv_bridge.cv2_to_imgmsg(frame, 'bgr8'))
self.get_logger().info('Publishing video frame...')
def main(args = None):
rclpy.init(args=args)
node = ImagePublisher("cam_pub")
rclpy.spin(node)
node.destroy_node()
rclpy.shutdown()
Below is the subscriber node:
class ImageSubscriber(Node):
def __init__(self, name):
super().__init__(name)
self.sub = self.create_subscription(Image, 'image_raw', self.listener_callback, 10)
self.cv_bridge = CvBridge()
def object_detect(self, image):
cv2.imshow("object", image)
cv2.waitKey(10)
def listener_callback(self, data):
self.get_logger().info('Receiving video frame')
image = self.cv_bridge.imgmsg_to_cv2(data, 'bgr8')
self.object_detect(image)
def main(args = None):
rclpy.init(args=args)
node = ImageSubscriber("cam_sub")
rclpy.spin(node)
node.destroy_node()
rclpy.shutdown()
In my IPC, when I was checking the code, I found that the "image_raw" topic is published successfully, but the subscription stuck in calling the listener_callback
.
Thank you in advance for helping me. Feel free to tell me if you need additional information.
Sorry, what is IPC? is it a PC?