当前位置: 首页 > news >正文

pywinauto通过图片定位怎么更加精准的识别图片?

pywinauto通过图片定位怎么更加精准的识别图片?

可以使用置信度的配置,添加了对比图片相似程度达到多少就可以认为是合适的定位图片

import time
from time import sleep
from pywinauto.application import Application
from pywinauto.keyboard import send_keys
from pywinauto import mouse
import pyautogui#判断是否存在
def search_is_exist_image(image_address):try:button_location = pyautogui.locateOnScreen(image_address, confidence=0.8)return button_location is not Noneexcept Exception as e:logger.error(f'Error: {str(e)}')return False#间隔interval秒查询下元素image_address是否存在,超过time秒则停止
def search_is_exist_with_timeout(image_address, timeout, interval):start_time = time.time()while True:if search_is_exist_image(image_address):return Trueif time.time() - start_time > timeout:return Falsetime.sleep(interval)#间隔interval秒查询下多个元素image_address是否存在,超过time秒则停止
def search_is_exist_images_with_timeout(image_address_list, timeout, interval):start_time = time.time()while True:for index,image_address in enumerate(image_address_list):if search_is_exist_image(image_address):return indexif time.time() - start_time > timeout:return Nonetime.sleep(interval)#查找到元素并点击
def search_click(image_address):try:button_location = pyautogui.locateOnScreen(image_address, confidence=0.8)if button_location is not None:button_center = pyautogui.center(button_location)pyautogui.click(button_center) except Exception as e:logger.error(f'Error: {str(e)}')#查找到元素并移动上去
def search_move(image_address):try:button_location = pyautogui.locateOnScreen(image_address, confidence=0.8)if button_location is not None:button_center = pyautogui.center(button_location)pyautogui.moveTo(button_center, duration=0.5) except Exception as e:logger.error(f'Error: {str(e)}')    

相关文章:

  • 关于tftpboot的用法
  • 计算机中的逻辑运算
  • 关于串口读写NAND闪存的用法
  • 多线程系列五:面试中常考的单例模式
  • SQL 与 Python:日期维度表创建的不同选择
  • LINUX——例行性工作
  • LeetCode 220 存在重复元素 III 题解
  • 高铁座位指示灯系统技术深度解析:从物联网到智慧出行的实践路径
  • [论文阅读]Deep Cross Network for Ad Click Predictions
  • 机器学习例题——预测facebook签到位置(K近邻算法)和葡萄酒质量预测(线性回归)
  • 多模态训练与微调
  • TypeScript简介
  • MPay码支付系统第四方聚合收款码多款支付插件个人免签支付源码TP8框架全开源
  • MD2card + Deepseek 王炸组合 一键制作小红书知识卡片
  • Qwen3与Deepseek R1对比(截止20250506)
  • CentOS 7 安装指定版本 Docker 及镜像加速/配置优化攻略
  • 计算机视觉与深度学习 | 基于数字图像处理的裂缝检测与识别系统(matlab代码)
  • SiC 材料及器件在高频大功率领域的应用现状
  • MCP服务发展现状的有趣发现
  • 【每天一个知识点】使用 apriori() 函数获取频繁项集
  • 潘功胜发布会答问五大要点:除了降准降息,这些政策“含金量”也很高
  • 央行行长:债券市场“科技板”准备工作基本就绪,目前近百家市场机构计划发行超三千亿科技创新债
  • 央行行长:未来还可以扩大结构性货币政策工具规模或创设新的政策工具
  • 正荣地产:公司控股股东已获委任联合清盘人
  • 上海虹桥机场至北京首都机场快线试运行跨航司自愿签转服务
  • 茹诗瑶评《失去伊斯坦布尔》︱“帝国主义者”的多重面相