diff --git a/src/python/tests/data/optical_flow.npy b/src/python/tests/data/optical_flow.npy new file mode 100644 index 0000000..c25b951 Binary files /dev/null and b/src/python/tests/data/optical_flow.npy differ diff --git a/src/python/tests/data/optical_flow.png b/src/python/tests/data/optical_flow.png deleted file mode 100644 index c7536d4..0000000 Binary files a/src/python/tests/data/optical_flow.png and /dev/null differ diff --git a/src/python/tests/optical_flow_test.py b/src/python/tests/optical_flow_test.py index d06f636..62769f3 100644 --- a/src/python/tests/optical_flow_test.py +++ b/src/python/tests/optical_flow_test.py @@ -1,10 +1,9 @@ """ Module for testing optical flow computations. Provides test cases for optical flow computation from pose landmarks data. """ -import tempfile from unittest import TestCase -from matplotlib.testing.compare import compare_images +import numpy as np from pose_format.numpy.representation.distance import DistanceRepresentation from pose_format.pose import Pose @@ -18,13 +17,11 @@ class TestOpticalFlow(TestCase): def test_optical_flow(self): """ - Tests optical flow from pose landmarks data and - visualize the computed flow using a heatmap. - - Compares the generated heatmap with the reference image provided in `data/optical_flow.png` to validate the correctness of the omputed optical flow. - - Raises: - AssertionError: If the computed optical flow visualization does not match the reference image. + Tests optical flow from pose landmarks data against a numeric reference. + + Compares the computed flow with `data/optical_flow.npy`. The reference is + the raw numeric output (not a rendered image), so the test is independent + of matplotlib/freetype rendering differences across environments. """ calculator = OpticalFlowCalculator(fps=30, distance=DistanceRepresentation()) @@ -32,16 +29,9 @@ def test_optical_flow(self): pose = Pose.read(f.read()) pose = pose.get_components(["POSE_LANDMARKS", "RIGHT_HAND_LANDMARKS", "LEFT_HAND_LANDMARKS"]) - flow = calculator(pose.body.data) - flow = flow.squeeze(axis=1) - print(flow.shape) - - # Matplotlib heatmap - import matplotlib.pyplot as plt - plt.imshow(flow.T) - plt.tight_layout() - - fp = tempfile.NamedTemporaryFile() - plt.savefig(fp.name, format='png') + flow = calculator(pose.body.data).squeeze(axis=1) - self.assertTrue(compare_images('tests/data/optical_flow.png', fp.name, 0.001) is None) + expected = np.load('tests/data/optical_flow.npy') + self.assertEqual(flow.shape, expected.shape) + self.assertTrue(np.allclose(flow, expected), + "Computed optical flow does not match the reference.")