实例如下所示:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
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自动截取需要区域,进行图像识别的方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持服务器之家。
原文链接:https://blog.csdn.net/tonghua1116/article/details/54670155