Skip to content

Commit 7465a5f

Browse files
committed
7.57 auto-commit
1 parent 71eb1ee commit 7465a5f

File tree

7 files changed

+94
-2
lines changed

7 files changed

+94
-2
lines changed

CHANGELOG.txt

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
7.57
2+
* 新增特征及模板找图客户端接口
3+
* 其他一些优化及问题修复
4+
15
7.55
26
* 修复屏幕旋转显示不正常的问题
37
* 修复远程桌面初次连接断开的问题

lamda/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
#
33
# Distributed under MIT license.
44
# See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
5-
__version__ = "7.55"
5+
__version__ = "7.57"

lamda/client.py

+20
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,8 @@ def corner(b, position):
242242
Bound.width = property(width)
243243
Bound.height = property(height)
244244

245+
FindImageMethod = protos.FindImageMethod
246+
245247
Bound.center = center
246248
Bound.corner = corner
247249

@@ -853,6 +855,19 @@ def get_clipboard(self):
853855
"""
854856
r = self.stub.getClipboard(protos.Empty())
855857
return r.value
858+
def find_similar_image(self, data, threshold=0,
859+
max_distance=0, bound=None,
860+
method=FindImageMethod.FI_TEMPLATE):
861+
"""
862+
根据提供的目标图片从屏幕中获取相似图片位置
863+
"""
864+
req = protos.FindImageRequest(bound=bound)
865+
req.method = method
866+
req.max_distance = max_distance
867+
req.threshold = threshold
868+
req.partial = data
869+
r = self.stub.findSimilarImage(req)
870+
return r.bounds
856871
def freeze_rotation(self, freeze=True):
857872
"""
858873
锁定屏幕旋转
@@ -2022,6 +2037,11 @@ def wait_for_idle(self, timeout):
20222037
return self.stub("UiAutomator").wait_for_idle(timeout)
20232038
def get_last_toast(self):
20242039
return self.stub("UiAutomator").get_last_toast()
2040+
def find_similar_image(self, data, threshold=0,
2041+
max_distance=0, bound=None,
2042+
method=FindImageMethod.FI_TEMPLATE):
2043+
return self.stub("UiAutomator").find_similar_image(data, threshold=threshold,
2044+
max_distance=max_distance, bound=bound, method=method)
20252045
# watcher
20262046
def remove_all_watchers(self):
20272047
return self.stub("UiAutomator").remove_all_watchers()

lamda/rpc/services.proto

+1
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ service UiAutomator {
186186
rpc registerClickUiObjectWatcher(WatcherRegistRequest) returns (Boolean) {}
187187
rpc registerPressKeysWatcher(WatcherRegistRequest) returns (Boolean) {}
188188
rpc registerNoneOpWatcher(WatcherRegistRequest) returns (Boolean) {}
189+
rpc findSimilarImage(FindImageRequest) returns (FindImageResponse) {}
189190
}
190191

191192
service Wifi {

lamda/rpc/uiautomator.proto

+17
Original file line numberDiff line numberDiff line change
@@ -554,3 +554,20 @@ message WatcherRegistRequest {
554554
Key key = 4;
555555
}
556556
}
557+
558+
enum FindImageMethod {
559+
FI_TEMPLATE = 0;
560+
FI_FEATURE_POINT = 1;
561+
}
562+
563+
message FindImageRequest {
564+
FindImageMethod method = 1;
565+
Bound bound = 2;
566+
bytes partial = 3;
567+
uint32 max_distance = 4;
568+
float threshold = 5;
569+
}
570+
571+
message FindImageResponse {
572+
repeated Bound bounds = 1;
573+
}

tools/debugimage.py

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#!/usr/bin/env python3
2+
import os
3+
import argparse
4+
5+
from PIL import Image, ImageDraw
6+
from lamda.client import *
7+
8+
9+
cert = os.environ.get("CERTIFICATE", None)
10+
port = int(os.environ.get("PORT", 65000))
11+
12+
parser = argparse.ArgumentParser()
13+
parser.add_argument("-d", type=str, dest="device",
14+
help="service ip address", required=True)
15+
parser.add_argument("-p", type=str, dest="port",
16+
default=port,
17+
help="service port")
18+
parser.add_argument("-f", "--method", type=int,
19+
dest="method",
20+
help="find method", default=0)
21+
parser.add_argument("-i", "--image", type=argparse.FileType("rb"),
22+
dest="image",
23+
help="find image path", required=True)
24+
parser.add_argument("-t", "--threshold", type=float,
25+
dest="threshold",
26+
help="threshold", default=0)
27+
parser.add_argument("-m", "--max-distance", type=int,
28+
dest="distance",
29+
help="max distance", default=0)
30+
parser.add_argument("-cert", type=str, default=cert,
31+
help="ssl cert")
32+
args = parser.parse_args()
33+
34+
35+
d = Device(args.device, port=args.port,
36+
certificate=args.cert)
37+
image = Image.open(d.screenshot(60))
38+
39+
draw = ImageDraw.Draw(image)
40+
for r in d.find_similar_image(args.image.read(),
41+
method=args.method,
42+
max_distance=args.distance,
43+
threshold=args.threshold):
44+
p1 = r.corner("top-left")
45+
p2 = r.corner("bottom-right")
46+
draw.rectangle(((p1.x, p1.y), (p2.x, p2.y)),
47+
outline="red", width=3)
48+
image.show()
49+
exit (0)

tools/requirements.txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
mitmproxy>=9.0.0,<=10.2.0
22
dnspython
33
httpx[socks]
4-
packaging
4+
packaging
5+
Pillow

0 commit comments

Comments
 (0)