当前位置:主页 > 软件编程 > Python代码 >

python自动截取需要区域,进行图像识别的方法

时间:2021-05-14 10:36:29 | 栏目:Python代码 | 点击:

实例如下所示:

import os
os.chdir("G:\Python1\Lib\site-packages\pytesser")
from pytesser import *
from pytesseract import image_to_string
from PIL import Image
from PIL import ImageGrab

#截图,获取需要识别的区域
x = 345
y = 281
m = 462
n = 327

k = 54
for i in range(2,6):
 box = (x,y,m,n)
 img = ImageGrab.grab(box)
 img.save("G:\Python1\Lib\site-packages\pytesser\kangkang"+str(i)+".png")
 #img.show()
 y+=54
 n+=54

#截图完毕后,开始图像识别
names=["kangkang2.png","kangkang3.png","kangkang4.png","kangkang5.png"]
for name in names:
 im = Image.open(name)
 text = image_to_string(im)
 print(name+":"+text)

您可能感兴趣的文章:

相关文章