Skip to content

Instantly share code, notes, and snippets.

@heaven00
Created December 24, 2014 05:52
Show Gist options
  • Save heaven00/3e1fd8052bde8ec648f3 to your computer and use it in GitHub Desktop.
Save heaven00/3e1fd8052bde8ec648f3 to your computer and use it in GitHub Desktop.
Template matching trial
#sign to be detected
template = cv2.imread('sign.png')
#image in which it is to be directed
image = cv2.imread('iamge.jpg')
template_gray = cv2.cvtColor(template, cv2.COLOR_BGR2GRAY)
image_gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
res = cv2.matchTemplate(image_gray, template_gray, cv2.TM_CCOEFF_NORMED)
threshold = 0.7
loc = np.where(res >= threshold)
print loc
for point in zip(*loc[::-1]):
cv2.rectangle(image, point, (20, 20), (0, 0, 255), 2)
cv2.imwrite('test.jpg', image)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment