-
Notifications
You must be signed in to change notification settings - Fork 64
/
Copy pathgetStereoImages.py
61 lines (46 loc) · 1.47 KB
/
getStereoImages.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
import numpy as np
import cv2
import glob
import argparse
import sys
# Set the values for your cameras
capL = cv2.VideoCapture(1)
capR = cv2.VideoCapture(0)
# Use these if you need high resolution.
# capL.set(3, 1024) # width
# capL.set(4, 768) # height
# capR.set(3, 1024) # width
# capR.set(4, 768) # height
i = 0
def main():
global i
if len(sys.argv) < 3:
print("Usage: ./program_name directory_to_save start_index")
sys.exit(1)
i = int(sys.argv[2]) # Get the start number.
while True:
# Grab and retreive for sync
if not (capL.grab() and capR.grab()):
print("No more frames")
break
_, leftFrame = capL.retrieve()
_, rightFrame = capR.retrieve()
# Use if you need high resolution. If you set the camera for high res, you can pass these.
# cv2.namedWindow('capL', cv2.WINDOW_NORMAL)
# cv2.resizeWindow('capL', 1024, 768)
# cv2.namedWindow('capR', cv2.WINDOW_NORMAL)
# cv2.resizeWindow('capR', 1024, 768)
cv2.imshow('capL', leftFrame)
cv2.imshow('capR', rightFrame)
key = cv2.waitKey(1)
if key == ord('q'):
break
elif key == ord('c'):
cv2.imwrite(sys.argv[1] + "/left" + str(i) + ".png", leftFrame)
cv2.imwrite(sys.argv[1] + "/right" + str(i) + ".png", rightFrame)
i += 1
capL.release()
capR.release()
cv2.destroyAllWindows()
if __name__ == '__main__':
main()