一次失败的OpenCV图片识别经历……

想用OpenCV实现以图搜图,以为遍历还OK,结果太年轻了,遍历10000张图,本地运行6秒,服务器运行75秒……考虑优化方案ing……

import threading
thn = 10
total = 10000

def mathc_img(image,Target,value,prt):
    import cv2
    import numpy as np
    img_rgb = cv2.imread(image,0)
    #img_gray = cv2.cvtColor(img_rgb, cv2.COLOR_BGR2GRAY)
    template = cv2.imread(Target,0)
    #w, h = template.shape[::-1]
    res = cv2.matchTemplate(img_rgb,template,cv2.TM_CCOEFF_NORMED)
    threshold = value
    loc = np.where( res >= threshold)
    if(len(loc[0])>0):
        print(str(prt)+'found!')
    #for pt in zip(*loc[::-1]):
        #cv2.rectangle(img_rgb, pt, (pt[0] + w, pt[1] + h), (7,249,151), 2)
    #cv2.imshow('Detected',img_rgb)
    #cv2.waitKey(0)
    #cv2.destroyAllWindows()

def imgsearch(start,end):
    for i in range(start, end):
        image=("image/cardsoss/"+str(i)+".jpg")
        Target=('m.jpg')
        value=0.85
        try:
            mathc_img(image,Target,value,i)
        except:
            print(str(i)+'failed!!!')

class myThread (threading.Thread):
    def __init__(self, threadID, name, start1 , end1):
        threading.Thread.__init__(self)
        self.threadID = threadID
        self.name = name
        self.start1 = start1
        self.end1 = end1
    def run(self):
        print ("开始线程:" + self.name)
        imgsearch(self.start1, self.end1)
        print ("退出线程:" + self.name)

import time
time_start=time.time()

names = locals()
for j in range (0,thn):
    names['tread'+str(j)] =  myThread(j , "Thread-"+str(j) , int(total*j/thn+1) , int(total*(j+1)/thn+1)) 
    names['tread'+str(j)].start()
for j in range (0,thn):
    names['tread'+str(j)].join()

time_end=time.time()
print('totally cost',time_end-time_start)