qqwjq1981 commited on
Commit
0d16938
Β·
verified Β·
1 Parent(s): f70f4f3

Update utils/bubble_utils.py

Browse files
Files changed (1) hide show
  1. utils/bubble_utils.py +27 -4
utils/bubble_utils.py CHANGED
@@ -15,6 +15,19 @@ from utils.polygon_utils import (
15
  )
16
  from utils.bubble_detect import detect_speech_bubbles_robust
17
  from utils.u2net_detector import detect_bubbles_u2net
 
 
 
 
 
 
 
 
 
 
 
 
 
18
 
19
 
20
  # ======================== Debug Visualization ============================
@@ -79,11 +92,21 @@ def bubble_pipeline_single(file_obj, num_chunks=1, polygon_strategy="hybrid", de
79
  print(f"πŸ“„ bubble_pipeline_single: filename={filename}, size={full_img.size}")
80
 
81
  # -------------------------------------------------------
82
- # 2) Robust bubble detection
83
  # -------------------------------------------------------
84
- bubble_polygons = detect_speech_bubbles_robust(full_img, min_area=400)
85
- # bubble_polygons = detect_bubbles_u2net(full_img)
86
- print(f"πŸ” Detected {len(bubble_polygons)} speech bubbles")
 
 
 
 
 
 
 
 
 
 
87
 
88
  if debug:
89
  visualize_all_debug(full_img, [], bubble_polygons,
 
15
  )
16
  from utils.bubble_detect import detect_speech_bubbles_robust
17
  from utils.u2net_detector import detect_bubbles_u2net
18
+ from utils.bubble_detect_rtdetr import detect_bubbles_rtdetr
19
+
20
+ def bbox_to_polygon(bbox):
21
+ """
22
+ Convert RT-DETR [x1, y1, x2, y2] box into a 4-point polygon.
23
+ """
24
+ x1, y1, x2, y2 = bbox
25
+ return [
26
+ (int(x1), int(y1)),
27
+ (int(x2), int(y1)),
28
+ (int(x2), int(y2)),
29
+ (int(x1), int(y2)),
30
+ ]
31
 
32
 
33
  # ======================== Debug Visualization ============================
 
92
  print(f"πŸ“„ bubble_pipeline_single: filename={filename}, size={full_img.size}")
93
 
94
  # -------------------------------------------------------
95
+ # 2) Bubble detection (RT-DETR comic model)
96
  # -------------------------------------------------------
97
+ detections = detect_bubbles_rtdetr(full_img)
98
+
99
+ bubble_boxes = [d["bbox"] for d in detections if d["class"] == 0] # pure bubble shapes
100
+ bubble_text_boxes = [d["bbox"] for d in detections if d["class"] == 1] # text inside bubble
101
+ free_text_boxes = [d["bbox"] for d in detections if d["class"] == 2] # text outside bubble
102
+
103
+ # Convert bubble boxes β†’ polygons for your polygon-based pipeline
104
+ bubble_polygons = [bbox_to_polygon(b) for b in bubble_boxes]
105
+
106
+ print(f"πŸ” RT-DETR: {len(bubble_polygons)} bubbles, "
107
+ f"{len(bubble_text_boxes)} bubble-text regions, "
108
+ f"{len(free_text_boxes)} free-text regions")
109
+
110
 
111
  if debug:
112
  visualize_all_debug(full_img, [], bubble_polygons,