- 检测孤儿ROI记录(ROI存在但摄像头配置缺失) - 诊断出3个有问题的摄像头ID - 提供根本原因分析和解决方案 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
107 lines
3.6 KiB
Python
107 lines
3.6 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
诊断脚本:检查并修复缺失摄像头配置的问题
|
|
"""
|
|
import sys
|
|
from pathlib import Path
|
|
sys.path.insert(0, str(Path(__file__).parent))
|
|
|
|
from core.config_sync import get_config_sync_manager
|
|
|
|
def main():
|
|
print("=== Camera Configuration Diagnostic Tool ===\n")
|
|
|
|
# 初始化配置管理器
|
|
config_manager = get_config_sync_manager()
|
|
|
|
# 问题摄像头ID
|
|
problem_ids = ['cam_6f4922f45568', 'cam_c51ce410c124', 'cam_1f0e3dad9990']
|
|
|
|
# 1. 检查摄像头配置
|
|
print("1. Camera Configuration Check")
|
|
print("-" * 50)
|
|
cameras = config_manager.get_cameras()
|
|
print(f"Total cameras: {len(cameras)}\n")
|
|
|
|
camera_dict = {c.camera_id: c for c in cameras}
|
|
|
|
for cam_id in problem_ids:
|
|
if cam_id in camera_dict:
|
|
camera = camera_dict[cam_id]
|
|
print(f"[OK] {cam_id}")
|
|
print(f" Name: {camera.name}")
|
|
print(f" RTSP: {camera.rtsp_url if camera.rtsp_url else '[MISSING]'}")
|
|
else:
|
|
print(f"[MISSING] {cam_id} - Configuration not found")
|
|
|
|
# 2. 检查ROI配置
|
|
print("\n2. ROI Configuration Check")
|
|
print("-" * 50)
|
|
rois = config_manager.get_rois()
|
|
print(f"Total ROIs: {len(rois)}\n")
|
|
|
|
problem_rois = [roi for roi in rois if roi.camera_id in problem_ids]
|
|
print(f"ROIs for problem cameras: {len(problem_rois)}")
|
|
|
|
for roi in problem_rois:
|
|
print(f" - ROI {roi.roi_id}")
|
|
print(f" Name: {roi.roi_name}")
|
|
print(f" Camera: {roi.camera_id}")
|
|
print(f" Points: {roi.points}")
|
|
|
|
# 3. 检查算法绑定
|
|
print("\n3. Algorithm Bindings Check")
|
|
print("-" * 50)
|
|
binds = config_manager.get_bindings()
|
|
|
|
problem_roi_ids = [roi.roi_id for roi in problem_rois]
|
|
problem_binds = [b for b in binds if b.roi_id in problem_roi_ids]
|
|
|
|
print(f"Bindings for problem cameras: {len(problem_binds)}")
|
|
for bind in problem_binds:
|
|
print(f" - Bind {bind.bind_id}")
|
|
print(f" ROI: {bind.roi_id}")
|
|
print(f" Algorithm: {bind.algo_code}")
|
|
print(f" Params: {bind.params}")
|
|
|
|
# 4. 诊断结果
|
|
print("\n" + "=" * 50)
|
|
print("DIAGNOSTIC RESULTS")
|
|
print("=" * 50)
|
|
|
|
missing_cameras = [cam_id for cam_id in problem_ids if cam_id not in camera_dict]
|
|
|
|
if missing_cameras:
|
|
print(f"\n[PROBLEM] {len(missing_cameras)} cameras missing:")
|
|
for cam_id in missing_cameras:
|
|
print(f" - {cam_id}")
|
|
|
|
print("\nRoot Cause Analysis:")
|
|
print(" These camera IDs are referenced in ROI configs,")
|
|
print(" but camera configurations do not exist.")
|
|
print("\n Possible Reasons:")
|
|
print(" 1. Cameras were deleted, ROI configs not synced (orphaned records)")
|
|
print(" 2. Incomplete configuration sync")
|
|
print(" 3. Database corruption")
|
|
|
|
print("\nSolutions:")
|
|
print(" Option A: Delete orphaned ROI configs (Recommended)")
|
|
print(" Option B: Add complete camera configs in cloud platform")
|
|
print(" Option C: Run cleanup script to remove orphaned records")
|
|
|
|
if len(problem_rois) > 0:
|
|
print(f"\n ROI IDs to cleanup:")
|
|
for roi in problem_rois:
|
|
print(f" - {roi.roi_id} (camera: {roi.camera_id})")
|
|
|
|
if len(problem_binds) > 0:
|
|
print(f"\n Bind IDs to cleanup:")
|
|
for bind in problem_binds:
|
|
print(f" - {bind.bind_id} (roi: {bind.roi_id})")
|
|
else:
|
|
print("\n[OK] All camera configurations are complete")
|
|
print(" If warnings persist, check RTSP URL configuration")
|
|
|
|
if __name__ == "__main__":
|
|
main()
|