qqwjq1981 commited on
Commit
f0e0cbc
·
verified ·
1 Parent(s): 6ba0dd5

Update utils/polygon_utils.py

Browse files
Files changed (1) hide show
  1. utils/polygon_utils.py +4 -3
utils/polygon_utils.py CHANGED
@@ -1,13 +1,15 @@
1
 
2
  from shapely.geometry import Polygon, MultiPoint
 
3
 
 
4
 
5
  def merge_polygons_to_convex_hull(polygons):
6
  points = [pt for poly in polygons for pt in poly]
7
  hull = MultiPoint(points).convex_hull
8
  return list(hull.exterior.coords)
9
 
10
- def draw_translated_text_convex(img, polygon_coords, text, font_path="arial.ttf"):
11
  draw = ImageDraw.Draw(img)
12
 
13
  # Fill the convex hull white to erase original text
@@ -22,8 +24,7 @@ def draw_translated_text_convex(img, polygon_coords, text, font_path="arial.ttf"
22
  box_height = y_max - y_min
23
 
24
  # Fit font size dynamically
25
- font_size = 14
26
- font = ImageFont.truetype(font_path, font_size)
27
  while True:
28
  w, h = draw.multiline_textsize(text, font=font)
29
  if w < box_width * 0.9 and h < box_height * 0.9:
 
1
 
2
  from shapely.geometry import Polygon, MultiPoint
3
+ import os
4
 
5
+ FONT_PATH = os.path.join(os.path.dirname(__file__), "..", "NotoSansSC-Regular.ttf")
6
 
7
  def merge_polygons_to_convex_hull(polygons):
8
  points = [pt for poly in polygons for pt in poly]
9
  hull = MultiPoint(points).convex_hull
10
  return list(hull.exterior.coords)
11
 
12
+ def draw_translated_text_convex(img, polygon_coords, text, font_path=FONT_PATH, font_size=14):
13
  draw = ImageDraw.Draw(img)
14
 
15
  # Fill the convex hull white to erase original text
 
24
  box_height = y_max - y_min
25
 
26
  # Fit font size dynamically
27
+ font = ImageFont.truetype(font_path, size=font_size)
 
28
  while True:
29
  w, h = draw.multiline_textsize(text, font=font)
30
  if w < box_width * 0.9 and h < box_height * 0.9: