Skip to content

Commit

Permalink
feat(pose_body): allow read based on time, not frames
Browse files Browse the repository at this point in the history
  • Loading branch information
AmitMY committed Oct 18, 2024
1 parent 09efe56 commit f984eb9
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
.idea/
.idea/
.DS_Store
1 change: 1 addition & 0 deletions src/js/pose_viewer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"name": "pose-viewer",
"version": "0.10.0",
"description": "Stencil Component Starter",
"homepage": "https://github.com/sign-language-processing/pose",
"main": "dist/index.cjs.js",
"module": "dist/index.js",
"es2015": "dist/esm/index.mjs",
Expand Down
18 changes: 18 additions & 0 deletions src/python/pose_format/pose_body.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from typing import BinaryIO, List, Tuple

import numpy as np
import math

from pose_format.pose_header import PoseHeader
from pose_format.utils.reader import BufferReader, ConstStructs
Expand Down Expand Up @@ -192,6 +193,8 @@ def read_v0_2(cls,
reader: BufferReader,
start_frame: int = None,
end_frame: int = None,
start_time: int = None,
end_time: int = None,
**unused_kwargs) -> "PoseBody":
"""
Reads pose data for version 0.2 from a buffer.
Expand All @@ -206,6 +209,10 @@ def read_v0_2(cls,
Index of the first frame to read. Default is None.
end_frame : int, optional
Index of the last frame to read. Default is None.
start_time : int, optional
Start time of the pose data (in milliseconds). Default is None.
end_time : int, optional
End time of the pose data (in milliseconds). Default is None.
**unused_kwargs : dict
Unused additional parameters for this version.
Expand All @@ -214,13 +221,24 @@ def read_v0_2(cls,
PoseBody
PoseBody object initialized with the read data for version 0.2.
"""

if start_time is not None and start_frame is not None:
raise ValueError("Cannot specify both start_time and start_frame")
if end_time is not None and end_frame is not None:
raise ValueError("Cannot specify both end_time and end_frame")

fps = reader.unpack(ConstStructs.float) # Changed from v0.1, uint -> float
_frames = reader.unpack(ConstStructs.uint) # Changed from v0.1, ushort -> uint

_people = reader.unpack(ConstStructs.ushort)
_points = sum([len(c.points) for c in header.components])
_dims = header.num_dims()

if start_time is not None:
start_frame = math.floor(start_time / 1000 * fps)
if end_time is not None:
end_frame = math.ceil(end_time / 1000 * fps)

data = cls.read_v0_1_frames(_frames, (_people, _points, _dims), reader, start_frame, end_frame)
confidence = cls.read_v0_1_frames(_frames, (_people, _points), reader, start_frame, end_frame)

Expand Down

0 comments on commit f984eb9

Please sign in to comment.