camera.py 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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. # 测试环境球机已在设备端设置为 ceiling 模式,代码层按 wall 避免双重翻转
  75. 'mount_type': 'wall',
  76. # pan_flip: 球机与全景朝向相反时设为 True
  77. # 测试环境球机竖装且设备端已做倒影,与枪机同向,无需翻转 pan
  78. 'pan_flip': False,
  79. # tilt_flip: 俯仰方向相反时设为 True(设备端 ceiling 模式已处理 tilt,代码层不翻转)
  80. # 2026-06-15 实测:使用手动标定 lookup 表,不在 transform 中额外翻转
  81. 'tilt_flip': False,
  82. # 视野映射:全景 x=0 -> pan=-90, x=1 -> pan=+90
  83. 'pan_range': (-90, 90),
  84. 'pan_center': 0,
  85. # tilt:负值为向下看。竖装+倒影后,y=0(画面上方/远处)向上看,y=1 向下看
  86. # 人要被显示器挡住,需要适当向上看(tilt 正值)
  87. 'tilt_range': (-5, 20),
  88. 'tilt_center': 7,
  89. # tilt 全局偏移补偿(度):正值向下,负值向上;用于现场微调
  90. 'tilt_offset': 5,
  91. 'tilt_linear_enabled': False, # 使用手动标定的 tilt_lookup,不用线性映射
  92. 'tilt_y0': 13, # 备用:y=0(画面上方/远处)略向上,使人头/上半身不被切出画面
  93. 'tilt_y1': -5,
  94. 'tilt_curve_power': 0.8,
  95. # 自动校准扫描范围:完整 360° 粗扫 + 每步由下朝上细扫,建立全景→PTZ 映射
  96. 'overlap_pan_range': (0, 360),
  97. 'overlap_tilt_range': (-35, 45),
  98. 'overlap_pan_step': 20,
  99. 'overlap_tilt_step': 10,
  100. },
  101. 'calibration_file': '/home/admin/dsh/calibration_group1.json',
  102. 'paired_image_dir': '/home/admin/dsh/paired_images_group1',
  103. },
  104. ]
  105. # SDK 路径配置
  106. _ARCH = platform.machine()
  107. if _ARCH == 'aarch64':
  108. _SDK_DIR = '/home/admin/dsh/dh/arm/Bin'
  109. elif _ARCH == 'x86_64':
  110. _SDK_DIR = '/home/wen/dsh/dh/Bin'
  111. else:
  112. _SDK_DIR = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), '..', 'dh', 'Bin')
  113. SDK_PATH = {
  114. 'lib_path': _SDK_DIR,
  115. 'netsdk': 'libdhnetsdk.so',
  116. }
  117. def get_enabled_groups() -> list:
  118. """获取所有启用的摄像头组配置"""
  119. return [g for g in CAMERA_GROUPS if g.get('enabled', False)]
  120. def parse_resolution(resolution) -> tuple:
  121. """解析分辨率配置为 (width, height)
  122. 支持格式:
  123. - (3840, 1080)
  124. - [3840, 1080]
  125. - "3840x1080"
  126. - "3840*1080"
  127. - "3840X1080"
  128. Args:
  129. resolution: 分辨率配置
  130. Returns:
  131. (width, height) 元组
  132. """
  133. if resolution is None:
  134. return 1920, 1080
  135. if isinstance(resolution, (tuple, list)) and len(resolution) == 2:
  136. return int(resolution[0]), int(resolution[1])
  137. if isinstance(resolution, str):
  138. # 支持 x、X、* 作为分隔符
  139. for sep in ['x', 'X', '*']:
  140. if sep in resolution:
  141. parts = resolution.split(sep)
  142. if len(parts) == 2:
  143. return int(parts[0]), int(parts[1])
  144. return 1920, 1080