1
votes

I have a face detection program that can draw a rectangle around a face when it sees it. However, I want my program to be able to recognize certain faces and be able to display the face's name.

Here's my current code:

    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()

How can I implement face recognition while still using the code I have and without making any drastic changes? Any help will be gladly appreciated.

1
In case anyone's wondering what I mean by face recognition, I mean that I want the program to be able to lable the face. - shreyshrey

1 Answers

0
votes

Nevermind, I figured it out. I decided to use the face_recognition library with help from this page: enter link description here