test_detection.py 655 B

123456789101112131415161718192021222324
  1. #!/usr/bin/env python3
  2. import cv2
  3. import numpy as np
  4. from rtsp_person_detection import create_detector
  5. # 测试检测功能
  6. model_path = 'yolo11m_safety.onnx' # 可以切换为 'yolo11m_safety.rknn'
  7. det = create_detector(model_path)
  8. # 读取测试图片
  9. img = cv2.imread('b.jpg')
  10. if img is None:
  11. print('无法读取测试图片')
  12. exit(1)
  13. print(f'测试图片形状: {img.shape}')
  14. # 进行检测
  15. conf_threshold_map = {3: 0.8, 0: 0.5, 4: 0.5}
  16. detections = det.detect(img, conf_threshold_map)
  17. print(f'检测结果: {len(detections)} 个目标')
  18. for det in detections:
  19. print(f' {det.class_name}: conf={det.confidence:.2f}, box={det.bbox}')