#!/usr/bin/env python """Test YOLO detection with different confidence levels""" import sys from PIL import Image import numpy as np # Use full conda python path sys.path.insert(0, r"c:\Users\barat\OneDrive\Desktop\model\plate-detector") try: from ultralytics import YOLO from detector import detect_plate # Test with the test image test_image_path = r"C:\Users\barat\OneDrive\Desktop\image.jpg" print(f"Loading image from: {test_image_path}") image = Image.open(test_image_path) image_np = np.array(image.convert("RGB")) print(f"Image shape: {image_np.shape}") print(f"Image dtype: {image_np.dtype}") # Load YOLO model print("\nLoading YOLO model...") yolo = YOLO("license-plate-finetune-v1s.pt") print("✅ YOLO loaded") # Run detection with default settings print("\nRunning YOLO detection (conf=0.5)...") results = yolo(image_np) boxes = results[0].boxes print(f"Boxes found: {len(boxes) if boxes is not None else 0}") if boxes is not None: print(f"Confidences: {boxes.conf.cpu().numpy()}") print(f"Box coordinates: {boxes.xyxy.cpu().numpy()}") # Try with lower confidence print("\nRunning YOLO detection (conf=0.3)...") results = yolo(image_np, conf=0.3) boxes = results[0].boxes print(f"Boxes found: {len(boxes) if boxes is not None else 0}") if boxes is not None: print(f"Confidences: {boxes.conf.cpu().numpy()}") print(f"Box coordinates: {boxes.xyxy.cpu().numpy()}") # Try with very low confidence print("\nRunning YOLO detection (conf=0.1)...") results = yolo(image_np, conf=0.1) boxes = results[0].boxes print(f"Boxes found: {len(boxes) if boxes is not None else 0}") if boxes is not None: print(f"Confidences: {boxes.conf.cpu().numpy()}") print(f"Box coordinates: {boxes.xyxy.cpu().numpy()}") # Now test full detection pipeline print("\n" + "="*50) print("Testing full detection pipeline...") print("="*50) plate, state, vehicle_type, vehicle_conf, success = detect_plate(image) print(f"\nPlate: {plate}") print(f"State: {state}") print(f"Vehicle Type: {vehicle_type}") print(f"Vehicle Conf: {vehicle_conf}") print(f"Success: {success}") except Exception as e: print(f"❌ Error: {e}") import traceback traceback.print_exc()