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)}')    
相关推荐
小狗丹尼40040 分钟前
JSON 基础认知、数据转换与 Flask 前后端交互全解
python·flask·json
1104.北光c°1 小时前
滑动窗口HotKey探测机制:让你的缓存TTL更智能
java·开发语言·笔记·程序人生·算法·滑动窗口·hotkey
for_ever_love__2 小时前
Objective-C学习 NSSet 和 NSMutableSet 功能详解
开发语言·学习·ios·objective-c
zm-v-159304339863 小时前
Python 数据挖掘从入门到精通:回归 / 分类 / 聚类 / 关联分析完整教程
python·数据挖掘·回归
似水明俊德8 小时前
02-C#.Net-反射-面试题
开发语言·面试·职场和发展·c#·.net
qq_417695058 小时前
机器学习与人工智能
jvm·数据库·python
漫随流水8 小时前
旅游推荐系统(view.py)
前端·数据库·python·旅游
Thera7779 小时前
C++ 高性能时间轮定时器:从单例设计到 Linux timerfd 深度优化
linux·开发语言·c++
yy我不解释9 小时前
关于comfyui的mmaudio音频生成插件时时间不一致问题(一)
python·ai作画·音视频·comfyui
炘爚9 小时前
C语言(文件操作)
c语言·开发语言