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)}')    
相关推荐
第二只羽毛7 分钟前
重载和继承的实践
java·开发语言
AndrewHZ11 分钟前
【图像处理基石】GIS图像处理入门:4个核心算法与Python实现(附完整代码)
图像处理·python·算法·计算机视觉·gis·cv·地理信息系统
光军oi42 分钟前
全栈开发杂谈————JAVA微服务全套技术栈详解
java·开发语言·微服务
帮帮志43 分钟前
目录【系列文章目录】-(关于帮帮志,关于作者)
java·开发语言·python·链表·交互
qiuiuiu4131 小时前
正点原子RK3568学习日记-GIT
linux·c语言·开发语言·单片机
草莓熊Lotso1 小时前
《C++ STL list 完全指南:从基础操作到特性对比,解锁链表容器高效用法》
开发语言·c++·list
二王一个今2 小时前
Python打包成exe(windows)或者app(mac)
开发语言·python·macos
一勺菠萝丶2 小时前
Mac 上用 Homebrew 安装 JDK 8(适配 zsh 终端)完整教程
java·python·macos
C嘎嘎嵌入式开发7 小时前
(2)100天python从入门到拿捏
开发语言·python
Stanford_11067 小时前
如何利用Python进行数据分析与可视化的具体操作指南
开发语言·c++·python·微信小程序·微信公众平台·twitter·微信开放平台