0
0
Computer Visionml~10 mins

Haar cascade face detection in Computer Vision - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to load the Haar cascade classifier for face detection.

Computer Vision
face_cascade = cv2.CascadeClassifier([1])
Drag options to blanks, or click blank then click option'
A"haarcascade_frontalface_default.xml"
B"face_detector.xml"
C"face_cascade.xml"
D"haarcascade_eye.xml"
Attempts:
3 left
💡 Hint
Common Mistakes
Using the eye cascade file instead of the face cascade.
Using a non-existent or incorrect file name.
2fill in blank
medium

Complete the code to convert the input image to grayscale before detection.

Computer Vision
gray = cv2.[1](img, cv2.COLOR_BGR2GRAY)
Drag options to blanks, or click blank then click option'
AtoGray
BconvertColor
CcvtColor
DchangeColor
Attempts:
3 left
💡 Hint
Common Mistakes
Using a non-existent function like convertColor or toGray.
Forgetting to convert to grayscale before detection.
3fill in blank
hard

Fix the error in the code to detect faces using the cascade classifier.

Computer Vision
faces = face_cascade.[1](gray, scaleFactor=1.1, minNeighbors=5)
Drag options to blanks, or click blank then click option'
AdetectFaces
BdetectMultiScale
CfindFaces
DdetectObjects
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect method names like detectFaces or findFaces.
Calling a method that does not exist on the cascade object.
4fill in blank
hard

Fill both blanks to draw rectangles around detected faces with a blue color and thickness 2.

Computer Vision
for (x, y, w, h) in faces:
    cv2.rectangle(img, (x, y), (x + w, y + h), [1], [2])
Drag options to blanks, or click blank then click option'
A(255, 0, 0)
B2
C(0, 255, 0)
D4
Attempts:
3 left
💡 Hint
Common Mistakes
Using green color instead of blue.
Using thickness 4 which is thicker than needed.
5fill in blank
hard

Fill all three blanks to complete the code that loads an image, detects faces, and shows the result window.

Computer Vision
img = cv2.[1]('test.jpg')
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
faces = face_cascade.[2](gray)
cv2.[3]('Faces', img)
cv2.waitKey(0)
cv2.destroyAllWindows()
Drag options to blanks, or click blank then click option'
Aimread
BdetectMultiScale
Cimshow
Dimwrite
Attempts:
3 left
💡 Hint
Common Mistakes
Using imwrite instead of imread to load images.
Using wrong method names for detection or display.