【Python】通过截图匹配原图中的位置(opencv)

来源:互联网 发布:各厂大数据平台 编辑:程序博客网 时间:2024/05/22 08:18

安装依赖

1)下载安装opencv-2.4.9,并将cv2.pyd拷贝到python安装目录的site-package下2)pip install numpy3)pip install aircv

准备一张原图和截图

原图

这里写图片描述

截图

这里写图片描述


代码

import cv2import aircv as ac# print circle_center_posdef draw_circle(img, pos, circle_radius, color, line_width):    cv2.circle(img, pos, circle_radius, color, line_width)    cv2.imshow('objDetect', imsrc)     cv2.waitKey(0)    cv2.destroyAllWindows()if __name__ == "__main__":    imsrc = ac.imread('bg.jpg')    imobj = ac.imread('obj.png')    # find the match position    pos = ac.find_template(imsrc, imobj)    circle_center_pos = pos['result']    circle_radius = 50    color = (0, 255, 0)    line_width = 10    # draw circle    draw_circle(imsrc, circle_center_pos, circle_radius, color, line_width)

效果图

这里写图片描述

0 0