import cv2 import numpy as np # Load the pre-trained model for face detection face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml') # Load the pre-trained model for face recognition recognizer = cv2.face.LBPHFaceRecognizer_create() recognizer.read("trained_model.yml") # Load the list of people and their IDs people = ["person1", "person2", "person3"] ids = [1, 2, 3] # Open the video stream cap = cv2.VideoCapture(0) while True:     # Read the frame from the video stream     ret, frame = cap.read()     # Convert the frame to grayscale     gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)     # Detect faces in the grayscale frame     faces = face_cascade.detectMultiScale(gray, 1.3, 5)     for (x,y,w,h) in faces:         # Get the ROI of the face         roi_gray = gray[y:y+h, x:x+w]         # Recognize the face using the pre-trained model         id, confidence = recognizer.predict(roi_gray)         # Draw a rectangle around the face         cv2.rectangle(frame, (x,y), (x+w,y+h), (0,255,0), 2)         # Add the name of the recognized person to the rectangle         if confidence < 100:             name = people[ids.index(id)]             cv2.putText(frame, name, (x+5,y-5), cv2.FONT_HERSHEY_SIMPLEX, 1, (0,255,0), 2)     # Show the frame     cv2.imshow('frame',frame)     # Exit if the 'q' key is pressed     if cv2.waitKey(1) & 0xFF == ord('q'):         break # Release the video stream and close all windows cap.release() cv2.destroyAllWindows()   Running with above coding for face recognition with opencv+python at visual code and i got error as per attached. please help how to solved it?

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter12: Points, Classes, Virtual Functions And Abstract Classes
Section: Chapter Questions
Problem 17SA
icon
Related questions
icon
Concept explainers
Question
import cv2
import numpy as np

# Load the pre-trained model for face detection
face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')

# Load the pre-trained model for face recognition
recognizer = cv2.face.LBPHFaceRecognizer_create()
recognizer.read("trained_model.yml")

# Load the list of people and their IDs
people = ["person1", "person2", "person3"]
ids = [1, 2, 3]

# Open the video stream
cap = cv2.VideoCapture(0)

while True:
    # Read the frame from the video stream
    ret, frame = cap.read()

    # Convert the frame to grayscale
    gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)

    # Detect faces in the grayscale frame
    faces = face_cascade.detectMultiScale(gray, 1.3, 5)

    for (x,y,w,h) in faces:
        # Get the ROI of the face
        roi_gray = gray[y:y+h, x:x+w]

        # Recognize the face using the pre-trained model
        id, confidence = recognizer.predict(roi_gray)

        # Draw a rectangle around the face
        cv2.rectangle(frame, (x,y), (x+w,y+h), (0,255,0), 2)

        # Add the name of the recognized person to the rectangle
        if confidence < 100:
            name = people[ids.index(id)]
            cv2.putText(frame, name, (x+5,y-5), cv2.FONT_HERSHEY_SIMPLEX, 1, (0,255,0), 2)

    # Show the frame
    cv2.imshow('frame',frame)

    # Exit if the 'q' key is pressed
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

# Release the video stream and close all windows
cap.release()
cv2.destroyAllWindows()
 
Running with above coding for face recognition with opencv+python at visual code and i got error as per attached.
please help how to solved it?
Traceback (most recent call last):
File "c:\Users\LENOVO\Desktop\facedetection1\percobaan2.py", line 9, in <module>
recognizer = cv2. face. LBPHFaceRecognizer_create()
AttributeError: module 'cv2' has no attribute 'face'
Transcribed Image Text:Traceback (most recent call last): File "c:\Users\LENOVO\Desktop\facedetection1\percobaan2.py", line 9, in <module> recognizer = cv2. face. LBPHFaceRecognizer_create() AttributeError: module 'cv2' has no attribute 'face'
Expert Solution
steps

Step by step

Solved in 4 steps

Blurred answer
Knowledge Booster
Concepts in designing Database
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning