【Python】通過截圖匹配原圖中的位置(opencv)
阿新 • • 發佈:2019-01-31
安裝依賴
1)下載安裝opencv-2.4.9,並將cv2.pyd拷貝到python安裝目錄的site-package下
2)pip install numpy
3)pip install aircv
準備一張原圖和截圖
原圖
截圖
程式碼
import cv2
import aircv as ac
# print circle_center_pos
def 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)