I'am simply using template matching with method cv2.TM_CCOEFF_NORMED by using opencv. The difference is that both reference image and warped image are divided into small pieces for instances 128x108 resolution. Generally, it works well but sometimes it returns zero even both pieces are almost same. Below are the sample image pairs that one of them has a line with "1" intensity but all other values are zero. Is there a specific reason why it fails for this example? Maybe because of low resolution of images?
Thanks in advance.
import cv2
import numpy as np
np.set_printoptions(threshold='nan')
def main():
img_ref = cv2.imread('folderoftheimage')
img_grab = cv2.imread('folderoftheimage')
max_val_array = []
template_matching_array = []
# Apply template Matching
res = cv2.matchTemplate(img_ref,img_grab,cv2.TM_CCOEFF_NORMED)
min_val, max_val, min_loc, max_loc = cv2.minMaxLoc(res)
max_val_array.append(max_val)
print "min_val", min_val
print "max_val", max_val
print "min_loc", min_loc
print "max_loc", max_loc
template_matching_array.append(np.min(max_val_array))
index_min = max_val_array.index(np.min(max_val_array))
print "template matching", template_matching_array
print "zero element", index_min
main()