|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+import sys
|
|
|
2
|
+import os
|
|
|
3
|
+import pyzed.sl as sl
|
|
|
4
|
+import threading
|
|
|
5
|
+import time
|
|
|
6
|
+from signal import signal, SIGINT
|
|
|
7
|
+
|
|
|
8
|
+zed_list = []
|
|
|
9
|
+timestamp_list = []
|
|
|
10
|
+thread_list = []
|
|
|
11
|
+stop_signal = False
|
|
|
12
|
+frame_list = []
|
|
|
13
|
+
|
|
|
14
|
+record_time_per_svo = 1800
|
|
|
15
|
+
|
|
|
16
|
+name_time_list = []
|
|
|
17
|
+
|
|
|
18
|
+
|
|
|
19
|
+root_path = "/data/"
|
|
|
20
|
+filenames = os.listdir(root_path)
|
|
|
21
|
+for f in filenames:
|
|
|
22
|
+ w_time = os.path.getctime(root_path + f)
|
|
|
23
|
+ name_time_list.append((f, w_time))
|
|
|
24
|
+sorted_list = sorted(name_time_list, key=lambda x: x[1], reverse=True)
|
|
|
25
|
+
|
|
|
26
|
+recent_file = sorted_list[0]
|
|
|
27
|
+target_dir = str(root_path) + str(recent_file[0])
|
|
|
28
|
+
|
|
|
29
|
+
|
|
|
30
|
+def handler(signal, frame):
|
|
|
31
|
+ global stop_signal
|
|
|
32
|
+ global zed_list
|
|
|
33
|
+ stop_signal = True
|
|
|
34
|
+ time.sleep(2)
|
|
|
35
|
+ exit()
|
|
|
36
|
+
|
|
|
37
|
+def grab_run(index, cameras):
|
|
|
38
|
+ global stop_signal
|
|
|
39
|
+ global zed_list
|
|
|
40
|
+ global timestamp_list
|
|
|
41
|
+ global left_list
|
|
|
42
|
+ global depth_list
|
|
|
43
|
+ global frame_list
|
|
|
44
|
+ global taget_dir
|
|
|
45
|
+
|
|
|
46
|
+ runtime = sl.RuntimeParameters()
|
|
|
47
|
+ shard_count = 0
|
|
|
48
|
+ while not stop_signal:
|
|
|
49
|
+ #I need loop and 1800ms
|
|
|
50
|
+ if frame_list[index] % record_time_per_svo == 0:
|
|
|
51
|
+ filepath = '%s/%s_%s.svo'%(target_dir,str(shard_count).zfill(3),cameras[index].id+1)
|
|
|
52
|
+ record_params = sl.RecordingParameters(filepath, sl.SVO_COMPRESSION_MODE.H264)
|
|
|
53
|
+ err = zed_list[index].enable_recording(record_params)
|
|
|
54
|
+ #print('new shard created')
|
|
|
55
|
+ shard_count += 1
|
|
|
56
|
+ if zed_list[index].grab(runtime) == sl.ERROR_CODE.SUCCESS :
|
|
|
57
|
+ frame_list[index] += 1
|
|
|
58
|
+ #if zed_list[index].grab() == "SUCCESS":
|
|
|
59
|
+ # zed_list[index].record()
|
|
|
60
|
+ print("Frame count: " + str(frame_list[index]), end='\r')
|
|
|
61
|
+ if zed_list[index].grab(runtime) == sl.ERROR_CODE.SUCCESS :
|
|
|
62
|
+ frame_list[index] += 1
|
|
|
63
|
+
|
|
|
64
|
+ zed_list[index].disable_recording()
|
|
|
65
|
+ print('saved')
|
|
|
66
|
+
|
|
|
67
|
+def main():
|
|
|
68
|
+
|
|
|
69
|
+ signal(SIGINT, handler)
|
|
|
70
|
+
|
|
|
71
|
+ print('Running...')
|
|
|
72
|
+ init = sl.InitParameters()
|
|
|
73
|
+ init.camera_resolution = sl.RESOLUTION.HD1080
|
|
|
74
|
+ init.camera_fps = 30
|
|
|
75
|
+
|
|
|
76
|
+ name_list = []
|
|
|
77
|
+
|
|
|
78
|
+ cameras = sl.Camera.get_device_list()
|
|
|
79
|
+ print(cameras)
|
|
|
80
|
+ index = 0
|
|
|
81
|
+ for cam in cameras:
|
|
|
82
|
+ init.set_from_serial_number(cam.serial_number)
|
|
|
83
|
+ name_list.append("ZED {}".format(cam.serial_number))
|
|
|
84
|
+ print("Opening {}".format(name_list[index]))
|
|
|
85
|
+ zed_list.append(sl.Camera())
|
|
|
86
|
+ timestamp_list.append(0)
|
|
|
87
|
+ frame_list.append(0)
|
|
|
88
|
+ status = zed_list[index].open(init)
|
|
|
89
|
+ if status != sl.ERROR_CODE.SUCCESS:
|
|
|
90
|
+ print(repr(status))
|
|
|
91
|
+ zed_list[index].close()
|
|
|
92
|
+ index = index +1
|
|
|
93
|
+
|
|
|
94
|
+ #Start camera threads
|
|
|
95
|
+ for index in range(0, len(zed_list)):
|
|
|
96
|
+ if zed_list[index].is_opened():
|
|
|
97
|
+ thread_list.append(threading.Thread(target=grab_run, args=(index,cameras)))
|
|
|
98
|
+ thread_list[index].start()
|
|
|
99
|
+
|
|
|
100
|
+
|
|
|
101
|
+
|
|
|
102
|
+if __name__ == "__main__":
|
|
|
103
|
+ main()
|