Update controlnet_module.py
Browse files- controlnet_module.py +49 -40
controlnet_module.py
CHANGED
|
@@ -774,56 +774,65 @@ class ControlNetProcessor:
|
|
| 774 |
print(f" 📏 Finale Crop-Größe: {crop_x2-crop_x1} × {crop_y2-crop_y1} px")
|
| 775 |
|
| 776 |
|
| 777 |
-
|
| 778 |
-
|
| 779 |
-
|
| 780 |
|
| 781 |
-
|
| 782 |
-
|
| 783 |
-
|
| 784 |
-
|
| 785 |
-
|
| 786 |
-
|
| 787 |
-
|
| 788 |
-
|
| 789 |
|
| 790 |
-
|
| 791 |
-
|
| 792 |
-
|
| 793 |
-
|
| 794 |
-
|
| 795 |
|
| 796 |
-
|
| 797 |
-
|
| 798 |
|
| 799 |
-
|
| 800 |
-
|
| 801 |
-
|
| 802 |
-
|
| 803 |
|
| 804 |
-
|
| 805 |
-
|
| 806 |
-
|
| 807 |
|
| 808 |
-
|
| 809 |
-
|
| 810 |
-
|
| 811 |
|
| 812 |
-
|
| 813 |
-
|
| 814 |
-
|
| 815 |
|
| 816 |
-
|
| 817 |
-
|
| 818 |
-
|
| 819 |
-
|
| 820 |
|
| 821 |
-
|
| 822 |
-
|
| 823 |
-
|
| 824 |
|
| 825 |
-
|
| 826 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 827 |
|
| 828 |
# ============================================================
|
| 829 |
# SAM-AUSFÜHRUNG
|
|
|
|
| 774 |
print(f" 📏 Finale Crop-Größe: {crop_x2-crop_x1} × {crop_y2-crop_y1} px")
|
| 775 |
|
| 776 |
|
| 777 |
+
# Bild ausschneiden- mit besten verfügbaren Crop der nach 3 Iterationen berechnet wurde
|
| 778 |
+
cropped_image = original_image.crop((crop_x1, crop_y1, crop_x2, crop_y2))
|
| 779 |
+
print(f" ✅ Quadratischer Ausschnitt erstellt: {cropped_image.size}")
|
| 780 |
|
| 781 |
+
# ============================================================
|
| 782 |
+
# BBox-Koordinaten transformieren wegen neuer Koordinatenausrichtung (anderer Nullpunkt)
|
| 783 |
+
# ============================================================
|
| 784 |
+
print("📐 SCHRITT 3: BBox-KOORDINATEN TRANSFORMIEREN")
|
| 785 |
+
rel_x1 = x1 - crop_x1
|
| 786 |
+
rel_y1 = y1 - crop_y1
|
| 787 |
+
rel_x2 = x2 - crop_x1
|
| 788 |
+
rel_y2 = y2 - crop_y1
|
| 789 |
|
| 790 |
+
# Sicherstellen, dass BBox innerhalb des Crops liegt
|
| 791 |
+
rel_x1 = max(0, rel_x1)
|
| 792 |
+
rel_y1 = max(0, rel_y1)
|
| 793 |
+
rel_x2 = min(cropped_image.width, rel_x2)
|
| 794 |
+
rel_y2 = min(cropped_image.height, rel_y2)
|
| 795 |
|
| 796 |
+
print(f" 🎯 Relative BBox im Crop: [{rel_x1}, {rel_y1}, {rel_x2}, {rel_y2}]")
|
| 797 |
+
print(f" 📏 Relative BBox Größe: {rel_x2-rel_x1} × {rel_y2-rel_y1} px")
|
| 798 |
|
| 799 |
+
# ============================================================
|
| 800 |
+
# INTENSIVE BILDAUFBEREITUNG FÜR GESICHTSERKENNUNG
|
| 801 |
+
# ============================================================
|
| 802 |
+
print("🔍 SCHRITT 4: ERWEITERTE BILDAUFBEREITUNG FÜR GESICHTSERKENNUNG")
|
| 803 |
|
| 804 |
+
# 1. Kontrast verstärken
|
| 805 |
+
contrast_enhancer = ImageEnhance.Contrast(cropped_image)
|
| 806 |
+
enhanced_image = contrast_enhancer.enhance(1.8) # 80% mehr Kontrast
|
| 807 |
|
| 808 |
+
# 2. Schärfe erhöhen für bessere Kantenerkennung
|
| 809 |
+
sharpness_enhancer = ImageEnhance.Sharpness(enhanced_image)
|
| 810 |
+
enhanced_image = sharpness_enhancer.enhance(2.0) # 100% mehr Schärfe
|
| 811 |
|
| 812 |
+
# 3. Helligkeit anpassen
|
| 813 |
+
brightness_enhancer = ImageEnhance.Brightness(enhanced_image)
|
| 814 |
+
enhanced_image = brightness_enhancer.enhance(1.1) # 10% heller
|
| 815 |
|
| 816 |
+
print(f" ✅ Erweiterte Bildaufbereitung abgeschlossen")
|
| 817 |
+
print(f" • Kontrast: +80%")
|
| 818 |
+
print(f" • Schärfe: +100%")
|
| 819 |
+
print(f" • Helligkeit: +10%")
|
| 820 |
|
| 821 |
+
# Für SAM: Verwende aufbereiteten Ausschnitt
|
| 822 |
+
image = enhanced_image
|
| 823 |
+
x1, y1, x2, y2 = rel_x1, rel_y1, rel_x2, rel_y2
|
| 824 |
|
| 825 |
+
print(" 🔄 SAM wird auf aufbereitetem Ausschnitt ausgeführt")
|
| 826 |
+
print(f" 📊 SAM-Eingabegröße: {image.size}")
|
| 827 |
+
|
| 828 |
+
|
| 829 |
+
# Variablen für späteres Zurücktransformieren setzen
|
| 830 |
+
needs_transform_back = True
|
| 831 |
+
transform_offset = (crop_x1, crop_y1)
|
| 832 |
+
|
| 833 |
+
|
| 834 |
+
|
| 835 |
+
|
| 836 |
|
| 837 |
# ============================================================
|
| 838 |
# SAM-AUSFÜHRUNG
|