Complete the code to load an image for face recognition.
import cv2 image = cv2.imread([1]) print(image.shape)
The cv2.imread function requires the file path as a string, so it must be in quotes.
Complete the code to convert the image to grayscale for face detection.
gray_image = cv2.cvtColor(image, [1]) print(gray_image.shape)
To convert a color image to grayscale, use cv2.COLOR_BGR2GRAY.
Fix the error in the face detection code by filling the correct method name.
face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml') facedetect = face_cascade.[1](gray_image, scaleFactor=1.1, minNeighbors=5) print(len(facedetect))
The correct method to detect faces using Haar cascades in OpenCV is detectMultiScale.
Fill both blanks to create a dictionary of face locations with width and height.
faces_info = {i: (x, y, [1], [2]) for i, (x, y, w, h) in enumerate(facedetect)}
print(faces_info)The width and height of each detected face are w and h respectively.
Fill all three blanks to draw rectangles around detected faces on the image.
for (x, y, w, h) in facedetect: cv2.rectangle(image, ([1], [2]), (x + w, y + h), [3], 2) cv2.imshow('Faces', image) cv2.waitKey(0) cv2.destroyAllWindows()
The rectangle starts at (x, y) and uses blue color (255, 0, 0) in BGR format.
