Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,22 @@ directory = "/path/to/holistic/directory"
pose = load_MediaPipe_directory(directory, fps=24, width=1000, height=1000)
```

#### 7. Conversion from JSON poses to `.pose` format

The library supports converting pose estimation outputs stored as `.json` files into the `.pose` format via `json_to_pose` utility.

> **Note**
> - At the moment, `json_to_pose` only supports [AlphaPose](https://github.com/MVIG-SJTU/AlphaPose) models with **133 keypoints** JSON files with 133 keypoints.
Copy link

Copilot AI Jan 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplicated text in the README: "JSON files with 133 keypoints" appears twice in the same sentence.

Suggested change
> - At the moment, `json_to_pose` only supports [AlphaPose](https://github.com/MVIG-SJTU/AlphaPose) models with **133 keypoints** JSON files with 133 keypoints.
> - At the moment, `json_to_pose` only supports [AlphaPose](https://github.com/MVIG-SJTU/AlphaPose) models whose JSON outputs contain **133 keypoints**.

Copilot uses AI. Check for mistakes.
> - Metadata such as FPS, width, and height can be automatically extracted from the original RGB video if provided.

**Example usage:**

```bash
json_to_pose -i alphapose.json -o alphapose.pose --format alphapose
json_to_pose -i alphapose.json -o alphapose.pose --original-video video.mp4 --format alphapose
```


### Running Tests:

To ensure the integrity of the toolkit, you can run tests using Bazel:
Expand Down
80 changes: 80 additions & 0 deletions src/python/pose_format/bin/json_to_pose.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#!/usr/bin/env python
import argparse
import os

from simple_video_utils.metadata import video_metadata
from simple_video_utils.frames import read_frames_exact
from pose_format.utils.alphapose import load_alphapose_wholebody_from_json
from typing import Optional

def json_to_pose(
input_path: str,
output_path: str,
original_video_path: Optional[str],
format: str):
"""
Render pose visualization over a video.

Parameters
----------
input_path : str
Path to the input .json file.
output_path : str
Path where the output .pose file will be saved.
original_video_path : str or None, optional
Path to the original RGB video to obtain metadata.
If None, it first check if the .json file already contains the metadata, otherwise use the default values.
"""

kwargs = {}
if original_video_path is not None:
# Load video metadata
print('Obtaining metadata from video ...')
metadata = video_metadata(original_video_path)
kwargs["fps"] = metadata.fps
kwargs["width"] = metadata.width
kwargs["height"] = metadata.height

# Perform pose estimation
print('Converting .json to .pose pose-format ...')
if format == 'alphapose':
pose = load_alphapose_wholebody_from_json(
input_path=input_path,
**kwargs # only includes keys if video metadata was found
)
else:
raise NotImplementedError(f'Pose format {format} not supported')

# Write
print('Saving to disk ...')
with open(output_path, "wb") as f:
pose.write(f)

def main():
parser = argparse.ArgumentParser()
parser.add_argument('-i', required=True, type=str, help='Path to the input .json file.')
parser.add_argument('-o', required=True, type=str, help='Path where the output .pose file will be saved.')
parser.add_argument(
'--original-video',
type=str,
default=None,
help=(
"Path to the original RGB video used for metadata extraction. "
"If None, metadata is taken from the JSON file if available, "
"otherwise default width/height/FPS values are used."
)
)
parser.add_argument('--format',
choices=['alphapose'],
default='alphapose',
type=str,
help='orignal type of the .json pose estimation')
args = parser.parse_args()

if not os.path.exists(args.i):
raise FileNotFoundError(f"Video file {args.i} not found")

json_to_pose(args.i, args.o, args.original_video, args.format)

# pip install . && json_to_pose -i alphapose.json -o alphapose.pose --format alphapose
# pip install . && json_to_pose -i alphapose.json -o alphapose.pose --original-video video.mp4 --format alphapose
Loading
Loading