Spaces:
Runtime error
Runtime error
File size: 1,757 Bytes
c8f49a6 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
import pandas as pd
import numpy as np
import cv2
def extract_landmarks(image, mp_pose, cols):
pre_list = []
with mp_pose.Pose(static_image_mode=True, enable_segmentation=True) as pose:
result = pose.process(
cv2.cvtColor(image, cv2.COLOR_BGR2RGB))
try:
# xy = bounding_box(result.pose_landmarks.landmark)
for landmark in result.pose_landmarks.landmark:
pre_list.append(landmark)
predict = True
except AttributeError:
return True, pd.DataFrame(), None
if predict == True:
gen1116 = np.array([
[
pre_list[m].x,
pre_list[m].y,
pre_list[m].z,
pre_list[m].visibility
] for m in range(11, 17)
]).flatten().tolist()
gen2333 = np.array([
[
pre_list[m].x,
pre_list[m].y,
pre_list[m].z,
pre_list[m].visibility
] for m in range(23, 33)
]).flatten().tolist()
gen1116.extend(gen2333)
all_list = [
pre_list[0].x,
pre_list[0].y,
pre_list[0].z,
pre_list[0].visibility,
]
all_list.extend(gen1116)
return False, pd.DataFrame([all_list], columns=cols), result.pose_landmarks
# def bounding_box(landmarks):
# w = 1280
# h = 720
# xy = [0, 0, w, h]
# for landmark in landmarks:
# x, y = int(landmark.x * w), int(landmark.y * h)
# if x > xy[0]:
# xy[0] = x
# if x < xy[2]:
# xy[2] = x
# if y > xy[1]:
# xy[1] = y
# if y < xy[3]:
# xy[3] = y
# return xy
|