-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathextract_stereo.py
52 lines (43 loc) · 1.28 KB
/
extract_stereo.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
#!/usr/bin/env python
import cv2
import sys
import numpy as np
import sys, time
# numpy and scipy
import numpy as np
from scipy.ndimage import filters
# OpenCV
import cv2
# Ros libraries
import roslib
import rospy
# Ros Messages
from sensor_msgs.msg import CompressedImage
def main():
cap = cv2.VideoCapture(int(sys.argv[1]))
cap.set(cv2.CAP_PROP_CONVERT_RGB, False)
rospy.init_node('image_feature', anonymous=True)
image_pub_left = rospy.Publisher("/camera/left/compressed",CompressedImage,queue_size=10)
image_pub_right = rospy.Publisher("/camera/right/compressed",CompressedImage,queue_size=10)
rate = rospy.Rate(10)
while not rospy.is_shutdown():
ret,frame = cap.read()
left = frame[:,:,0]
right = frame[:,:,1]
#### Create CompressedIamge ####
msg_left = CompressedImage()
msg_right = CompressedImage()
msg_left.header.stamp = rospy.Time.now()
msg_right.header.stamp = rospy.Time.now()
msg_left.format = "jpeg"
msg_right.format = "jpeg"
msg_left.data = np.array(cv2.imencode('.jpg', left)[1]).tostring()
msg_right.data = np.array(cv2.imencode('.jpg', right)[1]).tostring()
# Publish new image
image_pub_left.publish(msg_left)
image_pub_right.publish(msg_right)
rate.sleep()
#cv2.imshow("left",left)
#cv2.imshow("right",right)
#cv2.waitKey(1)
main()