qqwjq1981 commited on
Commit
a02eb69
·
verified ·
1 Parent(s): f995db3

Update utils/bubble_utils.py

Browse files
Files changed (1) hide show
  1. utils/bubble_utils.py +18 -4
utils/bubble_utils.py CHANGED
@@ -10,7 +10,7 @@ from utils.polygon_utils import (
10
  draw_translated_text_convex,
11
  shrink_or_expand_polygon,
12
  FONT_PATH,
13
- correct_ocr_polygons_with_bubbles,
14
  render_translated_chunk,
15
  )
16
  from utils.bubble_detect import detect_speech_bubbles_robust
@@ -70,6 +70,21 @@ def extract_and_translate_with_masks(full_img, interior_polygons):
70
 
71
  return translations
72
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
73
  # ======================== Debug Visualization ============================
74
 
75
  def visualize_all_debug(img, translations, bubble_polygons, step_name="debug", prefix="debug"):
@@ -164,9 +179,8 @@ def bubble_pipeline_single(file_obj, num_chunks=1, polygon_strategy="hybrid", de
164
  # 4. Match OCR polygons to bubble polygons
165
  # -------------------------------------------------------
166
  if bubble_polygons:
167
- translations = correct_ocr_polygons_with_bubbles(
168
- translations, bubble_polygons, strategy=polygon_strategy
169
- )
170
  else:
171
  print("⚠️ No bubble polygons → skip polygon correction")
172
 
 
10
  draw_translated_text_convex,
11
  shrink_or_expand_polygon,
12
  FONT_PATH,
13
+ match_polygon_to_bubble_by_overlap,
14
  render_translated_chunk,
15
  )
16
  from utils.bubble_detect import detect_speech_bubbles_robust
 
70
 
71
  return translations
72
 
73
+ def match_translations_to_bubbles(translations, bubble_polygons, min_overlap=0.10):
74
+ """
75
+ Add matched_bubble_idx to each OCR translation.
76
+ OCR polygon is NOT corrected.
77
+ """
78
+ for t in translations:
79
+ ocr_poly = t.get("polygon")
80
+ if not ocr_poly:
81
+ continue
82
+
83
+ idx = match_polygon_to_bubble_by_overlap(ocr_poly, bubble_polygons, min_overlap)
84
+ t["matched_bubble_idx"] = idx
85
+
86
+ return translations
87
+
88
  # ======================== Debug Visualization ============================
89
 
90
  def visualize_all_debug(img, translations, bubble_polygons, step_name="debug", prefix="debug"):
 
179
  # 4. Match OCR polygons to bubble polygons
180
  # -------------------------------------------------------
181
  if bubble_polygons:
182
+ print("🔄 Matching OCR → Bubble regions...")
183
+ translations = match_translations_to_bubbles(translations, bubble_polygons)
 
184
  else:
185
  print("⚠️ No bubble polygons → skip polygon correction")
186