Is working except it isnt opening my camera to get my face cords

Question:

import cv2
import mediapipe as mp
import pyautogui as py
cam = cv2.VideoCapture(0)

face_mesh = mp.solutions.face_mesh.FaceMesh(refine_landmarks=True)
while True:
    _, frame = cam.read()
    frame = cv2.flip(frame, 1)
    '''frameRGB = cv2.cvtColor(frame, cv2.COLOR_RGB2BGR)'''
    output = face_mesh.process(frameRGB)
    face_landmark = output.multi_face_landmarks
    frame_w, frame_h, _ = frame.shape
    '''if face_landmark:
        landmarks = face_landmark[0].landmark
        for landmark in enumerate(landmarks[474:478]):
            x = int(landmark.x * frame_w)
            y = int(landmark.y * frame_h)
            cv2.circle(frame, (x, y), 3, (0, 255, 0))
            if id == 1:
                py.moveTo(x, y)'''

            print(x, y)
    cv2.imshow('Lazy mouse', frame)
    cv2.waitKey(1)

it’s printing where my head is for x, y, isnt showing me a camera with my face I believe it has to do with the frame or with the RGB I tried debugging but no luck, highlighted where I believe are the problems

Asked By: MrBingB0NG

||

Answers:

enumerate() is a Python built-in function that returns a sequence of tuples.

Instead of

for landmark in enumerate(landmarks[474:478]):  # wrong

you should use

for landmark in landmarks[474:478]:

or

for (index, landmark) in enumerate(landmarks[474:478]):

index is the index into the sublist/slice, so you will get indices 0,1,2,3

Answered By: Christoph Rackwitz
Categories: questions Tags:
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.