这是一个简单的Python OCR代码示例,使用Tesseract作为OCR引擎:

import pytesseract
from PIL import Image

# 安装Tesseract OCR引擎并设置路径
pytesseract.pytesseract.tesseract_cmd = 'C:/Program Files/Tesseract-OCR/tesseract.exe'

# 打开图像文件并进行OCR
img = Image.open('sample_image.png')
text = pytesseract.image_to_string(img, lang='eng')

# 输出OCR结果
print(text)

请注意,您需要首先安装Tesseract OCR引擎并设置正确的路径,才能成功运行此代码。此外,您可能需要安装其他依赖项,如Pillow和pytesseract模块。


原文地址: https://www.cveoy.top/t/topic/mwS9 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录