메뉴 건너뛰기

OBG

Programming

Python
2014.01.16 00:49

OpenCV 이용한 템플릿 매칭

MoA
조회 수 1250 추천 수 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

?

  1. Programming 게시판 관련

    Date2014.11.01 CategoryTool/etc ByMoA Views1714
    read more
  2. 후킹 링크

    Date2013.07.28 CategoryAPI/MFC ByMoA Views416
    Read More
  3. 화면 캡쳐 소스

    Date2014.01.14 CategoryPython ByMoA Views973
    Read More
  4. 프린터 출력하기

    Date2013.10.16 CategoryAPI/MFC ByMoA Views3437
    Read More
  5. 프로세스 - 생성과 종료 그리고 이것 저것

    Date2011.10.12 CategoryAPI/MFC By너울 Views1834
    Read More
  6. 프로그램 배포용으로 만드는 과정

    Date2012.01.20 CategoryAPI/MFC By너울 Views488
    Read More
  7. 프로그래밍 관련 사이트

    Date2012.08.02 CategorySite ByMoA Views255
    Read More
  8. 파일 입출력

    Date2013.07.28 CategoryC/C++ ByMoA Views488
    Read More
  9. 파이썬에서 C모듈 사용하기

    Date2014.02.10 CategoryPython ByMoA Views1919
    Read More
  10. 파이썬 머신러닝 무료 강의 (7시간)

    Date2022.07.06 CategoryDeeplearning ByOBG Views97
    Read More
  11. 특정 자료형의 데이터를 binary(hex값, 2진수값)으로 변환

    Date2012.11.15 CategorySite ByNaya Views562
    Read More
  12. 텍스트 에디터 Sublime Text 2

    Date2012.03.30 CategoryTool/etc By너울 Views505
    Read More
  13. 태스크 대화상자 (Task Dialog)

    Date2013.10.22 CategoryAPI/MFC ByMoA Views436
    Read More
  14. 큰 수 구하기 알고리즘

    Date2012.08.02 CategoryAlgorithm ByNaya Views658
    Read More
  15. 쿠버네티스 클러스터

    Date2022.11.11 CategoryTool/etc ByOBG Views112
    Read More
  16. 코드 실행 시간 계산

    Date2012.08.02 CategoryC/C++ ByNaya Views297
    Read More
  17. 코드 실행 시간 계산

    Date2012.09.27 CategoryC/C++ ByNaya Views493
    Read More
  18. 컨텍스트 스위칭 (Context Switching)

    Date2013.07.28 CategoryTool/etc ByMoA Views1039
    Read More
  19. 카카오톡 웹버전 만들기

    Date2022.11.09 CategoryWeb ByOBG Views193
    Read More
  20. 추천(Recommendation) 시스템 - 알고리즘 Trend 정리

    Date2021.08.03 CategoryDeeplearning ByOBG Views134
    Read More
  21. 추천 시스템

    Date2023.03.30 CategoryDeeplearning ByOBG Views120
    Read More
Board Pagination Prev 1 2 3 4 5 6 7 8 9 10 ... 15 Next
/ 15
위로