-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathshow.py
executable file
·44 lines (34 loc) · 1.12 KB
/
show.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
41
42
43
#!/usr/bin/env python3
import numpy
import rclpy
from rclpy.node import Node
from std_msgs.msg import String
from sensor_msgs.msg import Image
import cv2
import cv_bridge
from rclpy.qos import QoSProfile, QoSReliabilityPolicy, QoSHistoryPolicy, QoSPresetProfiles, qos_profile_system_default
import sys
class MinimalSubscriber(Node):
def __init__(self):
super().__init__('camera_viewer')
qos_profile = QoSProfile(
reliability=QoSReliabilityPolicy.RMW_QOS_POLICY_RELIABILITY_BEST_EFFORT,
history=QoSHistoryPolicy.RMW_QOS_POLICY_HISTORY_KEEP_LAST,
depth=1
)
self.subscription = self.create_subscription(
Image,
sys.argv[1],
self.listener_callback,
qos_profile)
self.bridge = cv_bridge.CvBridge()
def listener_callback(self, msg):
img = self.bridge.imgmsg_to_cv2(msg, "bgr8")
cv2.imshow("img", img)
cv2.waitKey(1)
def main(args=None):
rclpy.init(args=args)
minimal_subscriber = MinimalSubscriber()
rclpy.spin(minimal_subscriber)
if __name__ == '__main__':
main()