-
Notifications
You must be signed in to change notification settings - Fork 0
/
showRosImage
executable file
·45 lines (39 loc) · 1.45 KB
/
showRosImage
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
41
42
43
44
45
#!/usr/bin/env python
import rospy
import cv2
import numpy as np
from sensor_msgs.msg import Image
from cv_bridge import CvBridge, CvBridgeError
import argparse
class image_converter:
def __init__(self, topic):
self.topic = topic
self.windowNameOrig = "Camera: {0}".format(self.topic)
self.bridge = CvBridge()
self.image_sub = rospy.Subscriber(self.topic, Image, self.callback)
def callback(self, msg):
#convert image to opencv
try:
cv_image = self.bridge.imgmsg_to_cv2(msg, "bgr8")
timestr = "%.6f" % msg.header.stamp.to_sec()
print(timestr)
print(cv_image.shape)
cv2.imwrite("1.png", cv_image)
cv2.namedWindow(self.windowNameOrig, 2)
cv2.imshow(self.windowNameOrig,cv_image)
cv2.waitKey(1)
except CvBridgeError, e:
print ("Could not convert ros message to opencv image: ", e)
return
if __name__ == "__main__":
parser = argparse.ArgumentParser(description='Validate the intrinsics of a camera.')
parser.add_argument('--topic', nargs='+', dest='topics', help='camera topic', required=True)
parsed = parser.parse_args()
for topic in parsed.topics:
camval = image_converter(topic)
rospy.init_node('kalibr_validator', anonymous=True)
try:
rospy.spin()
except KeyboardInterrupt:
print "Shutting down"
cv2.DestroyAllWindows()