forked from PalouseRobosub/vision_dev
-
Notifications
You must be signed in to change notification settings - Fork 0
/
publish_directory.py
40 lines (31 loc) · 1.08 KB
/
publish_directory.py
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
35
36
37
38
39
40
#!/usr/bin/python
import argparse
import cv2
import glob
import sys
import rospy
from sensor_msgs.msg import Image
import cv_bridge
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('dir')
parser.add_argument('--rate', type=float, default=5,
help='The rate at which to publish images.')
parser.add_argument('--regex', default='left_*.png', type=str,
help='The file regex to match for playback.')
parser.add_argument('--topic', type=str, default='camera/left/undistorted',
help='The topic to publish images to.')
args = parser.parse_args()
rospy.init_node('image_publisher')
pub = rospy.Publisher(args.topic, Image, queue_size=10)
bridge = cv_bridge.CvBridge()
r = rospy.Rate(args.rate)
names = glob.glob('{}/left_*.png'.format(args.dir))
names.sort()
for fname in names:
rospy.loginfo('Publishing {}'.format(fname))
img = cv2.imread(fname)
pub.publish(bridge.cv2_to_imgmsg(img, 'bgr8'))
r.sleep()
if rospy.is_shutdown():
break