surveillance / services /thermal_service.py
SuriRaja's picture
Update services/thermal_service.py
0882703
raw
history blame
883 Bytes
# services/thermal_service.py
import cv2
from transformers import pipeline
# Load HuggingFace DETR model
thermal_detector = pipeline("object-detection", model="facebook/detr-resnet-50")
def detect_thermal_anomalies(image_path):
results = thermal_detector(image_path) # ✅ directly pass path, not NumPy image!
thermal_boxes = []
for result in results:
if result['score'] > 0.7:
box = result['box']
thermal_boxes.append(box)
return thermal_boxes
def overlay_thermal_boxes(image_path, boxes):
image = cv2.imread(image_path)
for box in boxes:
xmin, ymin, xmax, ymax = box['xmin'], box['ymin'], box['xmax'], box['ymax']
cv2.rectangle(image, (xmin, ymin), (xmax, ymax), (0, 0, 255), 2)
cv2.putText(image, 'Hotspot', (xmin, ymin - 10), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 0, 255), 2)
return image