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.

rec_ubuntu.py 3.7KB

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