# 导入所需的库
import pytesseract
from PIL import Image
# 设置 Tesseract OCR 的路径(如果不在系统路径中)
# pytesseract.pytesseract.tesseract_cmd = r'C:\Program Files\Tesseract-OCR\tesseract.exe'
# 打开图像文件
image = Image.open('example.png')
# 使用 Tesseract 进行 OCR 识别
text = pytesseract.image_to_string(image)
# 输出识别结果
print(text)
pytesseract
和 PIL.Image
。pytesseract
是 Python 的 Tesseract OCR 包装器,而 PIL.Image
用于处理图像。Image.open()
方法打开一个图像文件(例如 example.png
)。pytesseract.image_to_string()
方法对图像进行 OCR 识别,并将结果存储在变量 text
中。print()
输出识别到的文本。如果你需要更复杂的功能或处理不同类型的图像,可以参考 pytesseract
的官方文档。
上一篇:编写一个简单的python程序
下一篇:split python
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站