camera.py 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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.8.2',
  19. 'port': 37777,
  20. 'rtsp_port': 554,
  21. 'username': 'admin',
  22. 'password': 'QAZwsx12',
  23. 'channel': 1,
  24. # 品牌:dahua 使用 SDK 登录;hikvision 仅使用 RTSP 取流
  25. 'brand': 'hikvision',
  26. 'use_sdk': False,
  27. # 全景摄像头期望分辨率,支持 (width, height) 或字符串如 "1920x1080"
  28. # 常见值:3840x1080、2560x1440、1920x1080
  29. 'resolution': (2560, 1440),
  30. 'rtsp_url': 'rtsp://admin:QAZwsx12@192.168.8.2:554/Streaming/Channels/101',
  31. }
  32. PTZ_CAMERA = {
  33. 'ip': '192.168.8.5',
  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.8.5:554/cam/realmonitor?channel=1&subtype=1',
  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.8.2',
  52. 'port': 37777,
  53. 'rtsp_port': 554,
  54. 'username': 'admin',
  55. 'password': 'QAZwsx12',
  56. 'channel': 1,
  57. # 品牌:dahua 使用 SDK 登录;hikvision 仅使用 RTSP 取流
  58. 'brand': 'hikvision',
  59. 'use_sdk': False,
  60. # 全景摄像头期望分辨率,支持 (width, height) 或字符串如 "2560x1440"
  61. # 常见值:3840x1080、2560x1440、1920x1080
  62. 'resolution': (2560, 1440),
  63. 'rtsp_url': 'rtsp://admin:QAZwsx12@192.168.8.2:554/Streaming/Channels/101',
  64. },
  65. 'ptz': {
  66. 'ip': '192.168.8.5',
  67. 'port': 37777,
  68. 'rtsp_port': 554,
  69. 'username': 'admin',
  70. 'password': 'Aa1234567',
  71. 'channel': 0,
  72. 'rtsp_url': 'rtsp://admin:Aa1234567@192.168.8.5:554/cam/realmonitor?channel=1&subtype=1',
  73. # 球机安装方向:ceiling=吸顶/吊装(镜头朝下), wall=壁装/立杆(镜头水平)
  74. 'mount_type': 'ceiling',
  75. # pan_flip: 球机与全景朝向相反时设为 True
  76. 'pan_flip': True,
  77. # tilt_flip: 俯仰方向相反时设为 True(ceiling 会自动翻转 tilt,通常无需再设)
  78. 'tilt_flip': False,
  79. },
  80. 'calibration_file': '/home/admin/dsh/calibration_group1.json',
  81. 'paired_image_dir': '/home/admin/dsh/paired_images_group1',
  82. },
  83. ]
  84. # SDK 路径配置
  85. _ARCH = platform.machine()
  86. if _ARCH == 'aarch64':
  87. _SDK_DIR = '/home/admin/dsh/dh/arm/Bin'
  88. elif _ARCH == 'x86_64':
  89. _SDK_DIR = '/home/wen/dsh/dh/Bin'
  90. else:
  91. _SDK_DIR = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), '..', 'dh', 'Bin')
  92. SDK_PATH = {
  93. 'lib_path': _SDK_DIR,
  94. 'netsdk': 'libdhnetsdk.so',
  95. }
  96. def get_enabled_groups() -> list:
  97. """获取所有启用的摄像头组配置"""
  98. return [g for g in CAMERA_GROUPS if g.get('enabled', False)]
  99. def parse_resolution(resolution) -> tuple:
  100. """解析分辨率配置为 (width, height)
  101. 支持格式:
  102. - (3840, 1080)
  103. - [3840, 1080]
  104. - "3840x1080"
  105. - "3840*1080"
  106. - "3840X1080"
  107. Args:
  108. resolution: 分辨率配置
  109. Returns:
  110. (width, height) 元组
  111. """
  112. if resolution is None:
  113. return 1920, 1080
  114. if isinstance(resolution, (tuple, list)) and len(resolution) == 2:
  115. return int(resolution[0]), int(resolution[1])
  116. if isinstance(resolution, str):
  117. # 支持 x、X、* 作为分隔符
  118. for sep in ['x', 'X', '*']:
  119. if sep in resolution:
  120. parts = resolution.split(sep)
  121. if len(parts) == 2:
  122. return int(parts[0]), int(parts[1])
  123. return 1920, 1080