Complete the code to load an image using OpenCV for face analysis.
import cv2 image = cv2.imread([1])
The cv2.imread function requires the file path as a string, so the filename must be in quotes.
Complete the code to convert the image to grayscale, which is common in face analysis.
gray_image = cv2.cvtColor(image, [1])To convert a color image to grayscale, use cv2.COLOR_BGR2GRAY because OpenCV loads images in BGR format.
Fix the error in the code to detect faces using a Haar cascade classifier.
face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml') facedetected = face_cascade.[1](gray_image, scaleFactor=1.1, minNeighbors=5)
The correct method to detect objects with Haar cascades in OpenCV is detectMultiScale.
Fill both blanks to draw rectangles around detected faces and display the image.
for (x, y, w, h) in facedetected: cv2.rectangle(image, (x, y), ([1], [2]), (255, 0, 0), 2) cv2.imshow('Faces', image) cv2.waitKey(0) cv2.destroyAllWindows()
The rectangle's bottom-right corner is at (x + w, y + h), which marks the face boundary.
Fill all three blanks to create a dictionary of face bounding boxes with keys as face IDs.
faces_dict = {f'face_[1]': (x, y, [2], [3]) for [1], (x, y, w, h) in enumerate(facedetected)}Use i from enumerate for keys, and w, h for width and height values.