Skip to content

Commit

Permalink
feat: add CLI tool for visualization
Browse files Browse the repository at this point in the history
Signed-off-by: ktro2828 <[email protected]>
  • Loading branch information
ktro2828 committed Jan 17, 2025
1 parent c7526c0 commit a2c1cc3
Show file tree
Hide file tree
Showing 7 changed files with 215 additions and 23 deletions.
40 changes: 17 additions & 23 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,34 +1,28 @@
[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

[project]
name = "t4-devkit"
version = "0.0.8"
description = "A toolkit to load and operate T4 dataset."
authors = [{ name = "Kotaro Uetake", email = "[email protected]" }]
readme = "README.md"
requires-python = ">=3.10,<3.13"
dependencies = [
"rerun-sdk==0.20.0",
"pyquaternion>=0.9.9",
"matplotlib>=3.9.2",
"shapely<2.0.0",
"pycocotools>=2.0.8",
]
dependencies = []

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

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

[dependency-groups]
dev = [
"pytest>=8.2.2",
"pytest-asyncio>=0.23.7",
"pytest-mock>=3.14.0",
"pytest-cov>=6.0.0",
"lark>=1.1.9",
"mkdocs>=1.6.0",
"mkdocs-material>=9.5.47",
"mkdocstrings[python]>=0.18",
"ruff>=0.8",
]
[tool.hatch.build.targets.wheel]
packages = ["t4-devkit", "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
37 changes: 37 additions & 0 deletions t4_devkit/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
[project]
name = "t4-devkit"
version = "0.0.8"
description = "A toolkit to load and operate T4 dataset."
authors = [{ name = "Kotaro Uetake", email = "[email protected]" }]
readme = "README.md"
requires-python = ">=3.10,<3.13"
dependencies = [
"rerun-sdk==0.20.0",
"pyquaternion>=0.9.9",
"matplotlib>=3.9.2",
"shapely<2.0.0",
"pycocotools>=2.0.8",
]

[dependency-groups]
dev = [
"pytest>=8.2.2",
"pytest-asyncio>=0.23.7",
"pytest-mock>=3.14.0",
"pytest-cov>=6.0.0",
"lark>=1.1.9",
"mkdocs>=1.6.0",
"mkdocs-material>=9.5.47",
"mkdocstrings[python]>=0.18",
"ruff>=0.8",
]

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

[tool.ruff]
line-length = 100

[tool.ruff.lint.isort]
required-imports = ["from __future__ import annotations"]
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", "t4-devkit"]

[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,
)

0 comments on commit a2c1cc3

Please sign in to comment.