"No one is harder on a talented person than the person themselves" - Linda Wilkinson ; "Trust your guts and don't follow the herd" ; "Validate direction not destination" ;

April 19, 2022

MediaPiple - Explored

Many interesting examples have been posted in mediapipe. Google Vision library for many vision tasks.

Bookmarking python examples link

  • Mediapipe Objectron provides pre-trained models for shoe, chair, cup and camera
  • Mediapipe pose estimation
  • MediaPipe Face Detection Solution API
  • mediapipe_face_mesh - Face Landmarks

Example Code 



#!pip install mediapipe
#Minor changes from https://colab.research.google.com/drive/1FCxIsJS9i58uAsgsLFqDwFmiPO14Z2Hd
from google.colab import files
uploaded = files.upload()
import cv2
from google.colab.patches import cv2_imshow
import math
import numpy as np
DESIRED_HEIGHT = 480
DESIRED_WIDTH = 480
def resize_and_show(image):
h, w = image.shape[:2]
if h < w:
img = cv2.resize(image, (DESIRED_WIDTH, math.floor(h/(w/DESIRED_WIDTH))))
else:
img = cv2.resize(image, (math.floor(w/(h/DESIRED_HEIGHT)), DESIRED_HEIGHT))
cv2_imshow(img)
# Read images with OpenCV.
images = {name: cv2.imread(name) for name in uploaded.keys()}
# Preview the images.
for name, image in images.items():
print(name)
resize_and_show(image)
import mediapipe as mp
mp_face_mesh = mp.solutions.face_mesh
# Load drawing_utils and drawing_styles
mp_drawing = mp.solutions.drawing_utils
mp_drawing_styles = mp.solutions.drawing_styles
# Run MediaPipe Face Mesh.
with mp_face_mesh.FaceMesh(
static_image_mode=True,
refine_landmarks=True,
max_num_faces=2,
min_detection_confidence=0.5) as face_mesh:
for name, image in images.items():
# Convert the BGR image to RGB and process it with MediaPipe Face Mesh.
results = face_mesh.process(cv2.cvtColor(image, cv2.COLOR_BGR2RGB))
# Draw face landmarks of each face.
print(f'Face landmarks of {name}:')
if not results.multi_face_landmarks:
continue
annotated_image = image.copy()
for face_landmarks in results.multi_face_landmarks:
#use this landmark points for further analysis / other usecases
print(face_landmarks)
print('FACEMESH_IRISES')
print(mp_face_mesh.FACEMESH_IRISES)
print('FACEMESH_TESSELATION')
print(mp_face_mesh.FACEMESH_TESSELATION)
print('FACEMESH_CONTOURS')
print(mp_face_mesh.FACEMESH_CONTOURS)
print(face_landmarks)


Keep Exploring!!!

No comments: