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)}')    
相关推荐
吴卫斌10 分钟前
波动率控制仓位系列(一):满仓轮动的“过山车”困境
大数据·python·股票·量化交易
如此这般英俊14 分钟前
手搓Claude Code-第三章 permission
人工智能·python·语言模型
TE-茶叶蛋33 分钟前
TF-IDF 与 BM25 深度解析:从理论到项目实战
python·django·tf-idf
赴生-33 分钟前
C++进阶 C++11(下)
开发语言·c++
xcbrand36 分钟前
湖南VI设计公司排名
大数据·人工智能·python
lllsure1 小时前
【开源项目】Learn Claude Code
python·ai
赴生-1 小时前
C++进阶 异常
开发语言·c++
黄毛火烧雪下2 小时前
Java 核心知识点总结(一)
java·开发语言
其实防守也摸鱼2 小时前
软件安全与漏洞--软件安全编码与防御技术理论题库
开发语言·网络·安全·网络安全·软件安全·软件安全与漏洞
x138702859572 小时前
c语言中srtlen(指针使用计算字符长度)、传值和传址调用
c语言·开发语言·算法·visual studio