Spaces:
Sleeping
Sleeping
Update ui.py
Browse files
ui.py
CHANGED
|
@@ -155,6 +155,116 @@ def mock_update_info(mode):
|
|
| 155 |
"`[UNREALISTISCH], [ASYMETRISCH]`"
|
| 156 |
)
|
| 157 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 158 |
# ==================== UI-DEFINITION ====================
|
| 159 |
def main_ui():
|
| 160 |
"""Haupt-UI-Funktion (angepasst für 3 Modi)"""
|
|
|
|
| 155 |
"`[UNREALISTISCH], [ASYMETRISCH]`"
|
| 156 |
)
|
| 157 |
|
| 158 |
+
def sort_coordinates(x1, y1, x2, y2):
|
| 159 |
+
"""Sortiert Koordinaten, so dass x1 <= x2 und y1 <= y2"""
|
| 160 |
+
sorted_x1 = min(x1, x2)
|
| 161 |
+
sorted_x2 = max(x1, x2)
|
| 162 |
+
sorted_y1 = min(y1, y2)
|
| 163 |
+
sorted_y2 = max(y1, y2)
|
| 164 |
+
return sorted_x1, sorted_y1, sorted_x2, sorted_y2
|
| 165 |
+
|
| 166 |
+
#Rahmendicke für alle Bildgrößen
|
| 167 |
+
def create_preview_image(image, bbox_coords, mode):
|
| 168 |
+
"""
|
| 169 |
+
ERWEITERTE FUNKTION: Erstellt Vorschau mit dynamischer Rahmendicke
|
| 170 |
+
|
| 171 |
+
Die Rahmendicke skaliert basierend auf der Bildgröße:
|
| 172 |
+
- Kleine Bilder: Mindestdicke 8px
|
| 173 |
+
- Große Bilder: Dicke = Bildbreite / 200 (z.B. 4096px → ~20px Dicke)
|
| 174 |
+
"""
|
| 175 |
+
if image is None:
|
| 176 |
+
return None
|
| 177 |
+
|
| 178 |
+
preview = image.copy()
|
| 179 |
+
draw = ImageDraw.Draw(preview)
|
| 180 |
+
|
| 181 |
+
# Farben basierend auf Modus
|
| 182 |
+
if mode == "environment_change":
|
| 183 |
+
border_color = (0, 255, 0, 180) # Grün für Umgebung
|
| 184 |
+
mode_text = "UMGEBUNG ÄNDERN (Bereich geschützt)"
|
| 185 |
+
box_color = (255, 255, 0, 200) # Gelb für geschützten Bereich
|
| 186 |
+
text_bg_color = (0, 128, 0, 160) # Dunkelgrün
|
| 187 |
+
|
| 188 |
+
elif mode == "focus_change":
|
| 189 |
+
border_color = (255, 165, 0, 180) # Orange für Focus
|
| 190 |
+
mode_text = "FOCUS VERÄNDERN (Bereich+Körper)"
|
| 191 |
+
box_color = (255, 0, 0, 200) # Rot für Veränderungsbereich
|
| 192 |
+
text_bg_color = (255, 140, 0, 160) # Dunkelorange
|
| 193 |
+
|
| 194 |
+
elif mode == "face_only_change":
|
| 195 |
+
border_color = (255, 0, 0, 180) # Rot für nur Gesicht
|
| 196 |
+
mode_text = "NUR BEREICH VERÄNDERN"
|
| 197 |
+
box_color = (255, 0, 0, 200) # Rot für Veränderungsbereich
|
| 198 |
+
text_bg_color = (128, 0, 0, 160) # Dunkelrot
|
| 199 |
+
else:
|
| 200 |
+
# Fallback
|
| 201 |
+
border_color = (128, 128, 128, 180)
|
| 202 |
+
mode_text = "UNBEKANNTER MODUS"
|
| 203 |
+
box_color = (128, 128, 128, 200)
|
| 204 |
+
text_bg_color = (64, 64, 64, 160)
|
| 205 |
+
|
| 206 |
+
# ==============================================
|
| 207 |
+
# WICHTIG: DYNAMISCHE RAHMENDICKE
|
| 208 |
+
# ==============================================
|
| 209 |
+
# Basierend auf Bildgröße skalieren
|
| 210 |
+
# Formel: Mindestens 8px, bei großen Bildern dicker (Breite/200)
|
| 211 |
+
border_width = max(8, image.width // 200)
|
| 212 |
+
box_width = max(3, image.width // 400) # BBox-Rahmen etwas dünner
|
| 213 |
+
|
| 214 |
+
print(f"📐 Dynamische Rahmendicke für {image.width}x{image.height}:")
|
| 215 |
+
print(f" - Außenrahmen: {border_width}px")
|
| 216 |
+
print(f" - BBox-Rahmen: {box_width}px")
|
| 217 |
+
|
| 218 |
+
# 1. ÄUßERER RAHMEN (um gesamtes Bild)
|
| 219 |
+
draw.rectangle([0, 0, preview.width-1, preview.height-1],
|
| 220 |
+
outline=border_color, width=border_width)
|
| 221 |
+
|
| 222 |
+
if bbox_coords and all(coord is not None for coord in bbox_coords):
|
| 223 |
+
# Sortiere Koordinaten
|
| 224 |
+
x1, y1, x2, y2 = sort_coordinates(*bbox_coords)
|
| 225 |
+
|
| 226 |
+
# Stelle sicher, dass die Koordinaten innerhalb des Bildes liegen
|
| 227 |
+
x1 = max(0, min(x1, preview.width-1))
|
| 228 |
+
y1 = max(0, min(y1, preview.height-1))
|
| 229 |
+
x2 = max(0, min(x2, preview.width-1))
|
| 230 |
+
y2 = max(0, min(y2, preview.height-1))
|
| 231 |
+
|
| 232 |
+
# Nur zeichnen, wenn die Bounding Box gültig ist
|
| 233 |
+
if x2 > x1 and y2 > y1:
|
| 234 |
+
# 2. BBOX-RAHMEN (mit dynamischer Dicke)
|
| 235 |
+
draw.rectangle([x1, y1, x2, y2], outline=box_color, width=box_width)
|
| 236 |
+
|
| 237 |
+
text_color = (255, 255, 255)
|
| 238 |
+
|
| 239 |
+
# 3. TEXT-LABEL (skaliert auch Schriftgröße optional)
|
| 240 |
+
text_y = max(0, y1 - 25)
|
| 241 |
+
|
| 242 |
+
# Verwende textbbox um Textgröße zu berechnen
|
| 243 |
+
from PIL import ImageFont
|
| 244 |
+
try:
|
| 245 |
+
# Versuche eine skalierbare Schrift
|
| 246 |
+
font_size = max(12, image.width // 50) # Dynamische Schriftgröße
|
| 247 |
+
font = ImageFont.truetype("arial.ttf", font_size)
|
| 248 |
+
text_bbox = draw.textbbox((x1, text_y), mode_text, font=font)
|
| 249 |
+
draw.text((x1, text_y), mode_text, fill=text_color, font=font)
|
| 250 |
+
except:
|
| 251 |
+
# Fallback ohne spezielle Schrift
|
| 252 |
+
text_bbox = draw.textbbox((x1, text_y), mode_text)
|
| 253 |
+
draw.text((x1, text_y), mode_text, fill=text_color)
|
| 254 |
+
|
| 255 |
+
# Hintergrund für Text
|
| 256 |
+
draw.rectangle([text_bbox[0]-5, text_bbox[1]-2,
|
| 257 |
+
text_bbox[2]+5, text_bbox[3]+2],
|
| 258 |
+
fill=text_bg_color)
|
| 259 |
+
|
| 260 |
+
# Text nochmal darüber zeichnen
|
| 261 |
+
try:
|
| 262 |
+
draw.text((x1, text_y), mode_text, fill=text_color, font=font)
|
| 263 |
+
except:
|
| 264 |
+
draw.text((x1, text_y), mode_text, fill=text_color)
|
| 265 |
+
|
| 266 |
+
return preview
|
| 267 |
+
|
| 268 |
# ==================== UI-DEFINITION ====================
|
| 269 |
def main_ui():
|
| 270 |
"""Haupt-UI-Funktion (angepasst für 3 Modi)"""
|