python 识别图片文字

当pip升级时报错

python -m pip uninstall pip setuptools

pip3 install --upgrade pip

c:\users\25671\appdata\local\programs\python\python38\python.exe -m pip install --upgrade pip

需要PIL 与 pytesseract库
识别中文的话需要Tesseract-OCR软件

import pytesseract
from PIL import Image
pytesseract.pytesseract.tesseract_cmd = 'E:/Program Files/Tesseract-OCR/tesseract'

image= Image.open('捕获56.PNG')
text = 9
text = pytesseract.image_to_string(image,lang='chi_sim')
list=[]
print(type(text))
for i in text.strip():
list.append(i)

print(list)
for i in list:
if i == '\n':
continue
else:
print(i,end='')

截图

import pyautogui

pyautogui.screenshot(region=(0,0, 300, 300),imageFilename='c:/Users/25671/Desktop/myphoto_a22.png')

posted @ 2022-04-03 17:16  supermao12  阅读(127)  评论(0编辑  收藏  举报