SuriRaja commited on
Commit
c2dcaee
·
1 Parent(s): 6f3c9ee

Update services/thermal_service.py

Browse files
Files changed (1) hide show
  1. services/thermal_service.py +22 -10
services/thermal_service.py CHANGED
@@ -1,17 +1,29 @@
1
  # services/thermal_service.py
2
 
3
- from ultralytics import YOLO
 
4
 
5
- # ✅ Load directly from the Ultralytics model hub (no .pt file)
6
- thermal_model = YOLO('yolov8n') # Smallest, fast model
7
 
8
  def detect_thermal_anomalies(image_path):
9
- results = thermal_model.predict(image_path)
10
- flagged_boxes = []
11
 
12
- for r in results:
13
- for box in r.boxes:
14
- if box.conf > 0.7:
15
- flagged_boxes.append(box)
 
16
 
17
- return flagged_boxes
 
 
 
 
 
 
 
 
 
 
 
1
  # services/thermal_service.py
2
 
3
+ import cv2
4
+ from transformers import pipeline
5
 
6
+ # ✅ Use DETR model for thermal detection as well
7
+ thermal_detector = pipeline("object-detection", model="facebook/detr-resnet-50")
8
 
9
  def detect_thermal_anomalies(image_path):
10
+ image = cv2.imread(image_path)
11
+ results = thermal_detector(image)
12
 
13
+ thermal_boxes = []
14
+ for result in results:
15
+ if result['score'] > 0.7:
16
+ box = result['box']
17
+ thermal_boxes.append(box)
18
 
19
+ return thermal_boxes
20
+
21
+ def overlay_thermal_boxes(image_path, boxes):
22
+ image = cv2.imread(image_path)
23
+
24
+ for box in boxes:
25
+ xmin, ymin, xmax, ymax = box['xmin'], box['ymin'], box['xmax'], box['ymax']
26
+ cv2.rectangle(image, (xmin, ymin), (xmax, ymax), (0, 0, 255), 2)
27
+ cv2.putText(image, 'Hotspot', (xmin, ymin - 10), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 0, 255), 2)
28
+
29
+ return image