Spaces:
Runtime error
Runtime error
Update services/thermal_service.py
Browse files- services/thermal_service.py +22 -10
services/thermal_service.py
CHANGED
@@ -1,17 +1,29 @@
|
|
1 |
# services/thermal_service.py
|
2 |
|
3 |
-
|
|
|
4 |
|
5 |
-
# ✅
|
6 |
-
|
7 |
|
8 |
def detect_thermal_anomalies(image_path):
|
9 |
-
|
10 |
-
|
11 |
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
|
|
16 |
|
17 |
-
return
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
|