0
0
Computer Visionml~20 mins

Haar cascade face detection in Computer Vision - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Haar Cascade Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Understanding Haar cascade features

Which of the following best describes what Haar cascade features detect in an image?

APatterns of light and dark areas that resemble edges and lines
BColor gradients and textures in the image
CPixel intensity histograms across the entire image
DFrequency components using Fourier transform
Attempts:
2 left
💡 Hint

Think about how Haar features use simple rectangular shapes to find contrasts.

Predict Output
intermediate
2:00remaining
Output of face detection code snippet

What will be the output of the following Python code snippet using OpenCV's Haar cascade?

Computer Vision
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))
AA boolean indicating if any face was detected
BA list of coordinates of detected faces
CThe number of faces detected in the image
DAn error because detectMultiScale requires color image
Attempts:
2 left
💡 Hint

Check what the variable faces contains and what len() returns.

Model Choice
advanced
2:00remaining
Choosing parameters for Haar cascade detection

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?

A<code>scaleFactor=1.05</code>, <code>minNeighbors=3</code>
B<code>scaleFactor=1.1</code>, <code>minNeighbors=5</code>
C<code>scaleFactor=1.5</code>, <code>minNeighbors=10</code>
D<code>scaleFactor=1.3</code>, <code>minNeighbors=1</code>
Attempts:
2 left
💡 Hint

Lower scaleFactor means more scales checked, higher minNeighbors means fewer false positives.

Metrics
advanced
2:00remaining
Evaluating Haar cascade face detector performance

Which metric is most appropriate to measure how well a Haar cascade face detector finds all faces without missing any?

APrecision
BF1-score
CAccuracy
DRecall
Attempts:
2 left
💡 Hint

Recall measures how many actual faces are detected out of all faces present.

🔧 Debug
expert
2:00remaining
Debugging no faces detected error

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))
AThe cascade file path is incorrect, so the classifier is empty
BThe image is not converted to grayscale before detection
CThe detectMultiScale method requires color images, not grayscale
DThe image file 'face.jpg' is corrupted and cannot be read
Attempts:
2 left
💡 Hint

Check if the cascade classifier loaded properly before detection.