File size: 1,093 Bytes
12dddb7
 
83e8ad5
12dddb7
b5f5a04
83e8ad5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1298d48
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
import cv2
import numpy as np
from typing import List, Tuple, Dict, Any

def process_bridge_piers(frame: np.ndarray) -> Tuple[List[Dict[str, Any]], np.ndarray]:
    """
    Detect bridge piers 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 < 400:  # 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"Bridge Pier {i+1}",
            "type": "bridge_pier"
        })
    
    return detections, frame