Astridkraft commited on
Commit
862d1fa
·
verified ·
1 Parent(s): 9a68db5

Update controlnet_module.py

Browse files
Files changed (1) hide show
  1. 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
- # Crop = BBox × 2.5 (ERHÖHT für mehr Kontext)
674
- # ============================================================
675
- print("✂️ SCHRITT 2: ERSTELLE QUADRATISCHEN AUSSCHNITT (BBox × 2.5)")
676
 
677
- # BBox-Zentrum berechnen
678
- bbox_center_x = (x1 + x2) // 2
679
- bbox_center_y = (y1 + y2) // 2
680
- print(f" 📍 BBox-Zentrum: ({bbox_center_x}, {bbox_center_y})")
 
 
681
 
682
- # Größte Dimension der BBox finden
683
- bbox_width = x2 - x1
684
- bbox_height = y2 - y1
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
- # Crop-Größe berechnen (BBox × 2.5)
690
- crop_size = int(bbox_max_dim * 2.5)
691
- print(f" 🎯 Ziel-Crop-Größe: {crop_size} × {crop_size} px (BBox × 2.5)")
 
 
692
 
693
- # Crop-Koordinaten berechnen (zentriert um BBox)
694
- crop_x1 = bbox_center_x - crop_size // 2
695
- crop_y1 = bbox_center_y - crop_size // 2
696
- crop_x2 = crop_x1 + crop_size
697
- crop_y2 = crop_y1 + crop_size
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
- # ITERATIVE ANPASSUNG für bessere Crop-Größe
707
- max_iterations = 3
708
- print(f" 🔄 Iterative Crop-Anpassung (max. {max_iterations} Versuche)")
709
 
710
- for iteration in range(max_iterations):
711
- actual_crop_width = crop_x2 - crop_x1
712
- actual_crop_height = crop_y2 - crop_y1
713
 
714
- # Prüfen ob Crop groß genug ist
715
- if actual_crop_width >= crop_size and actual_crop_height >= crop_size:
716
- print(f" ✅ Crop-Größe OK nach {iteration} Iteration(en): {actual_crop_width}×{actual_crop_height} px")
717
- break
718
 
719
- print(f" 🔄 Iteration {iteration+1}: Crop zu klein ({actual_crop_width}×{actual_crop_height})")
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: