File size: 1,604 Bytes
0f9b509
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# services/thermal_service.py
import cv2
import numpy as np

def process_thermal(frame):
    """
    Process thermal camera data to detect hot spots.
    Args:
        frame: Input frame (grayscale, representing temperature)
    Returns:
        dict: Hot spot detection results with numbered labels
        numpy array: Annotated frame
    """
    # Apply thresholding to detect hot spots (high temperature areas)
    _, hot_mask = cv2.threshold(frame, 200, 255, cv2.THRESH_BINARY)
    contours, _ = cv2.findContours(hot_mask, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)

    detections = []
    line_counter = 1  # Initialize counter for numbered labels

    # Convert frame to BGR for annotations
    frame_bgr = cv2.cvtColor(frame, cv2.COLOR_GRAY2BGR)

    for contour in contours:
        area = cv2.contourArea(contour)
        if area < 50:  # Filter small areas
            continue
        x, y, w, h = cv2.boundingRect(contour)
        x_min, y_min, x_max, y_max = x, y, x + w, y + h

        # Add numbered label
        detection_label = f"Line {line_counter} - Hot Spot"
        detections.append({
            "label": detection_label,
            "coordinates": [x_min, y_min, x_max, y_max]
        })

        # Draw bounding box and label
        color = (255, 0, 0)  # Red for hot spots
        cv2.rectangle(frame_bgr, (x_min, y_min), (x_max, y_max), color, 2)
        cv2.putText(frame_bgr, detection_label, (x_min, y_min - 10), 
                    cv2.FONT_HERSHEY_SIMPLEX, 0.5, color, 2)
        
        line_counter += 1

    return {"detections": detections, "frame": frame_bgr}