赞
踩
dm.click(r'C:\Users\999\Desktop\123.bmp')#找图点击
dm.doubleClick('1.jpg')#找图双击
dm.locateOnScreen('1.bmp', region=(0,0,0,0))#区域找图
img = dm.locateOnScreen('img.png')#全屏找图
dm.click('button.png')#找图点击1
x, y = dm.locateCenterOnScreen('1.bmp')#找图点击2
dm.click(x, y)
#!/usr/bin/python # -*- coding: utf-8 -*- # @Version : 3.8 # @Author : QQ736592720 # @Datetime : 2023/1/12 16:33 # @Project : smf # @File : my_pic.py import cv2 from ctypes import * # 获取屏幕上某个坐标的颜色 from PIL import ImageGrab import numpy as np from rgb_hex import * import os.path import aircv, cv2 def GetPixelColor(x, y): ''' 获取指定点的颜色 十六进制FFFFFF str :param x: 指定点的横向坐标 int :param y: 指定点的纵向坐标 int :return: 十六进制FFFFFF str ''' gdi32 = windll.gdi32 user32 = windll.user32 hdc = user32.GetDC(None) # 获取颜色值 pixel = gdi32.GetPixel(hdc, x, y) # 提取RGB值 r = pixel & 0x0000ff g = (pixel & 0x00ff00) >> 8 b = pixel >> 16 return rgb2hex((r, g, b)).upper() def pil2np(pil_img): ''' PIL.Image.Image===>numpy.ndarray :param pil_img: pil模块的图片数据 PIL.Image.Image :return: numpy 支持的narray 数据结构 numpy.ndarray ''' print(type(pil_img)) # PIL.Image.Image return np.array(pil_img) # numpy.ndarray def FindColor(x0, y0, x1, y1, color_hex): ''' 0,0,1024,768,"0000FF" :param x0: 找色区域左上角x坐标 int :param y0: 找色区域左上角y坐标 int :param x1: 找色区域右下角x坐标 int :param y1: 找色区域右下角y坐标 int :param color_hex:"0000FF" :return: (0,100) |(-1,-1) ''' color = hex2rgb(color_hex) img = pil2np(ImageGrab.grab((x0, y0, x1, y1))) for i in range(img.shape[0]): for j in range(img.shape[1]): if img[i, j, 0] == color[0] and img[i, j, 1] == color[1] and img[i, j, 2] == color[2]: return i, j print("没找到point") return -1, -1 # 0,0,1024,768,"Attachment:\神盾.bmp",0.9 def FindPic(x0, y0, x1, y1, small_picture_path, similarity=0.95): ''' 区域找图 :param x0: 找色区域左上角x坐标 int :param y0: 找色区域左上角y坐标 int :param x1: 找色区域右下角x坐标 int :param y1: 找色区域右下角y坐标 int :param small_picture_path:目标小图的路径 :param similarity:相似度,0.95 :return: (0,100) |(-1,-1) ''' if not os.path.exists(small_picture_path): return None bag = ImageGrab.grab((x0, y0, x1, y1)) small = cv2.imread(small_picture_path) res = aircv.find_template(pil2np(bag), small, similarity) # {'result': (430.0, 30.5), 'rectangle': ((420, 19), (420, 42), (440, 19), (440, 42)), 'confidence': 1.0} return res["result"] if res else (-1, -1) if __name__ == '__main__': from my_mouse import * r = ImageGrab.grab((0, 0, 582, 175)) r = pil2np(r) print(type(r)) # r = FindPic(0, 0, 1000, 1000, r"C:\Users\Administrator.USER-20200912KS\Desktop\small.bmp") # print(r) # LeftClick(*r)
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。