Skip to content

Commit

Permalink
feat(optical_flow): add stitching optical flow example
Browse files Browse the repository at this point in the history
  • Loading branch information
AmitMY committed Jun 12, 2024
1 parent 38c3ce8 commit 75d1738
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
Binary file added assets/example/optical_flow.pdf
Binary file not shown.
34 changes: 34 additions & 0 deletions pose_anonymization/evaluate_example_stitching.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
from pathlib import Path

from matplotlib import pyplot as plt
from pose_format import Pose
from pose_format.numpy.representation.distance import DistanceRepresentation
from pose_format.utils.optical_flow import OpticalFlowCalculator
from spoken_to_signed.gloss_to_pose.concatenate import concatenate_poses

plt.rcParams["font.family"] = "Times New Roman"
plt.rcParams["font.size"] = 13

example_dir = Path(__file__).parent.parent / "assets" / "example"

fig = plt.figure(figsize=(8, 2))

for directory in [example_dir / "original", example_dir / "anonymized"]:
poses = []
for word in ["kleine", "kinder", "essen", "pizza"]:
with open(directory / f"{word}.pose", 'rb') as pose_file:
poses.append(Pose.read(pose_file.read()))

concatenated = concatenate_poses(poses).get_components(["FACE_LANDMARKS"])
calculator = OpticalFlowCalculator(fps=30, distance=DistanceRepresentation())
flow = calculator(concatenated.body.data).sum(-1).squeeze()

# Plot the flow on the main plot, (173, 1)
plt.plot(flow, label=directory.name.capitalize())

plt.yticks([])
plt.legend(loc='upper left')
plt.ylabel("Optical Flow")
plt.tight_layout()
fig.show()
fig.savefig(example_dir / "optical_flow.pdf")

0 comments on commit 75d1738

Please sign in to comment.