| 3 | |
| 4 | |
| 5 | def template_demo(): |
| 6 | src = cv.imread("./test.png") |
| 7 | tpl = cv.imread("./test01.png") |
| 8 | cv.imshow("input", src) |
| 9 | cv.imshow("tpl", tpl) |
| 10 | th, tw = tpl.shape[:2] |
| 11 | result = cv.matchTemplate(src, tpl, cv.TM_CCORR_NORMED) |
| 12 | cv.imshow("result", result) |
| 13 | cv.imwrite("D:/039_003.png", np.uint8(result*255)) |
| 14 | t = 0.98 |
| 15 | loc = np.where(result > t) |
| 16 | |
| 17 | for pt in zip(*loc[::-1]): |
| 18 | cv.rectangle(src, pt, (pt[0] + tw, pt[1] + th), (255, 0, 0), 1, 8, 0) |
| 19 | cv.imshow("llk-demo", src) |
| 20 | cv.imwrite("D:/039_004.png", src) |
| 21 | |
| 22 | |
| 23 | template_demo() |