实例如下所示:importosos.chdir("G:\Python1\Lib\site-packages\pytesser")frompytesserimport*frompytesseractimportim
实例如下所示:
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)
以上这篇python自动截取需要区域,进行图像识别的方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持脚本之家。
python 图像识别