Просмотр исходного кода

recorder.py.bak for mailsys_client temporally

master
Jeong Geol Kim 4 лет назад
Родитель
Сommit
114c48a876
1 измененных файлов: 107 добавлений и 0 удалений
  1. 107
    0
      recorder.py.bak

+ 107
- 0
recorder.py.bak Просмотреть файл

@@ -0,0 +1,107 @@
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
+    filepath = '%s/log.txt'%(target_dir)
66
+    f = open(filepath, 'w')
67
+    f.write('record succesfully stopped')
68
+    f.close()
69
+    #print('saved')    
70
+
71
+def main():
72
+
73
+    signal(SIGINT, handler)
74
+
75
+    #print('Running...')
76
+    init = sl.InitParameters()
77
+    init.camera_resolution = sl.RESOLUTION.HD1080
78
+    init.camera_fps = 30
79
+
80
+    name_list = []
81
+
82
+    cameras = sl.Camera.get_device_list()
83
+    #print(cameras)
84
+    index = 0
85
+    for cam in cameras:
86
+        init.set_from_serial_number(cam.serial_number)
87
+        name_list.append("ZED {}".format(cam.serial_number))
88
+        print("Opening {}".format(name_list[index]))
89
+        zed_list.append(sl.Camera())
90
+        timestamp_list.append(0)
91
+        frame_list.append(0)
92
+        status = zed_list[index].open(init)
93
+        if status != sl.ERROR_CODE.SUCCESS:
94
+            print(repr(status))
95
+            zed_list[index].close()
96
+        index = index +1
97
+
98
+    #Start camera threads
99
+    for index in range(0, len(zed_list)):
100
+        if zed_list[index].is_opened():
101
+            thread_list.append(threading.Thread(target=grab_run, args=(index,cameras)))
102
+            thread_list[index].start()
103
+
104
+
105
+
106
+if __name__ == "__main__":
107
+    main()

Загрузка…
Отмена
Сохранить