Commit ef221954 authored by Gihan Jayatilaka's avatar Gihan Jayatilaka

jpg

parent 45a277f0
import numpy as np
import sys
import cv2
if __name__ == '__main__':
print("python jpgToMp4.py ./video/image 12 10012 labels.npz 10 10 saveVid.mp4 saveY.npz")
print("python argv[0] argv[1] [2] [3] [4] [5] [6] [7] [8]")
PREFIX=sys.argv[1]
START_NO=int(sys.argv[2])
END_NO=int(sys.argv[3])
NO_FRAMES=END_NO-START_NO+1
Y_NPZ=sys.argv[4]
CELLS_X=int(sys.argv[5])
CELLS_Y=int(sys.argv[6])
OUTPUT_MP4=sys.argv[7]
OUTPUT_NPZ=sys.argv[8]
H=1080
W=1920
# X=np.ndarray(shape=(NO_FRAMES,H,W,3),dtype=np.uint8)
Y=np.load(Y_NPZ)#[Y_VAR]
Y=Y[:NO_FRAMES,:CELLS_X,:CELLS_Y]
for j in range(len(Y)):
Y[j,:,:]=np.transpose(Y[j,:,:])
Y=np.reshape(Y,newshape=(Y.shape[0],Y.shape[1]*Y.shape[2]))
np.savez(OUTPUT_NPZ,Y=Y)
Y=None
fourcc = cv2.VideoWriter_fourcc(*'XVID')
vidOut = cv2.VideoWriter(OUTPUT_MP4, fourcc, 60, (W,H))
for f in range(NO_FRAMES):
ff=f+START_NO
fileName=PREFIX+"{}".format(ff)+".jpg"
# print("Loading ",fileName)
img=cv2.imread(fileName,cv2.IMREAD_COLOR)
#print("IMG",img.shape,img.dtype)
if img.shape[0]==H:
img=img
else:
img=cv2.resize(img,dsize=(H,W))
vidOut.write(img)
if f%100==0:
print("{} of {} images loaded".format(f+1,NO_FRAMES))
vidOut.release()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment