微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

多模板匹配性能

如何解决多模板匹配性能

对于网络钓鱼检测,我使用模板与 OpenCV 匹配将数千个徽标与潜在网络钓鱼页面的屏幕截图进行比较:

def doShot(file_path,ref_path,results):

colorread = 1

shot = cv2.imread(file_path,colorread)

scale_percent = 40 # percent of original size
width = int(shot.shape[1] * scale_percent / 100)
height = int(shot.shape[0] * scale_percent / 100)
dim = (width,height)

scaled_shot = cv2.resize(shot,dim,interpolation = cv2.INTER_AREA)

matches = []

dir_list = sorted(os.listdir(ref_path))
for f in dir_list:
        
    fpath = os.path.join(ref_path,f)
    
    template = cv2.imread(fpath,colorread)

    # Scale the template in varIoUs sizes
    for i in [0.9,1,1.1]:

        width = int(template.shape[1] * (scale_percent * i) / 100)
        height = int(template.shape[0] * (scale_percent * i) / 100)
        dim = (width,height)
    
        scaled_template = cv2.resize(template,interpolation = cv2.INTER_AREA)
        
        res = cv2.matchTemplate(scaled_shot,scaled_template,cv2.TM_CCOEFF_norMED)
        min_val,max_val,min_loc,max_loc1 = cv2.minMaxLoc(res)
        
        if max_val > 0.92:
            return True
            
return False

为了获得性能,我缩小了图像,但是比较所有徽标需要几分钟时间。如何让算法更快?

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。