-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathkinect_getData.py
81 lines (51 loc) · 1.46 KB
/
kinect_getData.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
"""
"""
import rospy
import time
import cv2
from sensor_msgs.msg import Image, PointCloud2
from std_msgs.msg import UInt8
from cv_bridge import CvBridge, CvBridgeError
#Global
num_images = 3
interval = 0.5
#last_response is for RGB and last_response1 is for depth
last_response = time.time()
last_response1 = time.time()
RGB_Topic = '/camera/rgb/image_color'
Depth_Topic = '/camera/depth_registered/points'
def callback_rgb(msg):
"""
Arguments:
msg: The message from the topic
Returns: None
Saves the latest published RGB image after every interval
"""
#print("Callback successful!")
global last_response
if(time.time() - last_response > interval):
print("Success1!")
cv2_img = bridge.imgmsg_to_cv2(msg, "bgr8")
cv2.imwrite('KinectResults/RGB.jpg', cv2_img)
last_response = time.time()
def callback_depth(msg):
"""
Arguments:
msg: The message from the topic
Returns: None
Saves the latest published RGB image after every interval
"""
#print("Callback successful!")
global last_response1
if(time.time() - last_response1 > interval):
print("Success2!")
#CORRECT THIS PART
cv2_img = bridge.imgmsg_to_cv2(msg, "bgr8")
cv2.imwrite('KinectResults/Depth.jpg', cv2_img)
last_response1 = time.time()
rospy.init_node('Vision')
bridge = CvBridge()
sub_rgb = rospy.Subscriber(RGB_Topic, Image, callback_rgb)
#Import required msg type and change from Image
sub_depth = rospy.Subscriber(Depth_Topic, Image, callback_depth)
rospy.spin()