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

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

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

python 复制代码
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 None
    except 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 True
        if time.time() - start_time > timeout:
            return False
        time.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 index
        if time.time() - start_time > timeout:
            return None
        time.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)}')    
相关推荐
AR-26710-7 小时前
机器学习复习Day8——异常检测
人工智能·python·机器学习·scikit-learn
千里码aicood7 小时前
Django 基于Django的电脑推荐与分析可视化系统设计与实现
python·django·电脑
未若君雅裁7 小时前
Agent 的结构化输出,ProviderStrategy、ToolStrategy 与错误重试
python·langchain
洛兮银儿7 小时前
pycharm选中同一个词的标记颜色的修改
ide·python·pycharm
郝学胜_神的一滴8 小时前
Effective Python 条款 6:善用拆包告别恼人的下标索引
python·pycharm
汤姆yu8 小时前
基于Django的学习资料共享与智能推荐系统
后端·python·django·毕业设计·学习资料共享
Freak嵌入式8 小时前
树莓派 Pico GPIO 深度解析:从 MCU 架构到寄存器控制,底层原理与实践指南
java·开发语言·科技·单片机·嵌入式硬件·架构
张人玉8 小时前
基于 Python + PyQt5 的水果目标检测与分割可视化系统——水果深度学习识别可视化大屏
python·深度学习·qt·目标检测·sqlite·echarts
啊啊啊啊啊!!!!8 小时前
【c++】map和set的使用
开发语言·c++
hu9245195598 小时前
Matlab保护源代码—P文件和exe文件详细解析
开发语言·matlab