Python+OpenCV摄像头人脸识别

Python+Opencv摄像头人脸识别

如需远程调试,可加QQ905733049由专业技术人员远程协助!
或进入博主淘宝连接咨询:https://item.taobao.com/item.htm?id=610632013406

运行代码如下:

import cv2

cap = cv2.VideoCapture(0)

while(True):
    # Capture frame-by-frame
    ret, frame = cap.read()

    # Our operations on the frame come here
    gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)

    xmlfile = r'haarcascade_frontalface_default.xml'

    face_cascade = cv2.CascadeClassifier(xmlfile)
    faces = face_cascade.detectMultiScale(
        gray,
        scaleFactor=1.15,
        minNeighbors=5,
        minSize=(5, 5),
    )
    print("发现{0}个目标!".format(len(faces)))
    for (x, y, w, h) in faces:
        cv2.rectangle(frame, (x, y), (x + w, y + w), (0, 255, 0), 2)

    cv2.imshow("frame", frame)
    # Display the resulting frame
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

# When everything done, release the capture
cap.release()
cv2.destroyAllWindows()

![在这里插入图片描述](https://img-blog.csdnimg.cn/20200325225552688.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L2FsaWNlbWExMTEx,size_16,color_FFFFFF,t_70#pic_center)

 运行结果:

 

 

你可能感兴趣的:(Python+OpenCV摄像头人脸识别)