pytesseract文字识别

import pytesseract
from PIL import Image

im=Image.open('image.png')
print(pytesseract.image_to_string(im))

安装注意:
  环境变量需要配置两处
  1、path
  2、TESSDATA_PREFIX

初始路径
pytesseract.pytesseract.tesseract_cmd = 'd://Tesseract-OCR//tesseract.exe'
tessdata_dir_config = '--tessdata-dir "d://Tesseract-OCR//tessdata"'

图像切割识别
im = Image.open(old_file)
R,C = im.size
newR = C//7
if right != 0:
    box = (left, low, right, high)
else:
    box = (left,low,R,high)
region = im.crop(box)
s = pytesseract.image_to_string(region,lang='chi_sim')

猜你喜欢

转载自www.cnblogs.com/pythonclass/p/11957012.html
今日推荐