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?

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
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
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education