-
Notifications
You must be signed in to change notification settings - Fork 27
Add AlphaPose WholeBody-133 JSON to pose-format conversion CLI #191
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
GerrySant
wants to merge
1
commit into
sign-language-processing:master
Choose a base branch
from
GerrySant:add-alphapose-json-support
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+398
−0
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.