Skip to content

Instantly share code, notes, and snippets.

@dipakkr
Created November 1, 2018 11:26
Show Gist options
  • Save dipakkr/ba5947b46b453160f8871edecd1180df to your computer and use it in GitHub Desktop.
Save dipakkr/ba5947b46b453160f8871edecd1180df to your computer and use it in GitHub Desktop.
import cv2
import numpy as np
image = cv2.imread('image.jpg')
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
# template image
waldo = cv2.imread('target.png', 0)
result = cv2.matchTemplate(gray, waldo, cv2.TM_CCOEFF)
min_val, max_val, min_loc, max_loc = cv2.minMaxLoc(result)
# box
top_left = max_loc
bottom_left = (top_left[0] + 50, top_left[1] + 50)
cv2.rectangle(image, top_left, bottom_left, (0, 0, 255), 5)
cv2.imshow('Waldo image', image)
cv2.waitKey(0)
cv2.destroyAllWindows()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment