htrnguyen commited on
Commit
351856a
·
1 Parent(s): 964ccb3

Fix Vietnamese font path to font/ARIAL.TTF

Browse files
Files changed (3) hide show
  1. .gitattributes +1 -0
  2. font/ARIAL.TTF +3 -0
  3. reengineer.py +12 -12
.gitattributes CHANGED
@@ -1 +1,2 @@
1
  models/*.pth.tar filter=lfs diff=lfs merge=lfs -text
 
 
1
  models/*.pth.tar filter=lfs diff=lfs merge=lfs -text
2
+ *.TTF filter=lfs diff=lfs merge=lfs -text
font/ARIAL.TTF ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:74d696e666f696e93db685a85c94bfbfcc0796dfcf8a2e2e2e2c908a54e82949
3
+ size 1047208
reengineer.py CHANGED
@@ -32,24 +32,24 @@ def draw_vietnamese_text(img_cv, text, position, font_size=24, color=(255, 255,
32
  img_pil = Image.fromarray(cv2.cvtColor(img_cv, cv2.COLOR_BGR2RGB))
33
  draw = ImageDraw.Draw(img_pil)
34
 
 
 
 
 
35
  try:
36
- # Sử dụng font Arial mặc định (Tìm trong thư mục dự án hoặc hệ thống)
37
- base_dir = os.path.dirname(os.path.abspath(__file__))
38
- font_path = os.path.join(base_dir, 'font', 'arial.ttf')
39
- if not os.path.exists(font_path):
40
- font_path = "C:\\Windows\\Fonts\\arial.ttf"
41
-
42
  font = ImageFont.truetype(font_path, font_size)
43
  except:
44
  font = ImageFont.load_default()
45
 
46
  if max_width:
47
- avg_char_width = font_size * 0.5
48
- chars_per_line = int(max_width / avg_char_width)
49
- wrapped_lines = textwrap.wrap(text, width=chars_per_line)
50
- text = "\n".join(wrapped_lines)
51
-
52
- draw.text(position, text, font=font, fill=color, spacing=6)
 
 
53
  return cv2.cvtColor(np.array(img_pil), cv2.COLOR_RGB2BGR)
54
 
55
  def draw_glass_panel(img, pt1, pt2, color=(0, 0, 0), alpha=0.5):
 
32
  img_pil = Image.fromarray(cv2.cvtColor(img_cv, cv2.COLOR_BGR2RGB))
33
  draw = ImageDraw.Draw(img_pil)
34
 
35
+ # Hardcode font path
36
+ script_dir = os.path.dirname(os.path.abspath(__file__))
37
+ font_path = os.path.join(script_dir, "font", "ARIAL.TTF")
38
+
39
  try:
 
 
 
 
 
 
40
  font = ImageFont.truetype(font_path, font_size)
41
  except:
42
  font = ImageFont.load_default()
43
 
44
  if max_width:
45
+ lines = textwrap.wrap(text, width=max_width)
46
+ y = position[1]
47
+ for line in lines:
48
+ draw.text((position[0], y), line, font=font, fill=color)
49
+ y += font_size + 5
50
+ else:
51
+ draw.text(position, text, font=font, fill=color)
52
+
53
  return cv2.cvtColor(np.array(img_pil), cv2.COLOR_RGB2BGR)
54
 
55
  def draw_glass_panel(img, pt1, pt2, color=(0, 0, 0), alpha=0.5):