Skip to content
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

feat: add CLI tool for visualization #91

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
20 changes: 16 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

[project]
name = "t4-devkit"
version = "0.0.8"
Expand Down Expand Up @@ -30,6 +26,22 @@ dev = [
"ruff>=0.8",
]

[tool.uv.sources]
t4-devkit-cli = { workspace = true }

[tool.uv.workspace]
members = ["t4-devkit-cli"]

[tool.hatch.build.targets.wheel]
packages = ["t4-devkit-cli"]

[project.scripts]
t4viz = "t4_devkit_cli.visualize:main"

[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

[tool.ruff]
line-length = 100

Expand Down
47 changes: 47 additions & 0 deletions t4_devkit_cli/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Command Line Tools for T4 Dataset

Following command line tools are supported:

- `t4viz`: Visualize T4 dataset features.

## `t4viz`

### Visualize a Scene

```shell
# [...] is optional arguments
t4viz scene <DATA_ROOT> [-o <OUTPUT_DIR> --no-show]
```

Arguments

- `<DATA_ROOT>`: Root directory path to T4 dataset.
- `-o <OUTPUT_DIR>`: Directory path to save recording `.rrd` file.
- `--no-show`: Indicates whether not to show viewer.

### Visualize a Specific Instance

```shell
# [...] is optional arguments
t4viz instance <DATA_ROOT> <INSTANCE_TOKEN> [-o <OUTPUT_DIR> --no-show]
```

Arguments

- `<DATA_ROOT>`: Root directory path to T4 dataset.
- `<INSTANCE_TOKEN>`: Unique identifier token of an instance record.
- `-o <OUTPUT_DIR>`: Directory path to save recording `.rrd` file.
- `--no-show`: Indicates whether not to show viewer.

### Visualize PointCloud

```shell
# [...] is optional arguments
t4viz pointcloud <DATA_ROOT> [--distortion -o <OUTPUT_DIR> --no-show]
```

- `<DATA_ROOT>`: Root directory path to T4 dataset.
- `<INSTANCE_TOKEN>`: Unique identifier token of an instance record.
- `--distortion`: Indicates whether not to ignore camera distortion.
- `-o <OUTPUT_DIR>`: Directory path to save recording `.rrd` file.
- `--no-show`: Indicates whether not to show viewer.
6 changes: 6 additions & 0 deletions t4_devkit_cli/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
def main():
print("Hello from t4cli!")


if __name__ == "__main__":
main()
14 changes: 14 additions & 0 deletions t4_devkit_cli/common.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from __future__ import annotations

import os


def create_dir(dir_path: str | None) -> None:
"""Create a directory with the specified path.
If the input path is `None` this function does nothing.

Args:
dir_path (str | None): Directory path to create.
"""
if dir_path is not None:
os.makedirs(dir_path, exist_ok=True)
17 changes: 17 additions & 0 deletions t4_devkit_cli/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[project]
name = "t4-devkit-cli"
version = "0.1.0"
description = "Command line tools for T4 dataset using t4-devkit."
readme = "README.md"
requires-python = ">=3.10, <3.13"
dependencies = ["click>=8.1.8"]

[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

[tool.ruff]
line-length = 100

[tool.ruff.lint.isort]
required-imports = ["from __future__ import annotations"]
77 changes: 77 additions & 0 deletions t4_devkit_cli/visualize.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
from __future__ import annotations

import click

from t4_devkit import Tier4

from .common import create_dir


@click.group(invoke_without_command=True)
@click.pass_context
def main(ctx: click.Context) -> None:
if ctx.invoked_subcommand is None:
print(ctx.get_help())
else:
ctx.invoked_subcommand


@main.command(name="scene", help="Visualize a specific scene.")
@click.argument("data_root", type=click.Path(exists=True))
@click.option(
"-o",
"--output",
type=click.Path(writable=True),
help="Output directory to save recoding .rrd file.",
)
@click.option("--no-show", is_flag=True, help="Indicates whether not to show viewer.")
def scene(data_root: str, output: str | None, no_show: bool) -> None:
create_dir(output)

t4 = Tier4("annotation", data_root, verbose=False)
scene_token = t4.scene[0].token
t4.render_scene(scene_token, save_dir=output, show=not no_show)


@main.command(name="instance", help="Visualize a particular instance in a corresponding scene")
@click.argument("data_root", type=click.Path(exists=True))
@click.argument("instance", type=click.STRING)
@click.option(
"-o",
"--output",
type=click.Path(writable=True),
help="Output directory to save recoding .rrd file.",
)
@click.option("--no-show", is_flag=True, help="Indicates whether not to show viewer.")
def instance(data_root: str, instance: str, output: str | None, no_show: bool) -> None:
create_dir(output)

t4 = Tier4("annotation", data_root, verbose=False)
t4.render_instance(instance_token=instance, save_dir=output, show=not no_show)


@main.command(name="pointcloud", help="Visualize pointcloud in a corresponding scene.")
@click.argument("data_root", type=click.Path(exists=True))
@click.option(
"--distortion",
is_flag=True,
help="Indicates whether not to ignore camera distortion.",
)
@click.option(
"-o",
"--output",
type=click.Path(writable=True),
help="Output directory to save recoding .rrd file.",
)
@click.option("--no-show", is_flag=True, help="Indicates whether not to show viewer.")
def pointcloud(data_root: str, distortion: bool, output: str | None, no_show: bool) -> None:
create_dir(output)

t4 = Tier4("annotation", data_root, verbose=False)
scene_token = t4.scene[0].token
t4.render_pointcloud(
scene_token,
ignore_distortion=not distortion,
save_dir=output,
show=not no_show,
)
Loading