zoukankan      html  css  js  c++  java
  • python+opencv+pil实现windows 图片位置查找

    PIL系统截图、cv2图片匹配

    from PIL import ImageGrab
    import cv2
    import numpy as np
    
    from utils.windows import mouseMove, mouseClick
    
    
    def mathc_img(Target, value = 0.9):
        try:
            im = np.array(ImageGrab.grab())
            img_gray = cv2.cvtColor(im, cv2.COLOR_BGR2GRAY)
            template = cv2.imread(Target, 0)
            res = cv2.matchTemplate(img_gray, template, cv2.TM_CCOEFF_NORMED)
            threshold = value
            loc = np.where(res >= threshold)
            return (int(loc[1][0]), int(loc[0][0]))
        except :
            raise Exception('未匹配到图片')
    
    
    def imageSearchClick(Target, x_, y_):
        mouseMove(0, 0)
        x, y = mathc_img(Target)
        mouseMove(x + x_, y + y_)
        mouseClick()
        mouseMove(0, 0)
    
    
    
    if __name__ == '__main__':
        # x, y = mathc_img(r'C:UserstcDesktop1.PNG')
        # mouseMove(x, y)
        imageSearchClick(r'C:invoicePrintimages	ool0.PNG', 50, 30)
    
    

    其中的 mouseClick和mouseMove是我自己定义的操作鼠标函数,采用pywin32写的

  • 相关阅读:
    CSPS模拟 49
    StrGame
    CSPS模拟 48
    [没有证明]原根求法
    CSPS模拟 47
    CSPS模拟 46
    CSPS模拟 45 乔迁之喜
    CSPS模拟 44
    平衡二叉树
    go语言学习--指针数组和数组指针
  • 原文地址:https://www.cnblogs.com/jokerBi/p/11356938.html
Copyright © 2011-2022 走看看