https://blog.csdn.net/woshiabc111/article/details/134739325
https://blog.51cto.com/u_16175478/8749221
下载安装tesseract,地址:https://digi.bib.uni-mannheim.de/tesseract/
无脑点下一步但是语言这里记得把中文这几个勾选上
2.然后就是配置tesseract系统环境变量,只要配置到tesseract.exe所在的文件夹那一级就行
配置到tesseract.exe所在的文件夹那一级就行
3.在命令行输入tesseract --help查看是否会返回一些提示信息看到如下信息说明安装成功。
from PIL import Image
import pytesseract
import time
import pyautogui
import pytesseract
from PIL import ImageGrab
# tesseract命令位置
tesseract_cmd = r'F:\Tesseract-OCR\tesseract'
pytesseract.pytesseract.tesseract_cmd =tesseract_cmd
# 显示
image=Image.open('text6.png')
print(pytesseract.image_to_string(image,lang='chi_sim'))
import pytesseract
from PIL import Image
image = Image.open('text6.png')
text = pytesseract.image_to_string(image,lang='chi_sim')
result = pytesseract.image_to_boxes(image,lang='chi_sim')
for line in result.splitlines():
character, x1, y1, x2, y2, _ = line.split(' ')
print(f"Character: {character}, X1: {x1}, Y1: {y1}, X2: {x2}, Y2: {y2}")
#while True:
# # 获取鼠标当前坐标
# x, y = pyautogui.position()
# # 打印坐标
# print(f"当前坐标:({x}, {y})")
# # 暂停1秒
# time.sleep(1)
# 设置Tesseract-OCR的路径
pytesseract.pytesseract.tesseract_cmd = r'F:\Tesseract-OCR\tesseract.exe' # 根据实际路径修改
# 获取屏幕截图
screenshot = ImageGrab.grab()
# 指定想要识别文本的坐标和尺寸
x, y = 151, 316 # 文本区域左上角坐标
width, height = 600, 600 # 文本区域的宽度和高度
# 从截图中获取指定区域的图像
text_region = screenshot.crop((x, y, x+width, y+height))
# 使用Tesseract进行文本识别
text = pytesseract.image_to_string(text_region,lang='chi_sim')
print(text)