Last active
June 10, 2022 14:06
-
-
Save JackDesBwa/9a9f717d82056fd4473f290d5bafe191 to your computer and use it in GitHub Desktop.
Script to convert (parallel) SBS or MPO image into a SBS image displayable by QooCam EGO device
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
#!/usr/bin/env python3 | |
# Script to convert (parallel) SBS or MPO image into a SBS image displayable by QooCam EGO device | |
# TODO: Add a thumbnail that could be displayed by the device | |
import argparse | |
import os | |
import sys | |
parser = argparse.ArgumentParser(description='SBS to QoocCam EGO') | |
parser.add_argument('files', nargs='+', help='List of files') | |
parser.add_argument('--start -s', dest='start', type=int, default=1, help='First number of the sequence') | |
parser.add_argument('--output --out -o', dest='output', default='out', help='Output directory') | |
args = parser.parse_args() | |
try: | |
from PIL import Image | |
except: | |
print('Pillow library is requiered but not found') | |
exit() | |
os.makedirs(args.output, exist_ok=True) | |
for cnt, f in enumerate(args.files): | |
im = Image.open(f) | |
if getattr(im, "n_frames", 1) == 1: | |
w, h = im.size | |
r = min(8000/w, 3000/h) | |
il = im.resize((round(w//2*r), round(h*r)), box=(0, 0, w//2, h)) | |
ir = im.resize((round(w//2*r), round(h*r)), box=(w//2, 0, w, h)) | |
else: | |
w, h = im.size | |
r = min(4000/w, 3000/h) | |
il = im.resize((round(w*r), round(h*r))) | |
im.seek(1) | |
ir = im.resize((round(w*r), round(h*r))) | |
mw = (4000-ir.size[0])//2 | |
mh = (3000-ir.size[1])//2 | |
exif = im.getexif() | |
exif[0x011a] = 72 | |
exif[0x011b] = 72 | |
im2 = Image.new("RGB", (8000, 3000)) | |
im2.paste(il, (mw, mh)) | |
im2.paste(ir, (mw+4000, mh)) | |
im2.save(f'{args.output}/0000_00000000_{cnt+args.start:06}.jpg', exif=exif) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment