Spaces:
Runtime error
Runtime error
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 |