| 106 | return img1 |
| 107 | |
| 108 | def template_match(self, tpl, target): |
| 109 | th, tw = tpl.shape[:2] |
| 110 | result = cv2.matchTemplate(target, tpl, cv2.TM_CCOEFF_NORMED) |
| 111 | # Find min and max value positions in matrix |
| 112 | min_val, max_val, min_loc, max_loc = cv2.minMaxLoc(result) |
| 113 | tl = max_loc |
| 114 | br = (tl[0] + tw, tl[1] + th) |
| 115 | # Draw rectangle border to mark the matched area |
| 116 | # target: target image |
| 117 | # tl: rectangle top-left corner |
| 118 | # br: rectangle width and height |
| 119 | # (0,0,255): rectangle border color |
| 120 | # 1: rectangle border size |
| 121 | cv2.rectangle(target, tl, br, (0, 0, 255), 2) |
| 122 | cv2.imwrite(self.out, target) |
| 123 | return tl[0] |
| 124 | |
| 125 | @staticmethod |
| 126 | def image_edge_detection(img): |