Advertisement
ridwan100

exr2mat

Dec 30th, 2023
808
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.95 KB | None | 0 0
  1. import sys
  2. import cv2
  3. import numpy as np
  4. from hdf5storage import savemat
  5. import os
  6.  
  7. # Set the environment variable to enable OpenEXR codec
  8. os.environ["OPENCV_IO_ENABLE_OPENEXR"] = "1"
  9.  
  10. rridx = sys.argv[-1]
  11.  
  12. def saveasmat(file_path, dst_path):
  13.     img = cv2.imread(file_path, cv2.IMREAD_ANYDEPTH | cv2.IMREAD_UNCHANGED)
  14.     savemat(dst_path, {'uv': img})
  15.  
  16. import multiprocessing
  17. pool = multiprocessing.Pool(processes=2)
  18.  
  19. src_dir = '../uv/{}/'.format(rridx)
  20. dst_dir = '../uvmat/{}/'.format(rridx)
  21.  
  22. if not os.path.exists(dst_dir):
  23.     os.makedirs(dst_dir)
  24.  
  25. for fname in os.listdir(src_dir):
  26.     if '.exr' in fname:
  27.         file_name = os.path.join(src_dir, fname)
  28.         if not os.path.isfile(file_name):
  29.             continue
  30.         t = dst_dir
  31.         if not os.path.exists(t):
  32.             os.makedirs(t)
  33.         dst_name = os.path.join(t, fname[:-4])
  34.         pool.apply_async(saveasmat, (file_name, dst_name))
  35.  
  36. pool.close()
  37. pool.join()
  38.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement