Rassibassi / mediapipeDemos

Real-time Python demos of google mediapipe
127 stars 38 forks source link

Iris.py video and static file processing #1

Open DimIsaev opened 3 years ago

DimIsaev commented 3 years ago

thanks for the simple Python implementation

plan to do video and static file processing?

Rassibassi commented 3 years ago

hej,

sure, see the updated iris.py. Now you can call it with a -i flag to the inputfile:

python iris.py -i /path/to/some/file/i-am-a-video-file.mp4

for static something like this

import cv2
import mediapipe as mp
import numpy as np
from PIL import Image

mp_face_mesh = mp.solutions.face_mesh

frame = cv2.imread("/path_to_image/something.png")
cv2_im_rgb = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
frame_rgb = np.asarray(Image.fromarray(cv2_im_rgb), dtype=np.uint8)

with mp_face_mesh.FaceMesh(
    static_image_mode=True, min_detection_confidence=0.5, min_tracking_confidence=0.5
) as face_mesh:

    results = face_mesh.process(frame_rgb)
    multi_face_landmarks = results.multi_face_landmarks

    if multi_face_landmarks:
        pass
        # now add the processing steps from iris.py
        #
        # ...
        # ...