运行环境:雷电模拟器9

使用语言:python

坐标识别

 由于坐标文本太小,所以文字识别的效果并不好。因此将坐标截图进行变成黑白图片,然后将图片变成二位数组,并进行切割。将文字识别改成数组比较。

使用adb进行截图并将图片pull到电脑上

1
2
3
4
5
6
7
8
9
10
import subprocess
def screenShot(filename):
"""
截取雷电模拟器屏幕并保存在E盘adb文件夹中
"""
# 截图在模拟器/sdcard/下
subprocess.run("cmd /c adb -s emulator-5554 shell screencap -p /sdcard/{0}".format(filename))
# 将图片复制到e盘adb文件夹下
subprocess.run("cmd /c adb -s emulator-5554 pull /sdcard/{0} E://adb".format(filename))
pass

将图片进行灰度图二值化

1
2
3
4
5
6
7
8
9
10
11
12
13
import cv2
def binaryImage(imagePath, threshold=150):
"""
将截图二值化
"""
# 读取图片
im = cv2.imread(imagePath)
# 将图像转为灰度图
imGray = cv2.cvtColor(im, cv2.COLOR_BGR2GRAY)
# 灰度图二值化
ret,binary = cv2.threshold(img_gray,127,255,cv2.THRESH_BINARY)
# 返回二值化图像
cv2.imwrite("E:\\adb\\screen01.png",binary)

对数组进行处理,删除没有255的行列

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
29
obj = cv2.imread("e:/adb/binary_image.png")
obj = cv2.cvtColor(obj, cv2.COLOR_BGR2GRAY)
nuary = numpy.array(obj)

# 将横向不含255的排除
print(nuary.shape)
new_array = []
for i in range(nuary.shape[0]):
if 255 in nuary[i]:
new_array.append(nuary[i])
nuary = numpy.array(new_array)

# 纵向分割图片
img_list = [[[] for _ in range(26)] for _ in range(7)]
xuhao = -1
l = 0
for i in range(nuary.shape[1]):
if 255 in nuary[:,i]:
if i-l==1:
xuhao = xuhao+1
for n in range(26):
print(xuhao)
print(n)
img_list[xuhao][n].append(nuary[n,i])
pass
else:
l = i
# 清除空数组
img_list.remove([])

以上属于东拼西凑起来的,要用还得捋一捋