I was looking to experiment existence of face, full body but mediapipe does not seem to give accurate results
Example Image #1 (No Foot / Partial Picture)
Detected Coordinates are
Example Image (No Face Present)
Detected Coordinates are
Seems to need to go with custom models :)
Nothing is fool proof
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#https://github.com/google/mediapipe/blob/master/mediapipe/python/solutions/pose_connections.py | |
#https://github.com/google/mediapipe/blob/master/mediapipe/python/solutions/pose.py | |
import cv2 | |
import mediapipe as mp | |
import numpy as np | |
mp_drawing = mp.solutions.drawing_utils | |
mp_drawing_styles = mp.solutions.drawing_styles | |
mp_pose = mp.solutions.pose | |
# For static images: | |
IMAGE_FILES = ['Sample2.jpg'] | |
BG_COLOR = (192, 192, 192) # gray | |
with mp_pose.Pose( | |
static_image_mode=True, | |
model_complexity=2, | |
enable_segmentation=True, | |
min_detection_confidence=0.5) as pose: | |
for idx, file in enumerate(IMAGE_FILES): | |
image = cv2.imread(file) | |
image_height, image_width, _ = image.shape | |
# Convert the BGR image to RGB before processing. | |
results = pose.process(cv2.cvtColor(image, cv2.COLOR_BGR2RGB)) | |
if not results.pose_landmarks: | |
continue | |
print( | |
f'LEFT_EYE coordinates: (' | |
f'{results.pose_landmarks.landmark[mp_pose.PoseLandmark.LEFT_EYE].x * image_width}, ' | |
f'{results.pose_landmarks.landmark[mp_pose.PoseLandmark.LEFT_EYE].y * image_height})' | |
) | |
print( | |
f'RIGHT_EYE coordinates: (' | |
f'{results.pose_landmarks.landmark[mp_pose.PoseLandmark.RIGHT_EYE].x * image_width}, ' | |
f'{results.pose_landmarks.landmark[mp_pose.PoseLandmark.RIGHT_EYE].y * image_height})' | |
) | |
print( | |
f'Nose coordinates: (' | |
f'{results.pose_landmarks.landmark[mp_pose.PoseLandmark.NOSE].x * image_width}, ' | |
f'{results.pose_landmarks.landmark[mp_pose.PoseLandmark.NOSE].y * image_height})' | |
) | |
print( | |
f'LEFT_FOOT_INDEX coordinates: (' | |
f'{results.pose_landmarks.landmark[mp_pose.PoseLandmark.LEFT_FOOT_INDEX].x * image_width}, ' | |
f'{results.pose_landmarks.landmark[mp_pose.PoseLandmark.LEFT_FOOT_INDEX].y * image_height})' | |
) | |
print( | |
f'RIGHT_FOOT_INDEX coordinates: (' | |
f'{results.pose_landmarks.landmark[mp_pose.PoseLandmark.RIGHT_FOOT_INDEX].x * image_width}, ' | |
f'{results.pose_landmarks.landmark[mp_pose.PoseLandmark.RIGHT_FOOT_INDEX].y * image_height})' | |
) | |
print( | |
f'LEFT_SHOULDER coordinates: (' | |
f'{results.pose_landmarks.landmark[mp_pose.PoseLandmark.LEFT_SHOULDER].x * image_width}, ' | |
f'{results.pose_landmarks.landmark[mp_pose.PoseLandmark.LEFT_SHOULDER].y * image_height})' | |
) | |
print( | |
f'RIGHT_SHOULDER coordinates: (' | |
f'{results.pose_landmarks.landmark[mp_pose.PoseLandmark.RIGHT_SHOULDER].x * image_width}, ' | |
f'{results.pose_landmarks.landmark[mp_pose.PoseLandmark.RIGHT_SHOULDER].y * image_height})' | |
) | |
annotated_image = image.copy() | |
# Draw segmentation on the image. | |
# To improve segmentation around boundaries, consider applying a joint | |
# bilateral filter to "results.segmentation_mask" with "image". | |
condition = np.stack((results.segmentation_mask,) * 3, axis=-1) > 0.1 | |
bg_image = np.zeros(image.shape, dtype=np.uint8) | |
bg_image[:] = BG_COLOR | |
annotated_image = np.where(condition, annotated_image, bg_image) | |
# Draw pose landmarks on the image. | |
mp_drawing.draw_landmarks( | |
annotated_image, | |
results.pose_landmarks, | |
mp_pose.POSE_CONNECTIONS, | |
landmark_drawing_spec=mp_drawing_styles.get_default_pose_landmarks_style()) | |
cv2.imwrite('/tmp/annotated_image' + str(idx) + '.png', annotated_image) | |
# Plot pose world landmarks. | |
mp_drawing.plot_landmarks( | |
results.pose_world_landmarks, mp_pose.POSE_CONNECTIONS) |
Keep Exploring!!!
No comments:
Post a Comment