import cv2
import numpy as np
import time
img = cv2.imread('rotate.png', 0)
template = cv2.imread('thresh_2.png', 0)
w, h = template.shape[::-1]
start = time.time();
res = cv2.matchTemplate( template, img, cv2.TM_CCORR)
stop = time.time();
print "TIME ",stop-start;
min_val, max_val, min_loc, max_loc = cv2.minMaxLoc( res )
top_left = max_loc
bottom_right = ( top_left[0] + w, top_left[1] + h )
cv2.rectangle( template, top_left, bottom_right, 255, 2 )
以上代码运行良好,但是cv2.matchtemplate
函数花费的时间超出了预期。
单条指令cv2.matchtemplate
花费的时间为0.23秒。
我该如何解决?