0
0
Computer Visionml~10 mins

Face landmark 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 an image using OpenCV.

Computer Vision
import cv2
image = cv2.[1]('face.jpg')
Drag options to blanks, or click blank then click option'
Aimread
Bimshow
Cimwrite
Dresize
Attempts:
3 left
💡 Hint
Common Mistakes
Using cv2.imshow instead of cv2.imread will cause an error because imshow is for displaying images.
Using cv2.imwrite tries to save an image, not load it.
2fill in blank
medium

Complete the code to convert the image to grayscale for face landmark detection.

Computer Vision
gray = cv2.[1](image, cv2.COLOR_BGR2GRAY)
Drag options to blanks, or click blank then click option'
Aresize
BcvtColor
Cthreshold
Dblur
Attempts:
3 left
💡 Hint
Common Mistakes
Using cv2.resize changes image size, not color.
Using cv2.threshold applies a binary filter, not color conversion.
3fill in blank
hard

Fix the error in loading the pre-trained face landmark model.

Computer Vision
import dlib
predictor = dlib.shape_predictor('[1]')
Drag options to blanks, or click blank then click option'
Ashape_predictor_68_face_landmarks.dat
Bface_detector.xml
Clandmark_model.pkl
Dface_landmark.dat
Attempts:
3 left
💡 Hint
Common Mistakes
Using a file with wrong extension or name will cause file not found or loading errors.
Using face_detector.xml is for face detection, not landmarks.
4fill in blank
hard

Fill both blanks to detect faces and predict landmarks on the grayscale image.

Computer Vision
detector = dlib.get_frontal_face_detector()
faces = detector([1])
for face in faces:
    landmarks = predictor([2], face)
Drag options to blanks, or click blank then click option'
Agray
Bimage
Cgray, 0
Dimage, 0
Attempts:
3 left
💡 Hint
Common Mistakes
Passing the color image to detector causes slower or incorrect detection.
Not passing the second argument 0 to predictor causes errors.
5fill in blank
hard

Fill all three blanks to extract landmark points and store them in a list.

Computer Vision
landmark_points = []
for n in range(0, [1]):
    x = landmarks.part(n).[2]
    y = landmarks.part(n).[3]
    landmark_points.append((x, y))
Drag options to blanks, or click blank then click option'
A68
Bx
Cy
D36
Attempts:
3 left
💡 Hint
Common Mistakes
Using 36 points extracts only eye landmarks, not full face.
Using .part(n).X or .part(n).Y (uppercase) causes attribute errors.