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)}')    
相关推荐
KobeSacre8 小时前
DelayQueue 源码
java·开发语言
han_hanker8 小时前
重新认识枚举enum
开发语言
鹏易灵9 小时前
C++——8.移动语义初探(移动构造、移动赋值)
开发语言·c++·php
2601_962341309 小时前
计算机毕业设计之jsp考研在线复习平台
java·大数据·开发语言·hadoop·python·考研·课程设计
凯瑟琳.奥古斯特9 小时前
力扣1008:前序重建BST
开发语言·c++·算法·leetcode·职场和发展
2zcode10 小时前
项目文档:基于MATLAB图像处理的饮料瓶灌装液位检测系统设计与实现
开发语言·图像处理·matlab
云烟成雨TD10 小时前
LangFlow 1.x 系列【7】工作流创建与部署指南
人工智能·python·agent
月疯10 小时前
np.where()[0]的用法
开发语言·python·numpy
z落落10 小时前
C#五大加密算法(AES、DES、MD5、RSA、SHA)
开发语言·c#
namexingyun10 小时前
Scaling Law bug实战启示:从“虚胖“到“精瘦“的算力效率革命
开发语言·网络·人工智能·bug·ai编程