zoukankan      html  css  js  c++  java
  • 6模板匹配(人脸匹配案例)

    模板匹配(人脸匹配案例)
    import cv2 as cv
    import numpy as np
    
    
    def template_demo():
        tpl = cv.imread("C:/Users/wml/Desktop/wml/ym_sample.png")
        target = cv.imread("C:/Users/wml/Desktop/wml/ym.jpg")
        cv.imshow("template image", tpl)
        cv.imshow("target image", target)
        methods = [cv.TM_SQDIFF_NORMED, cv.TM_CCORR_NORMED, cv.TM_CCOEFF_NORMED]#使用三种方法检测
        th, tw = tpl.shape[:2]
        for md in methods:
            print(md)
            result = cv.matchTemplate(target, tpl, md)
            min_val, max_val, min_loc, max_loc = cv.minMaxLoc(result)
            if md == cv.TM_SQDIFF_NORMED:
                tl = min_loc
            else:
                tl = max_loc
            br = (tl[0]+tw, tl[1]+th);
            cv.rectangle(target, tl, br, (0, 0, 255), 2)
            #cv.imshow("match-"+np.str(md), target)
            cv.imshow("match-" + np.str(md), target)#利用
    
    
    
    print("--------- Python OpenCV Tutorial ---------")
    src = cv.imread("C:/Users/wml/Desktop/wml/ym.jpg")
    cv.namedWindow("input image", cv.WINDOW_AUTOSIZE)
    cv.imshow("input image", src)
    template_demo()
    cv.waitKey(0)
    
    cv.destroyAllWindows()
  • 相关阅读:
    Django【进阶】信号
    Django【进阶】缓存
    exec,eval
    linux下磁盘分区、格式化、挂载
    Django【进阶】中间件
    Django【进阶】权限管理
    Django【进阶】FBV 和 CBV
    MySQL 进阶(待发布)
    Django【进阶】
    django 分页和中间件
  • 原文地址:https://www.cnblogs.com/wml2018/p/12181680.html
Copyright © 2011-2022 走看看