Python OpenCV学習ノート之:画像テンプレートマッチング

1008 ワード

# -*- coding: utf-8 -*-
"""
      
                  
         
                       ,        :                             。
        100x100     ,   10x10     ,         :
 (1)         (0,0)  ,    (0,0) (10,10)     ;
 (2)              ,      c;
 (3)    c,      (0,0)     ;
 (4)       (0,1) (10,11)     ,  ,        ;
 (5)  (1)~(4)           。
         
     OpenCv EmguCv     6     :
    CV_TM_SQDIFF       :             ;       0;    ,     。
    CV_TM_CCORR      :         ;            。
    CV_TM_CCOEFF        :1       ;-1       。
    CV_TM_SQDIFF_NORMED          
    CV_TM_CCORR_NORMED         
    CV_TM_CCOEFF_NORMED           
  :http://www.cnblogs.com/xrwang/archive/2010/02/05/MatchTemplate.html
"""
import cv2
import numpy as np
from matplotlib import pyplot as plt

img = cv2.imread('../../../datas/images/apple.jpg',0)
img2 = img.copy()
template = cv2.imread('../../../datas/images/apple-template.jpg',0)
w, h = template.shape[::-