2525
2626
2727class VisRes :
28- def __init__ (self , text_score : float = 0.5 ):
28+ def __init__ (
29+ self ,
30+ text_score : float = 0.5 ,
31+ lang_type : Optional [LangRec ] = None ,
32+ font_path : Optional [str ] = None ,
33+ ):
2934 self .logger = Logger (logger_name = __name__ ).get_log ()
3035
3136 self .text_score = text_score
3237 self .load_img = LoadImage ()
3338
3439 self .font_cfg = OmegaConf .load (FONT_YAML_PATH ).fonts
3540
41+ self .font_path = self .get_font_path (font_path , lang_type )
42+ self .logger .info (f"Using { self .font_path } to visualize results." )
43+
3644 def __call__ (
3745 self ,
3846 img_content : InputType ,
3947 dt_boxes : np .ndarray ,
4048 txts : Optional [Union [List [str ], Tuple [str ]]] = None ,
4149 scores : Optional [Tuple [float ]] = None ,
42- font_path : Optional [str ] = None ,
43- lang_type : Optional [LangRec ] = None ,
4450 ) -> np .ndarray :
4551 if txts is None :
4652 return self .draw_dt_boxes (img_content , dt_boxes , scores )
47-
48- font_path = self .get_font_path (font_path , lang_type )
49- return self .draw_ocr_box_txt (img_content , dt_boxes , txts , font_path , scores )
53+ return self .draw_ocr_box_txt (img_content , dt_boxes , txts , scores )
5054
5155 def draw_dt_boxes (
5256 self ,
@@ -180,7 +184,6 @@ def draw_ocr_box_txt(
180184 img_content : InputType ,
181185 dt_boxes : np .ndarray ,
182186 txts : Union [List [str ], Tuple [str ]],
183- font_path : str ,
184187 scores : Optional [Tuple [float ]] = None ,
185188 ) -> np .ndarray :
186189 image = Image .fromarray (self .load_img (img_content ))
@@ -208,7 +211,7 @@ def draw_ocr_box_txt(
208211 box_width = self .get_box_width (box )
209212 if box_height > 2 * box_width :
210213 font_size = max (int (box_width * 0.9 ), 10 )
211- font = ImageFont .truetype (font_path , font_size , encoding = "utf-8" )
214+ font = ImageFont .truetype (self . font_path , font_size , encoding = "utf-8" )
212215 cur_y = box [0 ][1 ]
213216
214217 for c in txt :
@@ -218,7 +221,7 @@ def draw_ocr_box_txt(
218221 cur_y += self .get_char_size (font , c )
219222 else :
220223 font_size = max (int (box_height * 0.8 ), 10 )
221- font = ImageFont .truetype (font_path , font_size , encoding = "utf-8" )
224+ font = ImageFont .truetype (self . font_path , font_size , encoding = "utf-8" )
222225 draw_right .text ([box [0 ][0 ], box [0 ][1 ]], txt , fill = (0 , 0 , 0 ), font = font )
223226
224227 img_left = Image .blend (image , img_left , 0.5 )
0 commit comments