jp4_batch_convert_eyesis4pi.py 1.13 KB
Newer Older
Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
1 2
#!/usr/bin/env python3

3 4 5 6 7 8 9 10 11 12 13
'''
SPDX-License-Identifier: GPL-3.0-or-later
Copyright (c) 2020, Elphel, Inc.

Author:      Oleg Dzhimiev <oleg@elphel.com>
Description: Converts composite jp4 images from Eyesis4Pi-like camera or
             camera with mux. A "composite" image consists of 2-3 images stacked
             vertically.
             Scans all images in src-dir and puts results to dst-dir.
'''

Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
from jp4_composite import JP4_C
#import cv2
import numpy as np
import sys
from PIL import Image, ImageOps
import os

try:
  src = sys.argv[1]
except IndexError:
  src = "."

try:
  dst = sys.argv[2]
except IndexError:
  dst = "."

lst = os.listdir(src)
lst.sort()

for f in lst:

  path = os.path.join(src,f)
  if os.path.isfile(path):
    print("Converting "+f)
    img = JP4_C(path)
    #print(img.exif.toString())
    #print(img.exif.data['Model'])
    img.deblock()
    img.demosaic_bilinear()
44
    img.saturation()
Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
45

46 47
    subs = img.extract_subframes()
    for i in range(len(subs)):
Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
48
      #subs[i].save(os.path.join("../res",img.basename+"_"+str(img.subnames[i])+".png"))
49
      subs[i].save(os.path.join(dst,img.basename+"_"+str(img.subnames[i])+".jpeg"))