簡體   English   中英

向人臉檢測程序添加人臉識別功能

[英]Adding Face Recognition functionality to a face detection program

我有一個人臉檢測程序,可以在看到人臉時在其周圍繪制一個矩形。 但是,我希望我的程序能夠識別某些面孔並能夠顯示面孔的名稱。

這是我當前的代碼:

    import cv2

    #load the cascade
    face_cascade = 
    cv2.CascadeClassifier('haarcascade_frontalface_default.xml')

    #capture video from webcam
    cap = cv2.VideoCapture(0)

    #continuously capture video
    while True:
       #read the frame
      _, img = cap.read()
      #convert to grayscale
      gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
      #detect a face
      faces = face_cascade.detectMultiScale(gray, 1.1, 4)
      #draw a rectangle to confirm face
      for (x, y, w, h) in faces:
        cv2.rectangle(img, (x, y), (x + w, y + h), (255, 0, 0), 2)
        #display video
        cv2.imshow('img', img)
        #stop if escape key is pressed
        k = cv2.waitKey(30) & 0xff
        if k == 27:
           break

    #release the video capture object
    cap.release()

如何在仍然使用我擁有的代碼而又不進行任何重大更改的情況下實現人臉識別? 任何幫助將不勝感激。

沒關系,我知道了。 我決定在此頁面的幫助下使用face_recognition庫: 在此處輸入鏈接描述

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM