Skip to content

Instantly share code, notes, and snippets.

@G07cha
Created June 16, 2015 14:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save G07cha/742a1b0acad05077cdf1 to your computer and use it in GitHub Desktop.
Save G07cha/742a1b0acad05077cdf1 to your computer and use it in GitHub Desktop.
import cv2
import sys
from matplotlib import pyplot as plt
#Path to image containing fragment
img = cv2.imread(sys.argv[1], 0)
#Path to fragment
template = cv2.imread(sys.argv[2], 0)
method = 'cv2.TM_CCOEFF'
# Apply template Matching
res = cv2.matchTemplate(img, template, eval(method))
min_val, max_val, min_loc, max_loc = cv2.minMaxLoc(res)
#Will return coords of top left corner
sys.stdout.write("%s;%s" % (max_loc[0], max_loc[1]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment