Skip to content

Commit 75d1738

Browse files
committed
feat(optical_flow): add stitching optical flow example
1 parent 38c3ce8 commit 75d1738

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

assets/example/optical_flow.pdf

15.9 KB
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
from pathlib import Path
2+
3+
from matplotlib import pyplot as plt
4+
from pose_format import Pose
5+
from pose_format.numpy.representation.distance import DistanceRepresentation
6+
from pose_format.utils.optical_flow import OpticalFlowCalculator
7+
from spoken_to_signed.gloss_to_pose.concatenate import concatenate_poses
8+
9+
plt.rcParams["font.family"] = "Times New Roman"
10+
plt.rcParams["font.size"] = 13
11+
12+
example_dir = Path(__file__).parent.parent / "assets" / "example"
13+
14+
fig = plt.figure(figsize=(8, 2))
15+
16+
for directory in [example_dir / "original", example_dir / "anonymized"]:
17+
poses = []
18+
for word in ["kleine", "kinder", "essen", "pizza"]:
19+
with open(directory / f"{word}.pose", 'rb') as pose_file:
20+
poses.append(Pose.read(pose_file.read()))
21+
22+
concatenated = concatenate_poses(poses).get_components(["FACE_LANDMARKS"])
23+
calculator = OpticalFlowCalculator(fps=30, distance=DistanceRepresentation())
24+
flow = calculator(concatenated.body.data).sum(-1).squeeze()
25+
26+
# Plot the flow on the main plot, (173, 1)
27+
plt.plot(flow, label=directory.name.capitalize())
28+
29+
plt.yticks([])
30+
plt.legend(loc='upper left')
31+
plt.ylabel("Optical Flow")
32+
plt.tight_layout()
33+
fig.show()
34+
fig.savefig(example_dir / "optical_flow.pdf")

0 commit comments

Comments
 (0)