camera.py 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. """
  2. 摄像头配置
  3. """
  4. import platform
  5. import os
  6. LOG_CONFIG = {
  7. 'level': 'INFO',
  8. 'format': '%(asctime)s - %(name)s - %(levelname)s - %(message)s',
  9. 'file': None, # 日志文件路径,设置为None则只输出到控制台
  10. 'max_bytes': 10 * 1024 * 1024,
  11. 'backup_count': 5,
  12. 'retention_days': 7, # 日志保留天数
  13. }
  14. # ============================================================
  15. # 单组摄像头配置(保持向后兼容)
  16. # ============================================================
  17. PANORAMA_CAMERA = {
  18. 'ip': '192.168.20.196',
  19. 'port': 37777,
  20. 'rtsp_port': 554,
  21. 'username': 'admin',
  22. 'password': 'Aa1234567',
  23. 'channel': 1,
  24. # 品牌:dahua 使用 SDK 登录;hikvision 仅使用 RTSP 取流
  25. 'brand': 'dahua',
  26. 'use_sdk': False,
  27. # 全景摄像头期望分辨率,支持 (width, height) 或字符串如 "1920x1080"
  28. # 常见值:3840x1080、2560x1440、1920x1080
  29. 'resolution': (3840, 1080),
  30. 'rtsp_url': 'rtsp://admin:Aa1234567@192.168.20.196:554/cam/realmonitor?channel=1&subtype=0',
  31. }
  32. PTZ_CAMERA = {
  33. 'ip': '192.168.20.197',
  34. 'port': 37777,
  35. 'rtsp_port': 554,
  36. 'username': 'admin',
  37. 'password': 'Aa1234567',
  38. 'channel': 0, # PTZ 控制通道号 (SDK 从 0 开始)
  39. 'rtsp_url': 'rtsp://admin:Aa1234567@192.168.20.197:554/cam/realmonitor?channel=1&subtype=0',
  40. }
  41. # ============================================================
  42. # 多组摄像头配置(新架构)
  43. # 使用方法:启用需要的组(enabled=True),配置对应的IP地址
  44. # ============================================================
  45. CAMERA_GROUPS = [
  46. {
  47. 'group_id': 'group_1',
  48. 'name': '现场主组',
  49. 'enabled': True,
  50. 'panorama': {
  51. 'ip': '192.168.20.196',
  52. 'port': 37777,
  53. 'rtsp_port': 554,
  54. 'username': 'admin',
  55. 'password': 'Aa1234567',
  56. 'channel': 1,
  57. # 品牌:dahua 使用 SDK 登录;hikvision 仅使用 RTSP 取流
  58. 'brand': 'dahua',
  59. 'use_sdk': False,
  60. # 全景摄像头期望分辨率,支持 (width, height) 或字符串如 "2560x1440"
  61. # 常见值:3840x1080、2560x1440、1920x1080
  62. 'resolution': (3840, 1080),
  63. 'rtsp_url': 'rtsp://admin:Aa1234567@192.168.20.196:554/cam/realmonitor?channel=1&subtype=0',
  64. },
  65. 'ptz': {
  66. 'ip': '192.168.20.197',
  67. 'port': 37777,
  68. 'rtsp_port': 554,
  69. 'username': 'admin',
  70. 'password': 'Aa1234567',
  71. 'channel': 0,
  72. 'rtsp_url': 'rtsp://admin:Aa1234567@192.168.20.197:554/cam/realmonitor?channel=1&subtype=0',
  73. # 球机安装方向:ceiling=吸顶/吊装(镜头朝下), wall=壁装/立杆(镜头水平/竖装镜头朝上)
  74. # 当前球机竖装、镜头朝上,pan/tilt 运动方向均与视觉方向相反
  75. 'mount_type': 'wall',
  76. # pan_flip: 球机水平运动方向与视觉方向相反时设为 True
  77. 'pan_flip': True,
  78. # tilt_flip: 球机俯仰运动方向与视觉方向相反时设为 True
  79. 'tilt_flip': True,
  80. # 视野映射:全景 x=0 -> pan=-90, x=1 -> pan=+90
  81. 'pan_range': (-90, 90),
  82. 'pan_center': 0,
  83. # tilt:负值为向下看。竖装+倒影后,y=0(画面上方/远处)向上看,y=1 向下看
  84. # 人要被显示器挡住,需要适当向上看(tilt 正值)
  85. 'tilt_range': (-5, 20),
  86. 'tilt_center': 7,
  87. # tilt 全局偏移补偿(度):正值向下,负值向上;用于现场微调
  88. 'tilt_offset': 5,
  89. 'tilt_linear_enabled': False, # 使用手动标定的 tilt_lookup,不用线性映射
  90. 'tilt_y0': 13, # 备用:y=0(画面上方/远处)略向上,使人头/上半身不被切出画面
  91. 'tilt_y1': -5,
  92. 'tilt_curve_power': 0.8,
  93. # 自动校准扫描范围:完整 360° 粗扫 + 每步由下朝上细扫,建立全景→PTZ 映射
  94. 'overlap_pan_range': (0, 360),
  95. 'overlap_tilt_range': (-35, 45),
  96. 'overlap_pan_step': 20,
  97. 'overlap_tilt_step': 10,
  98. },
  99. 'calibration_file': '/home/admin/dsh/calibration_group1.json',
  100. 'paired_image_dir': '/home/admin/dsh/paired_images_group1',
  101. },
  102. ]
  103. # SDK 路径配置
  104. _ARCH = platform.machine()
  105. if _ARCH == 'aarch64':
  106. _SDK_DIR = '/home/admin/dsh/dh/arm/Bin'
  107. elif _ARCH == 'x86_64':
  108. _SDK_DIR = '/home/wen/dsh/dh/Bin'
  109. else:
  110. _SDK_DIR = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), '..', 'dh', 'Bin')
  111. SDK_PATH = {
  112. 'lib_path': _SDK_DIR,
  113. 'netsdk': 'libdhnetsdk.so',
  114. }
  115. def get_enabled_groups() -> list:
  116. """获取所有启用的摄像头组配置"""
  117. return [g for g in CAMERA_GROUPS if g.get('enabled', False)]
  118. def parse_resolution(resolution) -> tuple:
  119. """解析分辨率配置为 (width, height)
  120. 支持格式:
  121. - (3840, 1080)
  122. - [3840, 1080]
  123. - "3840x1080"
  124. - "3840*1080"
  125. - "3840X1080"
  126. Args:
  127. resolution: 分辨率配置
  128. Returns:
  129. (width, height) 元组
  130. """
  131. if resolution is None:
  132. return 1920, 1080
  133. if isinstance(resolution, (tuple, list)) and len(resolution) == 2:
  134. return int(resolution[0]), int(resolution[1])
  135. if isinstance(resolution, str):
  136. # 支持 x、X、* 作为分隔符
  137. for sep in ['x', 'X', '*']:
  138. if sep in resolution:
  139. parts = resolution.split(sep)
  140. if len(parts) == 2:
  141. return int(parts[0]), int(parts[1])
  142. return 1920, 1080