Update controlnet_module.py
Browse files- controlnet_module.py +51 -51
controlnet_module.py
CHANGED
|
@@ -715,63 +715,63 @@ class ControlNetProcessor:
|
|
| 715 |
|
| 716 |
print(f" 🔄 Iteration {iteration+1}: Crop zu klein ({actual_crop_width}×{actual_crop_height})")
|
| 717 |
|
| 718 |
-
|
| 719 |
-
|
| 720 |
-
|
| 721 |
-
|
| 722 |
-
|
| 723 |
-
|
| 724 |
-
|
| 725 |
-
|
| 726 |
-
|
| 727 |
-
|
| 728 |
-
|
| 729 |
-
|
| 730 |
-
|
| 731 |
|
| 732 |
-
|
| 733 |
-
|
| 734 |
-
|
| 735 |
|
| 736 |
-
|
| 737 |
-
|
| 738 |
-
|
| 739 |
-
|
| 740 |
-
|
| 741 |
-
|
| 742 |
-
|
| 743 |
-
|
| 744 |
-
|
| 745 |
-
|
| 746 |
-
|
| 747 |
-
|
| 748 |
-
|
| 749 |
|
| 750 |
-
|
| 751 |
-
|
| 752 |
-
|
| 753 |
|
| 754 |
-
|
| 755 |
-
|
| 756 |
-
|
| 757 |
-
|
| 758 |
-
|
| 759 |
|
| 760 |
-
|
| 761 |
-
|
| 762 |
-
|
| 763 |
-
|
| 764 |
-
|
| 765 |
|
| 766 |
-
|
| 767 |
-
|
| 768 |
-
|
| 769 |
-
|
| 770 |
-
|
| 771 |
-
|
| 772 |
-
|
| 773 |
-
|
| 774 |
-
|
| 775 |
|
| 776 |
|
| 777 |
# Bild ausschneiden- 2,5 mal so groß und quadratisch wie BBox
|
|
|
|
| 715 |
|
| 716 |
print(f" 🔄 Iteration {iteration+1}: Crop zu klein ({actual_crop_width}×{actual_crop_height})")
|
| 717 |
|
| 718 |
+
# BREITE anpassen (falls nötig)
|
| 719 |
+
if actual_crop_width < crop_size:
|
| 720 |
+
if crop_x1 == 0: # Am linken Rand
|
| 721 |
+
crop_x2 = min(original_image.width, crop_x1 + crop_size)
|
| 722 |
+
print(f" ← Breite angepasst (linker Rand): crop_x2 = {crop_x2}")
|
| 723 |
+
elif crop_x2 == original_image.width: # Am rechten Rand
|
| 724 |
+
crop_x1 = max(0, crop_x2 - crop_size)
|
| 725 |
+
print(f" → Breite angepasst (rechter Rand): crop_x1 = {crop_x1}")
|
| 726 |
+
else:
|
| 727 |
+
# Nicht am Rand - zentriert erweitern
|
| 728 |
+
missing_width = crop_size - actual_crop_width
|
| 729 |
+
expand_left = missing_width // 2
|
| 730 |
+
expand_right = missing_width - expand_left
|
| 731 |
|
| 732 |
+
crop_x1 = max(0, crop_x1 - expand_left)
|
| 733 |
+
crop_x2 = min(original_image.width, crop_x2 + expand_right)
|
| 734 |
+
print(f" ↔ Zentriert erweitert um {missing_width}px")
|
| 735 |
|
| 736 |
+
# HÖHE anpassen (falls nötig)
|
| 737 |
+
if actual_crop_height < crop_size:
|
| 738 |
+
if crop_y1 == 0: # Am oberen Rand
|
| 739 |
+
crop_y2 = min(original_image.height, crop_y1 + crop_size)
|
| 740 |
+
print(f" ↑ Höhe angepasst (oberer Rand): crop_y2 = {crop_y2}")
|
| 741 |
+
elif crop_y2 == original_image.height: # Am unteren Rand
|
| 742 |
+
crop_y1 = max(0, crop_y2 - crop_size)
|
| 743 |
+
print(f" ↓ Höhe angepasst (unterer Rand): crop_y1 = {crop_y1}")
|
| 744 |
+
else:
|
| 745 |
+
# Nicht am Rand - zentriert erweitern
|
| 746 |
+
missing_height = crop_size - actual_crop_height
|
| 747 |
+
expand_top = missing_height // 2
|
| 748 |
+
expand_bottom = missing_height - expand_top
|
| 749 |
|
| 750 |
+
crop_y1 = max(0, crop_y1 - expand_top)
|
| 751 |
+
crop_y2 = min(original_image.height, crop_y2 + expand_bottom)
|
| 752 |
+
print(f" ↕ Zentriert erweitert um {missing_height}px")
|
| 753 |
|
| 754 |
+
# Sicherstellen, dass innerhalb der Bildgrenzen
|
| 755 |
+
crop_x1 = max(0, crop_x1)
|
| 756 |
+
crop_y1 = max(0, crop_y1)
|
| 757 |
+
crop_x2 = min(original_image.width, crop_x2)
|
| 758 |
+
crop_y2 = min(original_image.height, crop_y2)
|
| 759 |
|
| 760 |
+
# Letzte Iteration erreicht?
|
| 761 |
+
if iteration == max_iterations - 1:
|
| 762 |
+
actual_crop_width = crop_x2 - crop_x1
|
| 763 |
+
actual_crop_height = crop_y2 - crop_y1
|
| 764 |
+
print(f" ⚠️ Max. Iterationen erreicht. Finaler Crop: {actual_crop_width}×{actual_crop_height} px")
|
| 765 |
|
| 766 |
+
# Warnung wenn immer noch zu klein
|
| 767 |
+
if actual_crop_width < crop_size or actual_crop_height < crop_size:
|
| 768 |
+
min_acceptable = int(bbox_max_dim * 1.8) # Mindestens 1.8× BBox
|
| 769 |
+
if actual_crop_width < min_acceptable or actual_crop_height < min_acceptable:
|
| 770 |
+
print(f" 🚨 KRITISCH: Crop immer noch zu klein ({actual_crop_width}×{actual_crop_height})")
|
| 771 |
+
print(f" 🚨 SAM könnte Probleme haben!")
|
| 772 |
+
|
| 773 |
+
print(f" 🔲 Finaler Crop-Bereich: [{crop_x1}, {crop_y1}, {crop_x2}, {crop_y2}]")
|
| 774 |
+
print(f" 📏 Finale Crop-Größe: {crop_x2-crop_x1} × {crop_y2-crop_y1} px")
|
| 775 |
|
| 776 |
|
| 777 |
# Bild ausschneiden- 2,5 mal so groß und quadratisch wie BBox
|