-
Notifications
You must be signed in to change notification settings - Fork 25
[WIP] feat(generic): add functions is_left_handed and flip_holistic #95
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
J22Melody
wants to merge
1
commit into
sign-language-processing:master
Choose a base branch
from
J22Melody:flipping
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -190,3 +190,28 @@ def reduce_holistic(pose: Pose) -> Pose: | |
"FACE_LANDMARKS": face_contours, | ||
"POSE_LANDMARKS": body_no_face_no_hands | ||
}) | ||
|
||
|
||
def is_left_handed(pose: Pose) -> bool: | ||
left_hand = pose.get_components(["LEFT_HAND_LANDMARKS"]) | ||
right_hand = pose.get_components(["RIGHT_HAND_LANDMARKS"]) | ||
left_hand_variance = np.nan_to_num(left_hand.body.data).var(axis=0).sum() | ||
left_hand_variance = left_hand_variance if left_hand_variance != 'masked' else 0 | ||
right_hand_variance = np.nan_to_num(right_hand.body.data).var(axis=0).sum() | ||
right_hand_variance = right_hand_variance if right_hand_variance != 'masked' else 0 | ||
return left_hand_variance > right_hand_variance | ||
|
||
|
||
def flip_holistic(pose: Pose) -> Pose: | ||
FLIPPED_COMPONENTS = ["POSE_LANDMARKS", "FACE_LANDMARKS", "RIGHT_HAND_LANDMARKS", "LEFT_HAND_LANDMARKS"] | ||
FLIPPED_BODY_POINTS = ['NOSE', 'RIGHT_EYE_INNER', 'RIGHT_EYE', 'RIGHT_EYE_OUTER', 'LEFT_EYE_INNER', 'LEFT_EYE', 'LEFT_EYE_OUTER', 'RIGHT_EAR', 'LEFT_EAR', 'MOUTH_RIGHT', 'MOUTH_LEFT', 'RIGHT_SHOULDER', 'LEFT_SHOULDER', 'RIGHT_ELBOW', 'LEFT_ELBOW', 'RIGHT_WRIST', 'LEFT_WRIST', 'RIGHT_PINKY', 'LEFT_PINKY', 'RIGHT_INDEX', 'LEFT_INDEX', 'RIGHT_THUMB', 'LEFT_THUMB', 'RIGHT_HIP', 'LEFT_HIP', 'RIGHT_KNEE', 'LEFT_KNEE', 'RIGHT_ANKLE', 'LEFT_ANKLE', 'RIGHT_HEEL', 'LEFT_HEEL', 'RIGHT_FOOT_INDEX', 'LEFT_FOOT_INDEX'] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
# face flipping based on https://storage.googleapis.com/mediapipe-assets/documentation/mediapipe_face_landmark_fullsize.png | ||
# CAUTION: works on reduced set of face keypoints (face_contours) only | ||
FLIPPED_FACE_POINTS = ['0', '249', '10', '13', '14', '17', '251', '263', '267', '269', '270', '276', '282', '283', '284', '285', '288', '291', '293', '295', '296', '297', '300', '308', '310', '311', '312', '314', '317', '318', '321', '323', '324', '332', '334', '336', '338', '356', '361', '362', '365', '373', '374', '375', '377', '378', '379', '152', '380', '381', '382', '384', '385', '386', '387', '388', '389', '390', '397', '398', '400', '402', '405', '409', '415', '454', '466', \ | ||
'7', '21', '33', '37', '39', '40', '46', '52', '53', '54', '55', '58', '61', '63', '65', '66', '67', '70', '78', '80', '81', '82', '84', '87', '88', '91', '93', '95', '103', '105', '107', '109', '127', '132', '133', '136', '144', '145', '146', '148', '149', '150', '153', '154', '155', '157', '158', '159', '160', '161', '162', '163', '172', '173', '176', '178', '181', '185', '191', '234', '246'] | ||
body = [p for p in FLIPPED_BODY_POINTS if p in pose.header.components[0].points] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here, first create a component body_component = next(c for c in pose.header.components if c == "POSE_LANDMARKS")
body = [p for p in FLIPPED_BODY_POINTS if p in body_component.points] (same for the face) |
||
face = [p for p in FLIPPED_FACE_POINTS if p in pose.header.components[1].points] | ||
header = pose.header | ||
pose = pose.flip(0).get_components(FLIPPED_COMPONENTS, {"POSE_LANDMARKS": body, "FACE_LANDMARKS": face}) | ||
pose.header = header | ||
return pose |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to be even more generic (assume we don't know the original component ordering):