我的知识记录

Python 图片文字识别 OCR:批量提取图片里的文字

import os
import pytesseract
from PIL import Image

# Windows 需指定 tesseract 路径
pytesseract.pytesseract.tesseract_cmd = r'C:\Program Files\Tesseract-OCR\tesseract.exe'

def ocr_folder(folder):
    for name in os.listdir(folder):
        if not name.lower().endswith(('.png', '.jpg', '.jpeg')):
            continue
        path = os.path.join(folder, name)
        text = pytesseract.image_to_string(Image.open(path), lang='chi_sim+eng')
        print(f"--- {name} ---\n{text}\n")

ocr_folder('./截图')

Python 图片文字识别 OCR:批量提取图片里的文字

标签:

更新时间:2026-09-14 13:36:59

上一篇:Python 给 PDF 加水印:批量加文字水印

下一篇:Python 文字转语音:把文字变成 MP3 音频