Skip to content

Commit

Permalink
Merge branch 'sign-language-processing:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
cleong110 authored Nov 8, 2024
2 parents e7e1e84 + 4af357c commit 6cc32c0
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 13 deletions.
10 changes: 3 additions & 7 deletions src/python/pose_format/bin/pose_visualizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,20 @@
import argparse
import os

import numpy as np
from pose_format import Pose
from pose_format.pose_visualizer import PoseVisualizer
from pose_format.utils.generic import pose_normalization_info

from pose_format.utils.generic import normalize_pose_size


def visualize_pose(pose_path: str, video_path: str, normalize=False):
with open(pose_path, "rb") as f:
pose = Pose.read(f.read())

if normalize:
pose = pose.normalize(pose_normalization_info(pose.header))

new_width = 500
shift = 1.25
shift_vec = np.full(shape=(pose.body.data.shape[-1]), fill_value=shift, dtype=np.float32)
pose.body.data = (pose.body.data + shift_vec) * new_width
pose.header.dimensions.height = pose.header.dimensions.width = int(new_width * shift * 2)
normalize_pose_size(pose)

v = PoseVisualizer(pose)

Expand Down
2 changes: 1 addition & 1 deletion src/python/pose_format/pose_visualizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def _draw_frame(self, frame: ma.MaskedArray, frame_confidence: np.ndarray, img,
thickness = self.thickness
if self.thickness is None:
thickness = round(math.sqrt(img.shape[0] * img.shape[1]) / 150)
radius = round(thickness / 2)
radius = math.ceil(thickness / 2)

draw_operations = []

Expand Down
8 changes: 8 additions & 0 deletions src/python/pose_format/utils/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@
from pose_format.utils.openpose import OpenPose_Components


def normalize_pose_size(pose: Pose, target_width: int = 512):
shift = 1.25
shoulder_width = (target_width / shift) / 2
shift_vec = np.full(shape=(pose.body.data.shape[-1]), fill_value=shift, dtype=np.float32)
pose.body.data = (pose.body.data + shift_vec) * shoulder_width
pose.header.dimensions.height = pose.header.dimensions.width = target_width


def pose_hide_legs(pose: Pose):
if pose.header.components[0].name == "POSE_LANDMARKS":
point_names = ["KNEE", "ANKLE", "HEEL", "FOOT_INDEX"]
Expand Down
11 changes: 7 additions & 4 deletions src/python/pose_format/utils/pose_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,10 +221,13 @@ def convert_pose(pose: Pose, pose_components: List[PoseHeaderComponent]) -> Pose
dims = min(len(pose_header.components[0].format), len(pose.header.components[0].format)) - 1
for (c1, p1), (c2, p2) in mapping.items():
p2 = tuple([p2]) if isinstance(p2, str) else p2
p2s = [pose.header._get_point_index(c2, p) for p in list(p2)]
p1_index = pose_header._get_point_index(c1, p1)
data[:, :, p1_index, :dims] = pose.body.data[:, :, p2s, :dims].mean(axis=2)
conf[:, :, p1_index] = pose.body.confidence[:, :, p2s].mean(axis=2)
try:
p2s = [pose.header._get_point_index(c2, p) for p in list(p2)]
p1_index = pose_header._get_point_index(c1, p1)
data[:, :, p1_index, :dims] = pose.body.data[:, :, p2s, :dims].mean(axis=2)
conf[:, :, p1_index] = pose.body.confidence[:, :, p2s].mean(axis=2)
except Exception as e:
print(f"Error in mapping {c1} {p1} to {c2} {p2}: {e}")

pose_body = NumPyPoseBody(fps=pose.body.fps, data=data, confidence=conf)

Expand Down
2 changes: 1 addition & 1 deletion src/python/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[project]
name = "pose_format"
description = "Library for viewing, augmenting, and handling .pose files"
version = "0.6.2"
version = "0.7.0"
keywords = ["Pose Files", "Pose Interpolation", "Pose Augmentation"]
authors = [
{ name = "Amit Moryossef", email = "amitmoryossef@gmail.com" },
Expand Down

0 comments on commit 6cc32c0

Please sign in to comment.