您能否进行一些代码审查。有没有办法减少该功能的运行时间?现在平均工作时间约为3秒。
def searchCards(screen_area, deck, list_length):
hand = ''
threshold = 0.98
for value in deck:
try:
path = getLastScreen(screen_area)
path = path[0]['image_path']
img_rgb = cv2.imread(path, 0)
template = cv2.imread(str(value['image_path']), 0)
res = cv2.matchTemplate(img_rgb, template, cv2.TM_CCOEFF_NORMED)
loc = np.where(res >= threshold)
if len(loc[0]) != 0:
hand += value['alias']
if len(hand) == list_length:
return hand
except Exception as e:
error_log.errorLog('searchCards', str(e))
print(e)
if len(hand) < 4:
hand = '72o'
return hand