Bird
Raised Fist0
Computer Visionml~10 mins

Face landmark detection in Computer Vision - Interactive Code Practice

Choose your learning style10 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.

Practice

(1/5)
1. What is the main purpose of face landmark detection in computer vision?
easy
A. To detect the presence of multiple faces in an image
B. To classify the face into different age groups
C. To find key points on a face that represent facial features
D. To convert a face image into grayscale

Solution

  1. Step 1: Understand face landmark detection

    Face landmark detection identifies specific points on a face like eyes, nose, and mouth corners.
  2. Step 2: Differentiate from other tasks

    Other tasks like age classification or face detection do not focus on key facial points.
  3. Final Answer:

    To find key points on a face that represent facial features -> Option C
  4. Quick Check:

    Face landmark detection = key facial points [OK]
Hint: Landmark detection means finding facial points, not classifying faces [OK]
Common Mistakes:
  • Confusing face detection with landmark detection
  • Thinking it classifies face attributes like age or emotion
  • Assuming it changes image colors
2. Which of the following is the correct way to load a pre-trained face landmark model using MediaPipe in Python?
easy
A. mp_face_mesh = mp.solutions.face_mesh.FaceMesh()
B. mp_face_mesh = mp.solutions.load_face_mesh()
C. mp_face_mesh = mp.FaceMesh()
D. mp_face_mesh = mp.solutions.face_landmark()

Solution

  1. Step 1: Recall MediaPipe face mesh syntax

    The correct class to load face landmark detection is FaceMesh under mp.solutions.face_mesh.
  2. Step 2: Check each option

    Only mp_face_mesh = mp.solutions.face_mesh.FaceMesh() uses the correct full path and class name.
  3. Final Answer:

    mp_face_mesh = mp.solutions.face_mesh.FaceMesh() -> Option A
  4. Quick Check:

    Correct MediaPipe class = FaceMesh [OK]
Hint: MediaPipe face landmarks use mp.solutions.face_mesh.FaceMesh() [OK]
Common Mistakes:
  • Using incorrect method names like load_face_mesh()
  • Omitting the full module path
  • Using non-existent classes like face_landmark()
3. Given the following code snippet using MediaPipe to detect face landmarks, what will be the output type of results.multi_face_landmarks if a face is detected?
medium
A. A list of face landmark objects
B. A single integer representing number of faces
C. A dictionary with landmark coordinates
D. None

Solution

  1. Step 1: Understand MediaPipe output for face landmarks

    When a face is detected, results.multi_face_landmarks returns a list of landmark objects, one per face.
  2. Step 2: Analyze the options

    Only A list of face landmark objects correctly describes this as a list of face landmark objects.
  3. Final Answer:

    A list of face landmark objects -> Option A
  4. Quick Check:

    Detected faces landmarks = list of objects [OK]
Hint: multi_face_landmarks returns a list, not a number or dict [OK]
Common Mistakes:
  • Thinking it returns a count (integer)
  • Assuming it returns a dictionary
  • Confusing None with detected results
4. You wrote this code to draw face landmarks but get an error: mp_drawing.draw_landmarks(image, results.face_landmarks, mp_face_mesh.FACEMESH_TESSELATION). What is the likely cause?
medium
A. FACEMESH_TESSELATION is misspelled
B. mp_drawing is not imported
C. image must be grayscale
D. results.face_landmarks should be results.multi_face_landmarks[0]

Solution

  1. Step 1: Check results object structure

    MediaPipe stores landmarks in results.multi_face_landmarks as a list, not results.face_landmarks.
  2. Step 2: Correct usage for drawing

    To draw landmarks for the first face, use results.multi_face_landmarks[0].
  3. Final Answer:

    results.face_landmarks should be results.multi_face_landmarks[0] -> Option D
  4. Quick Check:

    Use multi_face_landmarks list for drawing [OK]
Hint: Use multi_face_landmarks[0] to access first face landmarks [OK]
Common Mistakes:
  • Using a non-existent attribute results.face_landmarks
  • Forgetting to import mp_drawing
  • Assuming image must be grayscale
5. You want to build an app that applies virtual glasses on a user's face using face landmark detection. Which landmarks should you primarily use to position the glasses correctly?
hard
A. Landmarks on the lips and chin
B. Landmarks around the eyes and nose bridge
C. Landmarks on the forehead and cheeks
D. Landmarks on the ears and jawline

Solution

  1. Step 1: Identify glasses placement on face

    Glasses rest on the nose bridge and cover the eyes area.
  2. Step 2: Choose landmarks matching these areas

    Landmarks around eyes and nose bridge provide accurate positioning points.
  3. Final Answer:

    Landmarks around the eyes and nose bridge -> Option B
  4. Quick Check:

    Glasses position = eyes + nose bridge landmarks [OK]
Hint: Glasses align with eyes and nose bridge landmarks [OK]
Common Mistakes:
  • Using lip or chin landmarks which are too low
  • Choosing forehead or cheeks which don't fit glasses
  • Selecting ears which are not detected by standard landmarks
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard