Add photo_stitcher/src/photo_stitcher/cli.py
This commit is contained in:
parent
7d87c67008
commit
acc7424738
1 changed files with 59 additions and 0 deletions
59
photo_stitcher/src/photo_stitcher/cli.py
Normal file
59
photo_stitcher/src/photo_stitcher/cli.py
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
import argparse
|
||||
import sys
|
||||
from pathlib import Path
|
||||
from typing import List
|
||||
from photo_stitcher.core import combine_images
|
||||
|
||||
|
||||
def _parse_arguments(argv: List[str] | None = None) -> argparse.Namespace:
|
||||
"""Parses command line arguments for the Photo Stitcher CLI."""
|
||||
parser = argparse.ArgumentParser(
|
||||
description="Kombiniert mehrere Einzelbilder zu einem Gesamtbild (Langzeitbelichtung)."
|
||||
)
|
||||
parser.add_argument(
|
||||
"--input",
|
||||
required=True,
|
||||
help="Pfad oder Muster der zu kombinierenden Eingabebilder (z.B. 'input/*.jpg')."
|
||||
)
|
||||
parser.add_argument(
|
||||
"--output",
|
||||
required=True,
|
||||
help="Pfad der Ausgabedatei (z.B. 'output/combined_result.tif')."
|
||||
)
|
||||
|
||||
return parser.parse_args(argv)
|
||||
|
||||
|
||||
def _validate_paths(input_pattern: str, output_path: str) -> list[str]:
|
||||
"""Überprüft Eingabe- und Ausgabepfade und gibt eine Liste gültiger Eingabedateien zurück."""
|
||||
image_paths = sorted(Path().glob(input_pattern))
|
||||
if not image_paths:
|
||||
raise FileNotFoundError(f"Keine Eingabedateien gefunden für Muster: {input_pattern}")
|
||||
|
||||
output_dir = Path(output_path).parent
|
||||
if not output_dir.exists():
|
||||
output_dir.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
return [str(p) for p in image_paths]
|
||||
|
||||
|
||||
def main(argv: List[str] | None = None) -> None:
|
||||
"""CLI-Einstiegspunkt für das Kombinieren von Bildern."""
|
||||
args = _parse_arguments(argv)
|
||||
|
||||
try:
|
||||
image_list = _validate_paths(args.input, args.output)
|
||||
except FileNotFoundError as e:
|
||||
sys.stderr.write(f"[Fehler] {e}\n")
|
||||
sys.exit(1)
|
||||
|
||||
try:
|
||||
combine_images(image_list=image_list, output_file=args.output)
|
||||
print(f"[OK] Bild erfolgreich kombiniert und gespeichert unter: {args.output}")
|
||||
except Exception as e:
|
||||
sys.stderr.write(f"[Fehler] Kombination fehlgeschlagen: {e}\n")
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Loading…
Reference in a new issue