Repository for M.A.I.L system's analysis server.
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

recorder.py 2.9KB

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