starmax.py
· 710 B · Python
Raw
import cv2
import numpy as np
import os
import argparse
parser = argparse.ArgumentParser(
description="""Takes in a path to a directory
of images and stacks them into a star trail image."""
)
parser.add_argument("path", help="Path to a directory containing images of stars")
parser.add_argument("--name", help="Name of output file")
args = parser.parse_args()
path = args.path
name = args.name
if name is None:
name = "out.jpg"
im, prev = None, None
for file in os.listdir(path):
if os.path.splitext(file)[1].lower() == ".jpg":
curr = cv2.imread(path + file)
if im is None:
im = curr
else:
im = np.maximum(im, curr)
cv2.imwrite(name, im)
| 1 | import cv2 |
| 2 | import numpy as np |
| 3 | import os |
| 4 | import argparse |
| 5 | |
| 6 | |
| 7 | parser = argparse.ArgumentParser( |
| 8 | description="""Takes in a path to a directory |
| 9 | of images and stacks them into a star trail image.""" |
| 10 | ) |
| 11 | parser.add_argument("path", help="Path to a directory containing images of stars") |
| 12 | |
| 13 | parser.add_argument("--name", help="Name of output file") |
| 14 | |
| 15 | args = parser.parse_args() |
| 16 | path = args.path |
| 17 | name = args.name |
| 18 | |
| 19 | if name is None: |
| 20 | name = "out.jpg" |
| 21 | |
| 22 | im, prev = None, None |
| 23 | for file in os.listdir(path): |
| 24 | if os.path.splitext(file)[1].lower() == ".jpg": |
| 25 | curr = cv2.imread(path + file) |
| 26 | if im is None: |
| 27 | im = curr |
| 28 | else: |
| 29 | im = np.maximum(im, curr) |
| 30 | |
| 31 | cv2.imwrite(name, im) |
| 32 |