반응형


이번 영상에서는 윈도우즈 10에서 화면을 캡처한 결과를 입력으로 사용하여 OpenCV Python에서 탬플릿 매칭을 해보았습니다.






# pip install pyautogui
# pip install opencv-python
import cv2 as cv
import numpy as np
import pyautogui



cv.namedWindow("result");
cv.moveWindow("result", 0, 500);

img_piece = cv.imread('dino.png', cv.IMREAD_COLOR)
h,w = img_piece.shape[:2]


while 1:
    pic = pyautogui.screenshot(region=(0, 0, 700, 500))
    img_frame = np.array(pic)
    img_frame  = cv.cvtColor(img_frame, cv.COLOR_RGB2BGR)
    meth = 'cv.TM_CCOEFF'
    method = eval(meth)


    res = cv.matchTemplate(img_piece, img_frame, method)
    min_val, max_val, min_loc, max_loc = cv.minMaxLoc(res)
    top_left = max_loc
    bottom_right = (top_left[0] + w, top_left[1] + h)

    cv.rectangle(img_frame, top_left, bottom_right, (0, 255, 0), 2)
    print(max_val, top_left)

    cv.imshow('result', img_frame)
   
    key = cv.waitKey(1)
    if key == 27:
        break



최초작성 2020. 04. 09


반응형

문제 발생시 지나치지 마시고 댓글 남겨주시면 가능한 빨리 답장드립니다.

도움이 되셨다면 토스아이디로 후원해주세요.
https://toss.me/momo2024


제가 쓴 책도 한번 검토해보세요 ^^

+ Recent posts