로그인

검색

Python
2014.01.16 00:49

OpenCV 이용한 템플릿 매칭

MoA
조회 수 3926 추천 수 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 15455
298 LLM 알리바바, 딥시크·오픈AI 넘는 추론 모델 출시..."오픈 소스 최강 입증" (QwQ-32B) OBG 2025.03.10 1205
297 Deeplearning 존 카맥이 일리야 수츠키버를 4년전에 만났을때, 추천받은 책과 논문 목록 OBG 2025.02.18 1339
296 Site 2024년 가장 조회수 높은 소프트웨어 엔지니어링 발표들 OBG 2025.02.18 1405
295 Tool/etc OS 개발에 관한 작은 책 OBG 2025.03.24 1441
294 LLM AI-hub 공공데이터를 활용하여 한국어-영어 번역 LLM 만들기 OBG 2025.01.14 1569
293 LLM llama3 implemented from scratch OBG 2024.05.24 1618
292 LLM 얼렁뚱땅 LLM을 만들어보자 OBG 2025.01.10 1649
291 LLM PEFT: Parameter-Efficient Fine-Tuning of Billion-Scale Models on Low-Resource Hardware OBG 2024.04.15 1681
290 LLM A Beginner's Guide to Prompt Engineering with GitHub Copilot OBG 2024.04.04 1785
289 Tool/etc GDB Dashboard OBG 2025.01.14 1809
288 Tool/etc GitHut Copilot - Agent 모드 공개 OBG 2025.02.14 1870
287 Tool/etc OS in 1,000 Lines OBG 2025.01.14 1879
286 서버 Caching in Node.js to optimize app performance OBG 2023.01.16 1939
285 서버 Debugging Node.js Memory Leaks: How to Detect, Solve or Avoid Them in Applications OBG 2023.07.04 1944
284 Tool/etc 나이 들어가는 프로그래머 - [발표영상] 요약 OBG 2025.02.14 2009
283 Deeplearning PyTorch 딥러닝 챗봇 OBG 2023.07.04 2141
282 LLM Mixture of Experts - Part 2 OBG 2024.04.14 2141
281 Web Creating A Fixed-Length Queue In JavaScript Using Arrays OBG 2022.09.14 2195
280 서버 멀티-플레이어 게임 서버와 레이턴시 보상 테크닉 OBG 2024.01.16 2203
279 서버 Design a Basic Search Engine (Google or Bing) | System Design Interview Prep OBG 2023.05.27 2207
Board Pagination Prev 1 2 3 4 5 6 7 8 9 10 ... 15 Next
/ 15