Update controlnet_module.py
Browse files- controlnet_module.py +39 -42
controlnet_module.py
CHANGED
|
@@ -665,58 +665,55 @@ class ControlNetProcessor:
|
|
| 665 |
use_crop_strategy = True
|
| 666 |
|
| 667 |
if use_crop_strategy:
|
| 668 |
-
|
| 669 |
-
|
| 670 |
-
|
|
|
|
|
|
|
| 671 |
|
| 672 |
-
|
| 673 |
-
|
| 674 |
-
|
| 675 |
-
|
| 676 |
|
| 677 |
-
|
| 678 |
-
|
| 679 |
-
|
| 680 |
-
|
|
|
|
|
|
|
| 681 |
|
| 682 |
-
|
| 683 |
-
|
| 684 |
-
|
| 685 |
-
bbox_max_dim = max(bbox_width, bbox_height)
|
| 686 |
-
print(f" 📏 BBox Dimensionen: {bbox_width} × {bbox_height} px")
|
| 687 |
-
print(f" 📐 Maximale BBox-Dimension: {bbox_max_dim} px")
|
| 688 |
|
| 689 |
-
|
| 690 |
-
|
| 691 |
-
|
|
|
|
|
|
|
| 692 |
|
| 693 |
-
|
| 694 |
-
|
| 695 |
-
|
| 696 |
-
|
| 697 |
-
|
| 698 |
-
|
| 699 |
-
# Sicherstellen, dass Crop innerhalb der Bildgrenzen bleibt
|
| 700 |
-
crop_x1 = max(0, crop_x1)
|
| 701 |
-
crop_y1 = max(0, crop_y1)
|
| 702 |
-
crop_x2 = min(original_image.width, crop_x2)
|
| 703 |
-
crop_y2 = min(original_image.height, crop_y2)
|
| 704 |
|
| 705 |
|
| 706 |
-
|
| 707 |
-
|
| 708 |
-
|
| 709 |
|
| 710 |
-
|
| 711 |
-
|
| 712 |
-
|
| 713 |
|
| 714 |
-
|
| 715 |
-
|
| 716 |
-
|
| 717 |
-
|
| 718 |
|
| 719 |
-
|
| 720 |
|
| 721 |
# BREITE anpassen (falls nötig)
|
| 722 |
if actual_crop_width < crop_size:
|
|
|
|
| 665 |
use_crop_strategy = True
|
| 666 |
|
| 667 |
if use_crop_strategy:
|
| 668 |
+
#
|
| 669 |
+
# ============================================================
|
| 670 |
+
# Crop = BBox × 2.5 (ERHÖHT für mehr Kontext)
|
| 671 |
+
# ============================================================
|
| 672 |
+
print("✂️ SCHRITT 2: ERSTELLE QUADRATISCHEN AUSSCHNITT (BBox × 2.5)")
|
| 673 |
|
| 674 |
+
# BBox-Zentrum berechnen
|
| 675 |
+
bbox_center_x = (x1 + x2) // 2
|
| 676 |
+
bbox_center_y = (y1 + y2) // 2
|
| 677 |
+
print(f" 📍 BBox-Zentrum: ({bbox_center_x}, {bbox_center_y})")
|
| 678 |
|
| 679 |
+
# Größte Dimension der BBox finden
|
| 680 |
+
bbox_width = x2 - x1
|
| 681 |
+
bbox_height = y2 - y1
|
| 682 |
+
bbox_max_dim = max(bbox_width, bbox_height)
|
| 683 |
+
print(f" 📏 BBox Dimensionen: {bbox_width} × {bbox_height} px")
|
| 684 |
+
print(f" 📐 Maximale BBox-Dimension: {bbox_max_dim} px")
|
| 685 |
|
| 686 |
+
# Crop-Größe berechnen (BBox × 2.5)
|
| 687 |
+
crop_size = int(bbox_max_dim * 2.5)
|
| 688 |
+
print(f" 🎯 Ziel-Crop-Größe: {crop_size} × {crop_size} px (BBox × 2.5)")
|
|
|
|
|
|
|
|
|
|
| 689 |
|
| 690 |
+
# Crop-Koordinaten berechnen (zentriert um BBox)
|
| 691 |
+
crop_x1 = bbox_center_x - crop_size // 2
|
| 692 |
+
crop_y1 = bbox_center_y - crop_size // 2
|
| 693 |
+
crop_x2 = crop_x1 + crop_size
|
| 694 |
+
crop_y2 = crop_y1 + crop_size
|
| 695 |
|
| 696 |
+
# Sicherstellen, dass Crop innerhalb der Bildgrenzen bleibt
|
| 697 |
+
crop_x1 = max(0, crop_x1)
|
| 698 |
+
crop_y1 = max(0, crop_y1)
|
| 699 |
+
crop_x2 = min(original_image.width, crop_x2)
|
| 700 |
+
crop_y2 = min(original_image.height, crop_y2)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 701 |
|
| 702 |
|
| 703 |
+
# ITERATIVE ANPASSUNG für bessere Crop-Größe
|
| 704 |
+
max_iterations = 3
|
| 705 |
+
print(f" 🔄 Iterative Crop-Anpassung (max. {max_iterations} Versuche)")
|
| 706 |
|
| 707 |
+
for iteration in range(max_iterations):
|
| 708 |
+
actual_crop_width = crop_x2 - crop_x1
|
| 709 |
+
actual_crop_height = crop_y2 - crop_y1
|
| 710 |
|
| 711 |
+
# Prüfen ob Crop groß genug ist
|
| 712 |
+
if actual_crop_width >= crop_size and actual_crop_height >= crop_size:
|
| 713 |
+
print(f" ✅ Crop-Größe OK nach {iteration} Iteration(en): {actual_crop_width}×{actual_crop_height} px")
|
| 714 |
+
break
|
| 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:
|