Skip to content

Instantly share code, notes, and snippets.

@Merwanski
Last active November 23, 2022 21:14
Show Gist options
  • Save Merwanski/bc20707fc9be72687edaade0b9c3aaa6 to your computer and use it in GitHub Desktop.
Save Merwanski/bc20707fc9be72687edaade0b9c3aaa6 to your computer and use it in GitHub Desktop.
talker text image py ros publisher
#!/usr/bin/env python3
import rospy
import cv2
from std_msgs.msg import String
from sensor_msgs.msg import Image
from cv_bridge import CvBridge
bridge = CvBridge()
def talker():
pubText = rospy.Publisher('textROS', String, queue_size=10)
pubImage = rospy.Publisher('imageROS', Image, queue_size=10)
imagecv2 = cv2.imread("image.jpg")
image2pub = bridge.cv2_to_imgmsg(imagecv2, encoding='passthrough')
image2pub.header.frame_id = "image_color_to_publish"
rospy.init_node('talker', anonymous=True)
rate = rospy.Rate(10) #1Hz
while not rospy.is_shutdown():
hello_str = "%s" % rospy.get_time()
rospy.loginfo(hello_str)
pubText.publish(hello_str)
pubImage.publish(image2pub)
rate.sleep()
if __name__ == "__main__":
try:
talker()
except rospy.ROSInterruptException:
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment