facebookresearch / MultiplexedOCR

Code for CVPR21 paper A Multiplexed Network for End-to-End, Multilingual OCR
Other
79 stars 10 forks source link

UnicodeEncodeError: 'latin-1' codec can't encode characters in position 0-3: ordinal not in range(256) #15

Closed leezx337 closed 1 year ago

leezx337 commented 1 year ago

Hello all, I encountered this error while trying to run predict_on_image(img_dir) using the code for the demo file despite having imported to repo to the MultiplexedOCR module and changed the directory of my yaml file to charmap/public/v3:

---------------------------------------------------------------------------
UnicodeEncodeError                        Traceback (most recent call last)
Cell In[13], line 1
----> 1 predict_on_image(img_dir)

Cell In[11], line 43, in predict_on_image(image_path)
     40 result_logs = result_logs_dict["result_logs"]
     42 img_vis = img.copy()
---> 43 render_box_multi_text(
     44     cfg=cfg,
     45     image=img_vis,
     46     result_logs_dict=result_logs_dict,
     47     resize_ratio=resize_ratio,
     48 )
     50 return img_vis

File ~/MultiplexedOCR/multiplexer/engine/text_inference.py:1162, in render_box_multi_text(cfg, image, result_logs_dict, resize_ratio, det_thresh)
   1159 word += "]"
   1161 draw_loc = (min_x, min_y - font_size)
-> 1162 text_size = draw.textsize(word, font=font)
   1163 rec_pad = 0
   1164 rec_min = (draw_loc[0] - rec_pad, draw_loc[1] - rec_pad)

File ~/.conda/envs/multiplexer/lib/python3.8/site-packages/PIL/ImageDraw.py:677, in ImageDraw.textsize(self, text, font, spacing, direction, features, language, stroke_width)
    675 with warnings.catch_warnings():
    676     warnings.filterwarnings("ignore", category=DeprecationWarning)
--> 677     return font.getsize(
    678         text,
    679         direction,
    680         features,
    681         language,
    682         stroke_width,
    683     )

File ~/.conda/envs/multiplexer/lib/python3.8/site-packages/PIL/ImageFont.py:152, in ImageFont.getsize(self, text, *args, **kwargs)
    138 """
    139 .. deprecated:: 9.2.0
    140 
   (...)
    149 :return: (width, height)
    150 """
    151 deprecate("getsize", 10, "getbbox or getlength")
--> 152 return self.font.getsize(text)

UnicodeEncodeError: 'latin-1' codec can't encode characters in position 0-3: ordinal not in range(256)

Is anyone able to assist me in this? @SuperIRabbit ? Thank you in advance!!