Tesseract ocr act weird while scalling up image size. How to know which scale factor is best for some particular types of image?

混江龙づ霸主 提交于 2020-06-27 18:35:11

问题


I have this 006.jpg image and i tried following python code
I downloaded "eng" from tessdata_best and renamed it to "eng_best"

img = cv2.imread(file_path)
lang = "eng_best"
for img_scale_factor in range (1,8):
    print(file_path, img_scale_factor)
    img = cv2.resize(img,None,fx=img_scale_factor,fy=img_scale_factor)
    hocr_data = pytesseract.image_to_pdf_or_hocr(img, extension="hocr", lang=lang, config="--dpi 1")
    file_name = '{0:03d}_jpg_{1}_x{3}.{2}'.format(6, lang, "hocr", img_scale_factor)
    with open(os.path.join(savediv, file_name), 'w+b') as f:
        f.write(hocr_data)
    print("    Output - {}".format(file_name))

I tried above code with varying img_scale_factor from 1 upto to 7 which scale given image by that scale factor
Here are output files :
006_jpg_eng_best_x1.html
006_jpg_eng_best_x2.html
006_jpg_eng_best_x3.html
006_jpg_eng_best_x4.html
006_jpg_eng_best_x5.html
006_jpg_eng_best_x6.html
006_jpg_eng_best_x7.html

We can clearly observe that Output

  1. From img_scale_factor 1 to 2 - Increases ocr result.

  2. For img_scale_factor 3 - best ocr result among all.

  3. From img_scale_factor 4 to 7 - Decreases ocr result.

For that particular image img_scale_factor 3 gives best results.

How can we figure out which scale factor is best without checking ocr for every scale factor for some particular types of image ?

May be this can be solved by fixing minimun and maximum font size.
Is there any way to configure minimun and maximum font size ?

来源:https://stackoverflow.com/questions/62480172/tesseract-ocr-act-weird-while-scalling-up-image-size-how-to-know-which-scale-fa

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!