Repository for M.A.I.L system's analysis server.
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

mailsetup.py 4.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. import os
  2. import sys
  3. import pyzed.sl as sl
  4. import json
  5. import numpy as np
  6. import math
  7. import time
  8. import subprocess
  9. import mailcalibrate
  10. WDIR_DEFAULT = os.path.expanduser('~/data/')
  11. SDIR_DEFAULT = os.path.abspath('/hdd/')
  12. MAINCAM_DEFAULT = 'cam1'
  13. RECFRAME_DEFAULT = 1800
  14. JSON_PATH = '~/sources/configuration.json'
  15. LOG_REBOOT = '~/sources/cfg/log_reboot.txt'
  16. cameras = sl.Camera.get_device_list()
  17. def get_cam_info():
  18. init = sl.InitParameters()
  19. init.depth_mode = sl.DEPTH_MODE.NONE # Use PERFORMANCE depth mode
  20. init.coordinate_units = sl.UNIT.METER # Use meter units (for depth measurements)
  21. init.camera_resolution = sl.RESOLUTION.HD720
  22. name_list = []
  23. zed_list = []
  24. angle_list = []
  25. for cam in cameras:
  26. init.set_from_serial_number(cam.serial_number)
  27. name_list.append("ZED {}".format(cam.serial_number))
  28. zed = sl.Camera()
  29. err = zed.open(init)
  30. if err != sl.ERROR_CODE.SUCCESS:
  31. print(repr(err))
  32. zed.close()
  33. info = zed.get_camera_information()
  34. sensors_data = sl.SensorsData()
  35. if zed.get_sensors_data(sensors_data, sl.TIME_REFERENCE.CURRENT) == sl.ERROR_CODE.SUCCESS :
  36. #print(" - IMU:")
  37. # Filtered orientation quaternion
  38. quaternion = sensors_data.get_imu_data().get_pose().get_orientation().get()
  39. #NOTE: IS IT REALLY CORRECT ANGLE???
  40. angle = (quaternion[0] * 900)/7+ 90
  41. angle_list.append(angle)
  42. print(angle)
  43. zed.close()
  44. return_list = []
  45. for x in range(0,len(name_list)):
  46. return_list.append(name_list[x])
  47. return_list.append(angle_list[x])
  48. return return_list
  49. def main():
  50. #Initialize JSON
  51. conf = {
  52. "confDate" : "",
  53. "branch" : "",
  54. "room" : "",
  55. "workingDir" : "",
  56. "storageDir" : "",
  57. "mainCam" : "cam1",
  58. "recFrame" : 1800,
  59. "cam1" : {
  60. "SN" : "",
  61. "angle" : "",
  62. "d_center" : "",
  63. "headCoord" : "",
  64. "d_headCoord" : "",
  65. "tailCoord" : "",
  66. "d_tailCoord" : ""
  67. },
  68. "cam2" : {
  69. "SN" : "",
  70. "angle" : "",
  71. "d_center" : "",
  72. "headCoord" : "",
  73. "d_headCoord" : "",
  74. "tailCoord" : "",
  75. "d_tailCoord" : ""
  76. }
  77. }
  78. wdirpath = os.path.abspath(os.path.expanduser('~/data'))
  79. sdirpath = os.path.abspath('/hdd')
  80. nowtime = time.localtime()
  81. #NOTE: createdDate = "2022/02/04 21:07:54"
  82. createdDate = "%04d/%02d/%02d %02d:%02d:%02d" % (nowtime.tm_year, nowtime.tm_mon, nowtime.tm_mday, nowtime.tm_hour, nowtime.tm_min, nowtime.tm_sec)
  83. caminfo_list = get_cam_info()
  84. conf["confDate"] = createdDate
  85. conf["workingDir"] = wdirpath
  86. conf["storageDir"] = sdirpath
  87. conf["mainCam"] = caminfo_list[0]
  88. conf["recFrame"] = RECFRAME_DEFAULT
  89. conf["cam1"]["SN"] = caminfo_list[0]
  90. conf["cam1"]["angle"] = caminfo_list[1]
  91. conf["cam1"]["d_center"] = 0
  92. conf["cam1"]["headCoord"] = ''
  93. conf["cam1"]["d_headCoord"] = 0
  94. conf["cam1"]["tailCoord"] = ''
  95. conf["cam1"]["d_tailCoord"] = 0
  96. if len(caminfo_list) == 4:
  97. conf["mainCam"] = "SN 00000000"
  98. conf["cam2"]["SN"] = caminfo_list[2]
  99. conf["cam2"]["angle"] = caminfo_list[3]
  100. conf["cam2"]["d_center"] = 0
  101. conf["cam2"]["headCoord"] = ''
  102. conf["cam2"]["d_headCoord"] = 0
  103. conf["cam2"]["tailCoord"] = ''
  104. conf["cam2"]["d_tailCoord"] = 0
  105. else:
  106. pass
  107. if os.path.isfile(os.path.expanduser(JSON_PATH)):
  108. subprocess.call(('mv', os.path.expanduser(JSON_PATH), os.path.expanduser('~/sources/configuration.json.bak')))
  109. print('Already configuration file exists.')
  110. with open (os.path.abspath(os.path.expanduser(JSON_PATH)), "w") as json_file:
  111. json.dump(conf,json_file, indent=4)
  112. print('configuration.json was created')
  113. else:
  114. with open (os.path.abspath(os.path.expanduser(JSON_PATH)), "w") as json_file:
  115. json.dump(conf,json_file, indent=4)
  116. if os.path.isfile(os.path.expanduser(LOG_REBOOT)) == False:
  117. with open (os.path.abspath(os.path.expanduser(LOG_REBOOT)), "w+") as log_reboot:
  118. log_reboot.write('This file automatically created at '+ createdDate)
  119. print('log_reboot.txt was created')
  120. if __name__ == "__main__":
  121. main()