Which of the following best describes what Haar cascade features detect in an image?
Think about how Haar features use simple rectangular shapes to find contrasts.
Haar cascade features detect contrasts between light and dark rectangular regions, which correspond to edges and lines in the image. This helps identify facial structures.
What will be the output of the following Python code snippet using OpenCV's Haar cascade?
import cv2 face_cascade = cv2.CascadeClassifier(cv2.data.haarcascades + 'haarcascade_frontalface_default.xml') img = cv2.imread('group_photo.jpg') gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) faces = face_cascade.detectMultiScale(gray, scaleFactor=1.1, minNeighbors=5) print(len(faces))
Check what the variable faces contains and what len() returns.
The detectMultiScale method returns a list of rectangles for detected faces. Using len(faces) gives the count of faces detected.
You want to detect faces in images with varying sizes and some noise. Which parameter setting for detectMultiScale is best to balance detection accuracy and speed?
Lower scaleFactor means more scales checked, higher minNeighbors means fewer false positives.
A scaleFactor of 1.1 and minNeighbors of 5 is a common balanced choice that detects faces well while reducing false positives and keeping reasonable speed.
Which metric is most appropriate to measure how well a Haar cascade face detector finds all faces without missing any?
Recall measures how many actual faces are detected out of all faces present.
Recall measures the proportion of true faces detected. High recall means few faces are missed, which is important for face detection completeness.
You run this code but it always prints 0 faces detected, even though faces are visible in the image. What is the most likely cause?
import cv2
face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
img = cv2.imread('face.jpg')
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
faces = face_cascade.detectMultiScale(gray)
print(len(faces))Check if the cascade classifier loaded properly before detection.
If the cascade file path is wrong, the classifier is empty and detects no faces. Using cv2.data.haarcascades ensures correct path.