dino_api.py 文件源码

python
阅读 35 收藏 0 点赞 0 评论 0

项目:go_dino 作者: pauloalves86 项目源码 文件源码
def find_game_position(screenshotter, threshold) -> Dict:
    dino_template = cv2.imread(os.path.join('templates', 'dino.png'), 0)
    w, h = dino_template.shape[::-1]
    landscape_template = cv2.imread(os.path.join('templates', 'dino_landscape.png'), 0)
    lw, lh = landscape_template.shape[::-1]
    monitor = screenshotter.monitors[0]
    buffer = screenshotter.grab(monitor)
    image = Image.frombytes('RGB', buffer.size, buffer.rgb).convert('L')
    image = np.array(image)
    res = cv2.matchTemplate(image, dino_template, cv2.TM_CCOEFF_NORMED)
    loc = np.where(res >= threshold)
    if len(loc[0]):
        pt = next(zip(*loc[::-1]))
        return dict(monitor, height=lh, left=pt[0], top=pt[1] - lh + h, width=lw)
    return {}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号