surveillance / services /thermal_service.py
SuriRaja's picture
Update services/thermal_service.py
45a917a
raw
history blame
819 Bytes
from transformers import DetrImageProcessor, DetrForObjectDetection
import torch
from PIL import Image
import cv2
# Load model
processor = DetrImageProcessor.from_pretrained("facebook/detr-resnet-50")
model = DetrForObjectDetection.from_pretrained("facebook/detr-resnet-50")
def detect_thermal_anomalies(frame):
image = Image.fromarray(cv2.cvtColor(frame, cv2.COLOR_BGR2RGB))
inputs = processor(images=image, return_tensors="pt")
outputs = model(**inputs)
target_sizes = torch.tensor([image.size[::-1]])
results = processor.post_process_object_detection(outputs, threshold=0.9, target_sizes=target_sizes)[0]
boxes = []
for score, label, box in zip(results["scores"], results["labels"], results["boxes"]):
if score >= 0.9:
boxes.append(box.tolist())
return boxes