python,提取图片中的文字

# -*- coding:utf-8 -*-
# Time:2023/5/16 16:03
# Author:Xue
# FileName:image.py
import pytesseract
from PIL import Image


def demo():
    # 打开要识别的图片
    image = Image.open(r'D:\python\lianxi\study\jpg\123.png')
    # 使用pytesseract调用image_to_string方法进行识别,传入要识别的图片,lang='chi_sim'是设置为中文识别,
    text = pytesseract.image_to_string(image, lang='chi_sim')
    # 输入所识别的文字
    print(text)
    with open('D:\\python\\lianxi\\study\\result_file\\image.txt', 'w', encoding='utf-8') as file:
        file.write(text)
    file.close()


if __name__ == '__main__':
    demo()

# tesseract test.png 1 -l eng



你可能感兴趣的:(python)