Computer Vision News - March 2022

7 MediaPipe Use MediaPipe on Python Installing MediaPipe tools on python can easily be done through pip. python3 -m venv mp_env && source mp_env/bin/activate pip install mediapipe Once the environment is ready, we can import some basic libraries and mediapipe, and we can call the desired pipeline using the following lines. import cv2 import math import numpy as np import mediapipe as mp import glob mp_hands = mp.solutions.hands mp_drawing = mp.solutions.drawing_utils mp_drawing_styles = mp.solutions.drawing_styles help(mp_hands.Hands) Running help on a MediaPipe module can give you useful insight on the class and how to use and modify its parameters. Running help on the hands pipeline gives you the list of parameters that can be modified to your convenience: static_image_mode (to treat the input images as static, rather than a video stream), max_num_hands to set the maximum number of hands to detect, model_complexity (ranging from 0 to 1), min_detection_ confidence and min_tracking_confidence to vary the lower bound confidence for both the hand and landmark detection. The remaining code allows to upload some static images and apply the technique to finally draw hand landmarks on the image itself, print the corresponding coordinates and draw a 3d plot of them. filenames = glob.glob(basedir+”/*.jpg”) # Read images with OpenCV. images = {name: cv2.imread(name) for name in filenames} # Preview the images. for name, image in images.items(): cv2.imshow(name,image)

RkJQdWJsaXNoZXIy NTc3NzU=