Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to load an image for face recognition.
Computer Vision
import cv2 image = cv2.imread([1]) print(image.shape)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting quotes around the file name
Using a function that does not exist like load() or read()
✗ Incorrect
The cv2.imread function requires the file path as a string, so it must be in quotes.
2fill in blank
mediumComplete the code to convert the image to grayscale for face detection.
Computer Vision
gray_image = cv2.cvtColor(image, [1]) print(gray_image.shape)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using RGB instead of BGR conversion codes
Converting grayscale back to color by mistake
✗ Incorrect
To convert a color image to grayscale, use cv2.COLOR_BGR2GRAY.
3fill in blank
hardFix the error in the face detection code by filling the correct method name.
Computer Vision
face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml') facedetect = face_cascade.[1](gray_image, scaleFactor=1.1, minNeighbors=5) print(len(facedetect))
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect method names that do not exist
Confusing method names with other libraries
✗ Incorrect
The correct method to detect faces using Haar cascades in OpenCV is detectMultiScale.
4fill in blank
hardFill both blanks to create a dictionary of face locations with width and height.
Computer Vision
faces_info = {i: (x, y, [1], [2]) for i, (x, y, w, h) in enumerate(facedetect)}
print(faces_info) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using x or y instead of width and height
Mixing up the order of values
✗ Incorrect
The width and height of each detected face are w and h respectively.
5fill in blank
hardFill all three blanks to draw rectangles around detected faces on the image.
Computer Vision
for (x, y, w, h) in facedetect: cv2.rectangle(image, ([1], [2]), (x + w, y + h), [3], 2) cv2.imshow('Faces', image) cv2.waitKey(0) cv2.destroyAllWindows()
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping x and y coordinates
Using wrong color tuples
✗ Incorrect
The rectangle starts at (x, y) and uses blue color (255, 0, 0) in BGR format.