import cv2
import numpy as np
img_rgb = cv2.imread('mainimage.jpg').
img_gray = cv2.cvtColor(img_rgb, cv2.COLOR_BGR2GRAY)
template = cv2.imread('template', 0)
w, h = template.shape[::-1]
resize = imutils.resize(img_gray, width=int(shape[0]), height=int(img_gray.shape[1]*scale)
if resized.shape[0] < h or resized.shape[1] < w:
break
found=(maxVal, maxLoc, r)
(__, maxLoc, r)=found
(startX, startY)=(int(maxLoc[0]*r), int maxLoc[1]*r)
(endX, endY)=(int((maxLoc[0]+tw)*r), int(maxLoc[1]+tH)*r)
cv2.rectangle(image, (startX, startY), (endX, endY), (0, 0, 255), 2)
cv2.imshow("Image", image)
cv2.waitKey(0)