Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the eye cascade file instead of the face cascade.
Using a non-existent or incorrect file name.
✗ Incorrect
The correct file name for the default Haar cascade face detector is "haarcascade_frontalface_default.xml".
2fill in blank
mediumComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a non-existent function like convertColor or toGray.
Forgetting to convert to grayscale before detection.
✗ Incorrect
The OpenCV function to convert color spaces is cvtColor.
3fill in blank
hardFix 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'
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.
✗ Incorrect
The correct method to detect objects in Haar cascades is detectMultiScale.
4fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using green color instead of blue.
Using thickness 4 which is thicker than needed.
✗ Incorrect
Blue color in BGR is (255, 0, 0) and thickness 2 is standard for drawing rectangles.
5fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using imwrite instead of imread to load images.
Using wrong method names for detection or display.
✗ Incorrect
imread loads the image, detectMultiScale detects faces, and imshow displays the image window.