test_detection.py 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import sys
  2. sys.path.insert(0, '/home/admin/dsh/dual_camera_system')
  3. import cv2
  4. from panorama_camera import ObjectDetector
  5. from config.detection import DETECTION_CONFIG
  6. import time
  7. print('Loading detector...')
  8. detector = ObjectDetector(
  9. model_path=DETECTION_CONFIG['model_path'],
  10. use_gpu=DETECTION_CONFIG['use_gpu'],
  11. model_type=DETECTION_CONFIG['model_type']
  12. )
  13. print('Detector loaded, type:', detector.model_type)
  14. # Load test image
  15. frame = cv2.imread('/home/admin/dsh/panorama_now.jpg')
  16. if frame is None:
  17. print('Failed to load image')
  18. sys.exit(1)
  19. print('Image shape:', frame.shape)
  20. # Run detection
  21. t0 = time.time()
  22. dets = detector.detect(frame)
  23. t1 = time.time()
  24. print(f'Detection took {t1-t0:.3f}s, found {len(dets)} objects')
  25. for d in dets:
  26. print(f' {d.class_name}: conf={d.confidence:.3f}, bbox={d.bbox}, center={d.center}')
  27. # Save marked image
  28. marked = frame.copy()
  29. for d in dets:
  30. x, y, w, h = d.bbox
  31. cv2.rectangle(marked, (x, y), (x+w, y+h), (0, 255, 0), 2)
  32. cv2.putText(marked, f'{d.class_name} {d.confidence:.2f}', (x, y-5),
  33. cv2.FONT_HERSHEY_SIMPLEX, 0.6, (0, 255, 0), 2)
  34. cv2.imwrite('/home/admin/dsh/detection_test.jpg', marked)
  35. print('Saved marked image to /home/admin/dsh/detection_test.jpg')