Skip to content

Instantly share code, notes, and snippets.

@mutsune
Created July 24, 2019 04:47
Show Gist options
  • Save mutsune/8a9b494ac45aae75934fb079c4891675 to your computer and use it in GitHub Desktop.
Save mutsune/8a9b494ac45aae75934fb079c4891675 to your computer and use it in GitHub Desktop.
import cv2
img = cv2.imread("input.png")
tmpl = cv2.imread("tmpl.png")
gray = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)
tmpl = cv2.cvtColor(tmpl, cv2.COLOR_RGB2GRAY)
match = cv2.matchTemplate(img, gray, cv2.TM_SQDIFF_NORMED)
min_value, max_value, min_pt, max_pt = cv2.minMaxLoc(match)
pt = min_pt
hight, width = tmpl.shape[:2]
cv2.rectangle(
img,
(pt[0], pt[1]),
(pt[0] + width, pt[1] + hight),
(0, 0, 200),
3
)
cv2.imwrite("output.png", img)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment