pip install pytesseract
pip install pytesseract Pillow
pip install opencv-python pyautogui
需要安装上面模块
需要安装这个软件:tesseract-ocr-w64-setup-5.5.0.20241111.exe
C:\Program Files\Tesseract-OCR\tessdata\chi_sim.traineddata
需要设置环境变量:C:\Program Files\Tesseract-OCR\tessdata
需要准备这个文件:tessdata-main.zip
以下是程序代码
import pytesseract
from PIL import Image
def image_to_text(image_path):
try:
text = pytesseract.image_to_string(Image.open(image_path), lang=‘chi_sim’) # 指定简体中文
print(“识别出的字符串内容:”)
print(text)
except Exception as e:
print(“图像识别出错:”, e)
if name == “main”:
image_path = “c.png” # 这里替换为实际的图像路径
image_to_text(image_path)