0

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.

grab_image

ref_image

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()
krisiun
  • 1
  • 2
  • If you don't provide a [mcve] that reproduces the problem, I'm not sure how we can help you. Noone in their right mind will try to reinvent your code, hoping they made the same (possible) mistake you have, and then try to debug that. – Dan Mašek Apr 07 '18 at 20:01
  • sample code is added as requested. Extracting this templates is another process but it is not a question. The question is that why template matching returns zero when two inputs have same resolution and almost same intensity levels. – krisiun Apr 07 '18 at 20:17

0 Answers0