• 7人脸识别


    1图片静态识别

    import cv2 as cv
    import numpy as np
    
    
    def face_deftect_demo():
        #转化为灰度图
        gray =cv.cvtColor(src,cv.COLOR_BGR2GRAY)
        #加载特征数据
        face_detector = cv.CascadeClassifier(  "D:/sofeware/sofeware/python37/Lib/site-packages/cv2/data/haarcascade_frontalface_alt_tree.xml")
        #在多个尺度空间进行检测(图像名,向上或者向下变换尺度值(原图几倍),变换图清晰度低选择低的值,调整1.02为1.1可以加快速度)
        faces = face_detector.detectMultiScale(gray, 1.02, 2)
        #绘制矩形,提取长宽高,设置线的颜色,宽度
        for x, y, w, h in faces:
            cv.rectangle(src, (x, y), (x+w, y+h), (0, 0, 255), 2)
        cv.imshow("result", src)
    
    
    print("--------- Python OpenCV Tutorial ---------")
    src = cv.imread("C:/Users/wml/Desktop/wml/ym.jpg")
    cv.namedWindow("input image", cv.WINDOW_AUTOSIZE)
    cv.namedWindow("result", cv.WINDOW_AUTOSIZE)
    cv.imshow("input image", src)
    face_deftect_demo()
    cv.waitKey(0)
    cv.destroyAllWindows()

    2视频动态识别

    import cv2 as cv
    import numpy as np
    def face_deftect_demo(image):
        gray =cv.cvtColor(image,cv.COLOR_BGR2GRAY)
        face_detector = cv.CascadeClassifier(  "D:/sofeware/sofeware/python37/Lib/site-packages/cv2/data/haarcascade_frontalface_alt_tree.xml")
        faces = face_detector.detectMultiScale(gray, 1.02, 1)
        for x, y, w, h in faces:
            cv.rectangle(image, (x, y), (x+w, y+h), (0, 0, 255), 2)
        cv.imshow("result", image)
    
    
    print("--------- Python OpenCV Tutorial ---------")
    capture = cv.VideoCapture(0)
    cv.namedWindow("result", cv.WINDOW_AUTOSIZE)
    while(True):
        ret, frame = capture.read()
        frame = cv.flip(frame, 1)#镜像变换
        face_deftect_demo(frame)
        c=cv.waitKey(10)
        if(c==27):#esc停止执行
            break
    # cv.imshow("input image", src)
    # face_deftect_demo()
    cv.waitKey(0)
    cv.destroyAllWindows()
  • 相关阅读:
    无root权限安装tmux
    mosquitto_pub和mosquitto_sub 命令参数说明
    安装Mosquitto学习MOTT协议
    Linux之prink原理
    JZ2440支持设备树(1)-添加设备树之后kernel的启动参数跟dts里面不一致
    Linux可以生产uImage
    Ubuntu18.04下make menuconfig缺少ncurses库
    如何打开kernel最开始的打印
    buildroot管理uboot+kernel+rootfs
    STM32L071CBTX操作ECC508
  • 原文地址:https://www.cnblogs.com/wml2018/p/12181681.html
Copyright © 2020-2023  润新知