Spaces:
				
			
			
	
			
			
		Sleeping
		
	
	
	
			
			
	
	
	
	
		
		
		Sleeping
		
	File size: 1,094 Bytes
			
			| 6bc2b8b 2886d5a a3b4a03 2886d5a daef382 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | import cv2
import numpy as np
from typing import List, Tuple, Dict, Any
def process_signages(frame: np.ndarray) -> Tuple[List[Dict[str, Any]], np.ndarray]:
    """
    Detect road signages in the frame.
    Args:
        frame: Input frame as a numpy array.
    Returns:
        Tuple of (list of detections, annotated frame).
    """
    # Convert to grayscale
    gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
    
    # Apply edge detection
    edges = cv2.Canny(gray, 50, 150)
    
    # Find contours
    contours, _ = cv2.findContours(edges, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
    
    detections = []
    for i, contour in enumerate(contours):
        area = cv2.contourArea(contour)
        if area < 200:  # Ignore small contours
            continue
        
        x, y, w, h = cv2.boundingRect(contour)
        x_min, y_min, x_max, y_max = x, y, x + w, y + h
        
        detections.append({
            "box": [x_min, y_min, x_max, y_max],
            "label": f"Signage {i+1}",
            "type": "signage"
        })
    
    return detections, frame
 | 
