-
Notifications
You must be signed in to change notification settings - Fork 0
/
004_capture.py
76 lines (59 loc) · 2.12 KB
/
004_capture.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
import cv2
import math
import time
import numpy as np
n = 100000
time1 = np.zeros((n,1))
time2 = np.zeros((n,1))
# open device
camera1 = cv2.VideoCapture('v4l2src device=/dev/video0 io-mode=2 ! image/jpeg, width=(int)1920, height=(int)1080 ! jpegdec ! video/x-raw ! videoconvert ! video/x-raw,format=BGR ! appsink', cv2.CAP_GSTREAMER)
camera2 = cv2.VideoCapture('v4l2src device=/dev/video1 io-mode=2 ! image/jpeg, width=(int)1920, height=(int)1080 ! jpegdec ! video/x-raw ! videoconvert ! video/x-raw,format=BGR ! appsink', cv2.CAP_GSTREAMER)
if not (camera1.isOpened()):
print("Could not open camera 1")
if not (camera2.isOpened()):
print("Could not open camera 2")
#To get the resolution
width = int(camera1.get(cv2.CAP_PROP_FRAME_WIDTH))
height = int(camera1.get(cv2.CAP_PROP_FRAME_HEIGHT))
# get frame rate
frameRate1 = camera1.get(5)
frameRate2 = camera2.get(5)
# set up writer
writer1 = cv2.VideoWriter('004_video1.mp4v', cv2.VideoWriter_fourcc(*'mp4v'), 30, (width,height))
writer2 = cv2.VideoWriter('004_video2.mp4v', cv2.VideoWriter_fourcc(*'mp4v'), 30, (width,height))
i = 0
starttime = time.time()
while(True):
# Capture frame-by-frame
ret1, frame1 = camera1.read()
time1[i] = time.time() - starttime
writer1.write(frame1)
ret2, frame2 = camera2.read()
time2[i] = time.time() - starttime
writer2.write(frame2)
# Display the resulting frame
cv2.imshow('preview1',frame1)
cv2.imshow('preview2',frame2)
# Capture frames every tenth of a second
frameId1 = camera1.get(1) # current frame number
if ((frameId1 * 10) % int(frameRate1) == 0):
filename1 = "captures/004_image1_" + str(int(frameId)) + ".jpg"
cv2.imwrite(filename1, frame1)
filename2 = "captures/004_image2_" + str(int(frameId)) + ".jpg"
cv2.imwrite(filename2, frame2)
i +=1
#Waits for a user input to quit the application
if i == n | (cv2.waitKey(1) & 0xFF == ord('q')):
endtime = time.time()
break
camera1.release()
camera2.release()
writer1.release()
writer2.release()
cv2.destroyAllWindows()
f = open("004d_timedata.txt",'a')
f.write(str(time1))
f.write(str(time2))
f.write("Start time: " + str(starttime))
f.write("End time: " + str(endtime))
f.close()