-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* chore: wip * chore: wip * chore: wip * chore: wip * chore: wip * chore: wip * refactor: refactor a lot * feat: add cli * chore: update deps * test: update test * style: run pre-commit * fix: fix cli and add more tests * docs(readme): update README.md * fix(remapper): fix radius estimation for "max" * chore: fix last commit * fix: backward compatibility * feat(cli): add more commands * docs(readme): update README.md * refactor: shorter name * fix(transformer): remove unnecessary print * feat: add PolynomialScaler * feat: fix PolynomialScaler, add image to the docs
- Loading branch information
Showing
15 changed files
with
1,340 additions
and
50 deletions.
There are no files selected for viewing
This file contains 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 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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 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 |
---|---|---|
@@ -1 +1,32 @@ | ||
__version__ = "0.0.1" | ||
__version__ = "0.0.0" | ||
from .remapper import apply, apply_lr, get_map | ||
from .transformer import ( | ||
DenormalizeTransformer, | ||
EquirectangularEncoder, | ||
Euclidean3DRotator, | ||
Euclidean3DTransformer, | ||
FisheyeDecoder, | ||
FisheyeEncoder, | ||
MultiTransformer, | ||
NormalizeTransformer, | ||
PolarRollTransformer, | ||
TransformerBase, | ||
ZoomTransformer, | ||
) | ||
|
||
__all__ = [ | ||
"TransformerBase", | ||
"ZoomTransformer", | ||
"MultiTransformer", | ||
"NormalizeTransformer", | ||
"PolarRollTransformer", | ||
"DenormalizeTransformer", | ||
"FisheyeDecoder", | ||
"FisheyeEncoder", | ||
"EquirectangularEncoder", | ||
"Euclidean3DRotator", | ||
"Euclidean3DTransformer", | ||
"apply", | ||
"apply_lr", | ||
"get_map", | ||
] |
This file contains 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 |
---|---|---|
@@ -1,12 +1,148 @@ | ||
from enum import auto | ||
from pathlib import Path | ||
|
||
import cv2 as cv | ||
import typer | ||
from rich import print | ||
from quaternion import * # noqa | ||
from strenum import StrEnum | ||
from typing_extensions import Annotated | ||
|
||
from vr180_convert.transformer import * # noqa | ||
from vr180_convert.transformer import EquirectangularEncoder, FisheyeDecoder | ||
|
||
from .main import add | ||
from .remapper import apply, apply_lr | ||
|
||
DEFAULT_EXTENSION = ".png" | ||
|
||
app = typer.Typer() | ||
|
||
|
||
class _InterpolationFlags(StrEnum): | ||
"""Interpolation flags enum for typer.""" | ||
|
||
INTER_NEAREST = auto() | ||
INTER_LINEAR = auto() | ||
INTER_CUBIC = auto() | ||
INTER_AREA = auto() | ||
INTER_LANCZOS4 = auto() | ||
INTER_MAX = auto() | ||
WARP_FILL_OUTLIERS = auto() | ||
WARP_INVERSE_MAP = auto() | ||
|
||
|
||
class _BorderTypes(StrEnum): | ||
"""Border types enum for typer.""" | ||
|
||
BORDER_CONSTANT = auto() | ||
BORDER_REPLICATE = auto() | ||
BORDER_REFLECT = auto() | ||
BORDER_WRAP = auto() | ||
BORDER_REFLECT_101 = auto() | ||
BORDER_TRANSPARENT = auto() | ||
BORDER_ISOLATED = auto() | ||
|
||
|
||
@app.command() | ||
def main(n1: int, n2: int) -> None: | ||
"""Add the arguments and print the result.""" | ||
print(add(n1, n2)) | ||
def lr( | ||
left_path: Annotated[Path, typer.Argument(help="Left image path")], | ||
right_path: Annotated[Path, typer.Argument(help="Right image path")], | ||
transformer: Annotated[ | ||
str, typer.Option(help="Transformer Python code (to be `eval()`ed)") | ||
] = "", | ||
out_path: Annotated[ | ||
Path, | ||
typer.Option( | ||
help="Output image path, defaults to left_path.with_suffix('.out.jpg')" | ||
), | ||
] = Path(""), | ||
size: Annotated[ | ||
str, typer.Option(help="Output image size, defaults to 2048x2048") | ||
] = "2048x2048", | ||
interpolation: Annotated[ | ||
_InterpolationFlags, | ||
typer.Option(help="Interpolation method, defaults to lanczos4"), | ||
] = _InterpolationFlags.INTER_LANCZOS4, # type: ignore | ||
boarder_mode: Annotated[ | ||
_BorderTypes, typer.Option(help="Border mode, defaults to constant") | ||
] = _BorderTypes.BORDER_CONSTANT, # type: ignore | ||
boarder_value: int = 0, | ||
radius: Annotated[ | ||
str, typer.Option(help="Radius of the fisheye image, defaults to 'auto'") | ||
] = "auto", | ||
) -> None: | ||
"""Remap a pair of fisheye images to a pair of SBS equirectangular images.""" | ||
if transformer == "": | ||
transformer_ = EquirectangularEncoder() * FisheyeDecoder("equidistant") | ||
else: | ||
transformer_ = eval(transformer) # noqa | ||
apply_lr( | ||
transformer=transformer_, | ||
left_path=left_path, | ||
right_path=right_path, | ||
out_path=( | ||
Path(left_path).with_suffix(f".out.{DEFAULT_EXTENSION}") | ||
if out_path == Path("") | ||
else out_path | ||
), | ||
radius=float(radius) if radius not in ["auto", "max"] else radius, # type: ignore | ||
size_output=tuple(map(int, size.split("x"))), # type: ignore | ||
interpolation=getattr(cv, interpolation.upper()), | ||
boarder_mode=getattr(cv, boarder_mode.upper()), | ||
boarder_value=boarder_value, | ||
) | ||
|
||
|
||
@app.command() | ||
def s( | ||
in_paths: Annotated[list[Path], typer.Argument(help="Image paths")], | ||
transformer: Annotated[ | ||
str, typer.Option(help="Transformer Python code (to be `eval()`ed)") | ||
] = "", | ||
out_path: Annotated[ | ||
Path, | ||
typer.Option( | ||
help="Output image path, defaults to left_path.with_suffix('.out.jpg')" | ||
), | ||
] = Path(""), | ||
size: Annotated[ | ||
str, typer.Option(help="Output image size, defaults to 2048x2048") | ||
] = "2048x2048", | ||
interpolation: Annotated[ | ||
_InterpolationFlags, | ||
typer.Option(help="Interpolation method, defaults to lanczos4"), | ||
] = _InterpolationFlags.INTER_LANCZOS4, # type: ignore | ||
boarder_mode: Annotated[ | ||
_BorderTypes, typer.Option(help="Border mode, defaults to constant") | ||
] = _BorderTypes.BORDER_CONSTANT, # type: ignore | ||
boarder_value: int = 0, | ||
radius: Annotated[ | ||
str, typer.Option(help="Radius of the fisheye image, defaults to 'auto'") | ||
] = "auto", | ||
) -> None: | ||
"""Remap fisheye images to SBS equirectangular images.""" | ||
if transformer == "": | ||
transformer_ = EquirectangularEncoder() * FisheyeDecoder("equidistant") | ||
else: | ||
transformer_ = eval(transformer) # noqa | ||
|
||
if out_path == Path(""): | ||
out_paths = [p.with_suffix(f".out.{DEFAULT_EXTENSION}") for p in in_paths] | ||
elif out_path.is_dir(): | ||
out_paths = [out_path / p.name for p in in_paths] | ||
else: | ||
if len(in_paths) > 1: | ||
raise ValueError( | ||
"Output path must be a directory when multiple input paths are provided" | ||
) | ||
out_paths = [out_path for p in in_paths] | ||
|
||
apply( | ||
transformer=transformer_, | ||
in_paths=in_paths, | ||
out_paths=out_paths, | ||
radius=float(radius) if radius not in ["auto", "max"] else radius, # type: ignore | ||
size_output=tuple(map(int, size.split("x"))), # type: ignore | ||
interpolation=getattr(cv, interpolation.upper()), | ||
boarder_mode=getattr(cv, boarder_mode.upper()), | ||
boarder_value=boarder_value, | ||
) |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.