如何利用OpenCv解决图片定位

class TestDemo:
    def __init__(self, driver):
        self.driver = driver

    def find_image(self, target):
        # 定义截图路径
        screen_path = os.path.join(screen_image, "screen.png")
        # 截图
        self.driver.get_screenshot_as_file(screen_path)
        source = cv.imread(screen_path)
        template = cv.imread(target)
        result = cv.matchTemplate(source, template, cv.TM_CCOEFF_NORMED)
        imin, imax, min_loc, max_loc = cv.minMaxLoc(result)
        if imax > 0.95:
            pos_x = max_loc[0] + int(template.shape[1] / 2)
            pos_y = max_loc[1] + int(template.shape[0] / 2)
            return [True, (pos_x, pos_y)]
        else:
            return False

 

posted @ 2020-11-06 17:46  勇敢面对difficult  阅读(637)  评论(0)    收藏  举报