import cv2
import os
def capture_images(person_name, image_count):
# Initialize the webcam or camera module
cap = [Link](0)
# Create a folder for the person's images if it doesn't exist
folder_path = f'images/{person_name}'
[Link](folder_path, exist_ok=True)
# Load the Haar cascade for face detection
face_cascade = [Link]([Link] +
'haarcascade_frontalface_default.xml')
# Capture images
count = 0
while count < image_count:
# Capture frame-by-frame
ret, frame = [Link]()
# Convert the frame to grayscale for face detection
gray = [Link](frame, cv2.COLOR_BGR2GRAY)
# Detect faces in the grayscale frame
faces = face_cascade.detectMultiScale(gray, scaleFactor=1.3,
minNeighbors=5)
for (x, y, w, h) in faces:
# Draw rectangle around the face
[Link](frame, (x, y), (x + w, y + h), (255, 0, 0), 2)
# Save the face image to the folder
face_image = [Link](folder_path,
f'{person_name}_{count}.jpg')
[Link](face_image, frame[y:y + h, x:x + w])
# Increment image count
count += 1
# Display the captured frame
[Link]('Capture Images', frame)
# Break the loop when 'q' is pressed
if [Link](1) & 0xFF == ord('q'):
break
# Release the camera and close OpenCV windows
[Link]()
[Link]()
# Main function to capture images
if __name__ == "__main__":
person_name = input("Enter the person's name: ")
image_count = int(input("Enter the number of images to capture: "))
capture_images(person_name, image_count)