Update app.py
Browse files
app.py
CHANGED
@@ -134,9 +134,10 @@ def create_heatmap_overlay(image, box, score):
|
|
134 |
width = x2 - x1
|
135 |
height = y2 - y1
|
136 |
|
|
|
137 |
steps = 30
|
138 |
for i in range(steps):
|
139 |
-
alpha = int(
|
140 |
base_color = get_temp_color(score)
|
141 |
color = base_color + (alpha,)
|
142 |
|
@@ -149,8 +150,9 @@ def create_heatmap_overlay(image, box, score):
|
|
149 |
outline=None
|
150 |
)
|
151 |
|
|
|
152 |
border_color = get_temp_color(score) + (200,)
|
153 |
-
draw.rectangle([x1, y1, x2, y2], outline=border_color, width=
|
154 |
|
155 |
return overlay
|
156 |
|
@@ -163,21 +165,27 @@ def draw_boxes(image, predictions):
|
|
163 |
box = pred['box']
|
164 |
score = pred['score']
|
165 |
|
|
|
166 |
heatmap = create_heatmap_overlay(image, box, score)
|
167 |
result_image = Image.alpha_composite(result_image, heatmap)
|
168 |
|
|
|
169 |
draw = ImageDraw.Draw(result_image)
|
170 |
-
temp = 36.5 + (score * 2.5)
|
171 |
label = f"{translate_label(pred['label'])} ({score:.1%}) • {temp:.1f}°C"
|
172 |
|
|
|
173 |
text_bbox = draw.textbbox((box['xmin'], box['ymin']-25), label)
|
174 |
padding = 3
|
175 |
text_bbox = (
|
176 |
-
text_bbox[0]-padding,
|
177 |
-
text_bbox[
|
|
|
|
|
178 |
)
|
179 |
draw.rectangle(text_bbox, fill="#000000CC")
|
180 |
|
|
|
181 |
draw.text(
|
182 |
(box['xmin'], box['ymin']-25),
|
183 |
label,
|
|
|
134 |
width = x2 - x1
|
135 |
height = y2 - y1
|
136 |
|
137 |
+
# Fond semi-transparent avec dégradé
|
138 |
steps = 30
|
139 |
for i in range(steps):
|
140 |
+
alpha = int(100 * (1 - (i / steps))) # Réduit l'opacité maximale à 100
|
141 |
base_color = get_temp_color(score)
|
142 |
color = base_color + (alpha,)
|
143 |
|
|
|
150 |
outline=None
|
151 |
)
|
152 |
|
153 |
+
# Bordure plus visible
|
154 |
border_color = get_temp_color(score) + (200,)
|
155 |
+
draw.rectangle([x1, y1, x2, y2], outline=border_color, width=3)
|
156 |
|
157 |
return overlay
|
158 |
|
|
|
165 |
box = pred['box']
|
166 |
score = pred['score']
|
167 |
|
168 |
+
# Ajout de l'overlay avec heatmap
|
169 |
heatmap = create_heatmap_overlay(image, box, score)
|
170 |
result_image = Image.alpha_composite(result_image, heatmap)
|
171 |
|
172 |
+
# Ajout du texte
|
173 |
draw = ImageDraw.Draw(result_image)
|
174 |
+
temp = 36.5 + (score * 2.5) # Température simulée
|
175 |
label = f"{translate_label(pred['label'])} ({score:.1%}) • {temp:.1f}°C"
|
176 |
|
177 |
+
# Fond noir semi-transparent pour le texte
|
178 |
text_bbox = draw.textbbox((box['xmin'], box['ymin']-25), label)
|
179 |
padding = 3
|
180 |
text_bbox = (
|
181 |
+
text_bbox[0]-padding,
|
182 |
+
text_bbox[1]-padding,
|
183 |
+
text_bbox[2]+padding,
|
184 |
+
text_bbox[3]+padding
|
185 |
)
|
186 |
draw.rectangle(text_bbox, fill="#000000CC")
|
187 |
|
188 |
+
# Texte en blanc avec contour noir
|
189 |
draw.text(
|
190 |
(box['xmin'], box['ymin']-25),
|
191 |
label,
|