1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
| import cv2 import rospy from sensor_msgs.msg import Image from cv_bridge import CvBridge, CvBridgeError
rospy.init_node('video_publisher', anonymous=True)
video_pub = rospy.Publisher('video_stream', Image, queue_size=10)
cap = cv2.VideoCapture('rtsp://admin:qwer1234!.@192.168.1.67:554')
bridge = CvBridge()
while not rospy.is_shutdown(): ret, frame = cap.read()
try: ros_image = bridge.cv2_to_imgmsg(frame, "bgr8") except CvBridgeError as e: rospy.logerr(e)
video_pub.publish(ros_image)
cap.release() rospy.shutdown()
|