surveillance / services /thermal_service.py
SuriRaja's picture
Update services/thermal_service.py
682cff4
raw
history blame
995 Bytes
from transformers import pipeline
import cv2
# Load DETR model from Hugging Face
object_detector = pipeline("object-detection", model="facebook/detr-resnet-50")
def detect_thermal_anomalies(image_path):
"""
Simulate thermal anomalies using DETR object detection.
If an object has a high confidence and occupies a big bounding box, simulate a "hotspot."
"""
image = cv2.imread(image_path)
results = object_detector(image)
anomalies = []
for result in results:
score = result.get('score', 0)
box = result.get('box', {})
width = box.get('width', 0)
height = box.get('height', 0)
area = width * height
# Simulate: large bounding boxes + high score = thermal anomaly
if score > 0.7 and area > 5000: # adjust thresholds if needed
anomalies.append({
"label": result.get('label', ''),
"score": score,
"bbox": box
})
return anomalies