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.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. stop_signal = True
  26. time.sleep(2)
  27. exit()
  28. def grab_run(index, cameras):
  29. global stop_signal
  30. global zed_list
  31. global timestamp_list
  32. global left_list
  33. global depth_list
  34. global frame_list
  35. global taget_dir
  36. runtime = sl.RuntimeParameters()
  37. shard_count = 0
  38. while not stop_signal:
  39. #I need loop and 1800ms
  40. if frame_list[index] % record_time_per_svo == 0:
  41. filepath = '%s/%s_%s.svo'%(target_dir,str(shard_count).zfill(3),cameras[index].id+1)
  42. record_params = sl.RecordingParameters(filepath, sl.SVO_COMPRESSION_MODE.H264)
  43. err = zed_list[index].enable_recording(record_params)
  44. #print('new shard created')
  45. shard_count += 1
  46. if zed_list[index].grab(runtime) == sl.ERROR_CODE.SUCCESS :
  47. frame_list[index] += 1
  48. #if zed_list[index].grab() == "SUCCESS":
  49. # zed_list[index].record()
  50. #print("Frame count: " + str(frame_list[index]), end='\r')
  51. if zed_list[index].grab(runtime) == sl.ERROR_CODE.SUCCESS :
  52. frame_list[index] += 1
  53. zed_list[index].disable_recording()
  54. #print('saved')
  55. def main():
  56. signal(SIGINT, handler)
  57. #print('Running...')
  58. init = sl.InitParameters()
  59. init.camera_resolution = sl.RESOLUTION.HD1080
  60. init.camera_fps = 30
  61. name_list = []
  62. cameras = sl.Camera.get_device_list()
  63. #print(cameras)
  64. index = 0
  65. for cam in cameras:
  66. init.set_from_serial_number(cam.serial_number)
  67. name_list.append("ZED {}".format(cam.serial_number))
  68. print("Opening {}".format(name_list[index]))
  69. zed_list.append(sl.Camera())
  70. timestamp_list.append(0)
  71. frame_list.append(0)
  72. status = zed_list[index].open(init)
  73. if status != sl.ERROR_CODE.SUCCESS:
  74. print(repr(status))
  75. zed_list[index].close()
  76. index = index +1
  77. #Start camera threads
  78. for index in range(0, len(zed_list)):
  79. if zed_list[index].is_opened():
  80. thread_list.append(threading.Thread(target=grab_run, args=(index,cameras)))
  81. thread_list[index].start()
  82. if __name__ == "__main__":
  83. main()