合并代码
This commit is contained in:
@@ -246,7 +246,7 @@ def longPressAction():
|
||||
def growAccount():
|
||||
body = request.get_json()
|
||||
udid = body.get("udid")
|
||||
# Variables.commentList = body.get("comment")
|
||||
Variables.commentList = body.get("comment")
|
||||
|
||||
manager = ScriptManager()
|
||||
event = threading.Event()
|
||||
@@ -292,7 +292,7 @@ def passAnchorData():
|
||||
|
||||
# 主播列表
|
||||
acList = data.get("anchorList", [])
|
||||
# Variables.commentList = data.get("comment")
|
||||
Variables.commentList = data.get("comment")
|
||||
|
||||
|
||||
LogManager.info(f"[INFO] 获取数据: {idList} {acList}")
|
||||
@@ -662,17 +662,61 @@ def changeAccount():
|
||||
|
||||
@app.route('/test', methods=['POST'])
|
||||
def test():
|
||||
body = request.get_json()
|
||||
import wda
|
||||
import cv2
|
||||
import numpy as np
|
||||
|
||||
manager = ScriptManager()
|
||||
threading.Event()
|
||||
# 设备的UDID
|
||||
udid = "00008110-000120603C13801E"
|
||||
|
||||
# 启动脚本
|
||||
manager.test()
|
||||
# thread = threading.Thread(target=, args=(udid,))
|
||||
# # 添加到线程管理
|
||||
# thread.start()
|
||||
return ResultData(data="", code=200, message="成功").toJson()
|
||||
# 连接到设备
|
||||
client = wda.USBClient(udid)
|
||||
session = client.session()
|
||||
|
||||
# 设置Appium的截图深度
|
||||
session.appium_settings({"snapshotMaxDepth": 15})
|
||||
|
||||
# 获取当前屏幕截图
|
||||
screenshot = session.screenshot()
|
||||
screenshot = cv2.imdecode(np.frombuffer(screenshot, np.uint8), cv2.IMREAD_COLOR)
|
||||
|
||||
# 读取大图和小图
|
||||
large_image = screenshot # 这里使用截图作为大图
|
||||
template = cv2.imread(r'E:\python\Scrcpy_test\open-cv-tk\insert_comment.png', 0) # 0 表示以灰度模式读取
|
||||
|
||||
# 检查图像是否成功加载
|
||||
if template is None:
|
||||
print("小图加载失败,请检查路径")
|
||||
exit()
|
||||
|
||||
# 获取模板的宽度和高度
|
||||
w, h = template.shape[::-1]
|
||||
|
||||
# 使用模板匹配方法
|
||||
result = cv2.matchTemplate(large_image, template, cv2.TM_CCOEFF_NORMED)
|
||||
|
||||
# 设定阈值
|
||||
threshold = 0.8
|
||||
loc = np.where(result >= threshold)
|
||||
|
||||
# 遍历所有匹配点
|
||||
if loc[0].size > 0: # 检查是否有匹配点
|
||||
for pt in zip(*loc[::-1]): # 将坐标转换为 (x, y) 格式
|
||||
cv2.rectangle(large_image, pt, (pt[0] + w, pt[1] + h), (0, 255, 0), 2)
|
||||
print(f"找到匹配区域,坐标:{pt},尺寸:{(w, h)}")
|
||||
else:
|
||||
print("未找到匹配区域,请检查模板和大图的内容,或调整阈值")
|
||||
|
||||
# 保存结果
|
||||
cv2.imwrite('matched_result.png', large_image)
|
||||
|
||||
# 显示结果
|
||||
cv2.imshow('Matched Result', large_image)
|
||||
cv2.waitKey(0)
|
||||
cv2.destroyAllWindows()
|
||||
|
||||
# 关闭会话
|
||||
session.close()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
Reference in New Issue
Block a user