使用归一化互相关的手动模板匹配

时间:2018-10-27 18:57:46

标签: python opencv image-processing

因此,我必须使用此代码来编写与模板匹配的代码 formula

这是我的函数的样子,如何使它起作用?返回一个介于1和0之间的值,对吧?

import numpy as np

def correlation(image_original, image_element):

  altura_1, w_1, channels_1 = image_original.shape
  height_2, w_2, channels_2 = image_element.shape

  partial_sum_1 = float(np.sum(image_original))
  average_1 = partial_sum_1 / (height_1 * w_1)
  partial_sum_2 = float(np.sum(image_element))
  average_2 = partial_sum_2 / (height_2 * w_2)

  # Normalized Cross Correlation

  top_equation = np.sum((imagem_original - average_1) * (imagem_elemento - average_2))
  e1 = np.sum((image_original - average_1)**2)
  e2 = np.sum((image_element - average_2)**2)
  result = (top_equation) / ((e1 * e2)**(1/2))
  return result

0 个答案:

没有答案