jp4_batch_convert.py 1.15 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
'''
SPDX-License-Identifier: GPL-3.0-or-later
Copyright (c) 2020, Elphel, Inc.

Author:      Oleg Dzhimiev <oleg@elphel.com>
Description: Converts jp4 images to jpeg for preview
             Scans all images in src-dir and puts results to dst-dir
'''

Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
12 13 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
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()
42 43 44
    img_arr = img.saturation()
    im = Image.fromarray(img_arr.astype(np.uint8))
    im.save(os.path.join(dst,img.basename+"_"+str(img.subnames)+".jpeg"))
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"))