From e63d6290565af3f2963593a1a9e0eae9bea80f30 Mon Sep 17 00:00:00 2001 From: Ryohei Ueda Date: Thu, 12 Feb 2015 14:31:13 +0900 Subject: [PATCH] [jsk_perception] Add simple script to publish image file into ros image --- jsk_perception/scripts/image_publisher.py | 24 +++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100755 jsk_perception/scripts/image_publisher.py diff --git a/jsk_perception/scripts/image_publisher.py b/jsk_perception/scripts/image_publisher.py new file mode 100755 index 0000000000..017b8e176e --- /dev/null +++ b/jsk_perception/scripts/image_publisher.py @@ -0,0 +1,24 @@ +#!/usr/bin/env python + +import rospy +from sensor_msgs.msg import Image +import cv2 +import cv_bridge + +rospy.init_node("image_publisher") + +rate = rospy.Rate(rospy.get_param("rate", 1)) +file_name = rospy.get_param("~file_name", "image.png") +pub = rospy.Publisher("~output", Image) +bridge = cv_bridge.CvBridge() +while not rospy.is_shutdown(): + try: + image = cv2.imread(file_name) + image_message = bridge.cv2_to_imgmsg(image, encoding="bgr8") + image_message.header.stamp = rospy.Time.now() + pub.publish(image_message) + except Exception, e: + rospy.loginfo("cannot read the image at %s" % file_name) + rospy.loginfo(e.message) + rate.sleep() +