로그인

검색

Python
2014.01.16 00:49

OpenCV 이용한 템플릿 매칭

MoA
조회 수 13151 추천 수 0 댓글 0
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 게시글 수정 내역 댓글로 가기 인쇄
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 게시글 수정 내역 댓글로 가기 인쇄

템플릿 매칭(Template Matching) = 큰 이미지에서 특정 작은 이미지를 찾는 알고리즘


import cv2
import numpy as np
from matplotlib import pyplot as plt

img = cv2.imread('messi5.jpg',0)
img2 = img.copy()
template = cv2.imread('template.jpg',0)
w, h = template.shape[::-1]

# All the 6 methods for comparison in a list
methods = ['cv2.TM_CCOEFF', 'cv2.TM_CCOEFF_NORMED', 'cv2.TM_CCORR',
            'cv2.TM_CCORR_NORMED', 'cv2.TM_SQDIFF', 'cv2.TM_SQDIFF_NORMED']

for meth in methods:
    img = img2.copy()
    method = eval(meth)

    # Apply template Matching
    res = cv2.matchTemplate(img,template,method)
    min_val, max_val, min_loc, max_loc = cv2.minMaxLoc(res)

    # If the method is TM_SQDIFF or TM_SQDIFF_NORMED, take minimum
    if method in [cv2.TM_SQDIFF, cv2.TM_SQDIFF_NORMED]:
        top_left = min_loc
    else:
        top_left = max_loc
    bottom_right = (top_left[0] + w, top_left[1] + h)

    cv2.rectangle(img,top_left, bottom_right, 255, 2)

    plt.subplot(121),plt.imshow(res,cmap = 'gray')
    plt.title('Matching Result'), plt.xticks([]), plt.yticks([])
    plt.subplot(122),plt.imshow(img,cmap = 'gray')
    plt.title('Detected Point'), plt.xticks([]), plt.yticks([])
    plt.suptitle(meth)

    plt.show()

https://opencv-python-tutroals.readthedocs.org/en/latest/py_tutorials/py_imgproc/py_template_matching/py_template_matching.html

?

List of Articles
번호 분류 제목 글쓴이 날짜 조회 수
공지 Tool/etc Programming 게시판 관련 2 MoA 2014.11.01 111160
340 LLM everything is a ralph loop OBG 2026.03.05 819
339 LLM [OpenAI] 엔지니어링 활용: 에이전트 우선 환경에서 Codex를 활용하기 OBG 2026.03.05 1059
338 Agent Claude Code 창시자가 공개한 실전 사용 팁 OBG 2026.02.03 2201
337 Agent Claude Skills 구축을 위한 완벽 가이드 OBG 2026.02.03 2206
336 Agent 앤트로픽 해커톤 우승자의 클로드 코드 구성(configuration) 전체 컬렉션 OBG 2026.01.22 3117
335 LLM 나노바나나 프로 레시피 북 OBG 2026.01.15 4361
334 모던 Node.js 패턴 (2025) OBG 2025.08.07 5392
333 Deeplearning Apriori 알고리즘 OBG 2025.12.09 6411
332 Agent Claude Code 마스터하기 (Github, 책) OBG 2026.01.22 6454
331 Agent Claude Code - Ollama Integration OBG 2026.01.26 6465
330 Web 함수형 프로그래밍을 배워보자! OBG 2025.11.25 6598
329 Web 알아두면 유익한 2019 개발이야기 OBG 2025.09.15 7258
328 Agent 초보를 위한 Claude Code 안내서 OBG 2025.09.15 7287
327 Omarchy, DHH가 만든 Linux 배포판 OBG 2025.08.12 7405
326 Agent Vibe Code an MVP Web App OBG 2025.08.28 7600
325 Web JSON.stringify를 두 배 이상 빠르게 만든 방법 OBG 2025.08.07 7765
324 Agent Kimi K2 클로드 코드와 함께 사용하는 방법 OBG 2025.08.28 7794
323 Agent Claude Code를 최고의 설계 파트너로 만들기 OBG 2025.08.28 7830
322 LLM 클로드 코드로 프로덕트 팀 바이브코딩 표준화한 방법 (aka 맥도날드 시스템) OBG 2025.11.24 8165
321 Agent 코딩 에이전트 만드는 법 OBG 2025.08.28 8188
Board Pagination Prev 1 2 3 4 5 6 7 8 9 10 ... 17 Next
/ 17