Commit f1cdc033 authored by Gihan Jayatilaka's avatar Gihan Jayatilaka

landmark

parent f3819ab4
'''
This code was written by Gihan during his stay at larc.smu.edu.sg during 2019 Feb-Jul.
He won't be there by the time you are reading this code.
If you find this code in SMU's internal git and want some clarification,
please try contacting (Dr. by the time you are reading this) Vu Tran or Prof. Archan Misra
who would be in sis.smu.edu.sg
If you want to contact Gihan (for any reason except for blaming him for the bugs in the code),
drop an email to gihanjayatilaka@eng.pdn.ac.lk or look up https://gihan.me/contact
'''
import numpy as np
import cv2
import sys
def getFrame(r,g,b,h,w):
fr=np.zeros(shape=(h,w,3),dtype=np.uint8)
fr[:,:,0]=b
fr[:,:,1]=g
fr[:,:,2]=r
return fr
if __name__ == '__main__':
print("python create-dataset-for-multi-shot-decoding-1.py inputVid.mp4 10 msg.npz outVid.mp4")
print("python create-dataset-for-multi-shot-decoding-1.py [1] [2] [3] [4]")
print("python create-dataset-for-multi-shot-decoding-1.py inputVid.mp4 landMarkevery msg-bits out-vid")
INPUT_VIDEO_FILE=sys.argv[1]
LANDMARK_ONCE_EVERY=int(sys.argv[2])
OUTPUT_VIDEO_FILE=sys.argv[4]
FRAME_RATE=60
vidIn=cv2.VideoCapture(INPUT_VIDEO_FILE)
ret,fr=vidIn.read()
if not ret:
print("ERROR in reading video")
quit(0)
H=fr.shape[0]
W=fr.shape[1]
vidOut=cv2.VideoWriter(OUTPUT_VIDEO_FILE,cv2.VideoWriter_fourcc('M','J','P','G'),FRAME_RATE,(W,H))
NO_INPUT_VIDEO_FRAMES=vidIn.get(cv2.CAP_PROP_FRAME_COUNT)
vidOut.write(getFrame(255,0,0,H,W))
vidOut.write(getFrame(0,255,0,H,W))
vidOut.write(getFrame(0,0,255,H,W))
allFramesCompleted=0
videoFramesCompleted=0
font = cv2.FONT_HERSHEY_SIMPLEX
while videoFramesCompleted<NO_INPUT_VIDEO_FRAMES:
if (allFramesCompleted%LANDMARK_ONCE_EVERY)==0:
tempFr=getFrame(255,0,0,H,W)
cv2.putText(tempFr,'Fr no: {}. Completed {} vid frames\n Written {} frames to file.'.format(allFramesCompleted,videoFramesCompleted,allFramesCompleted+3),(10,500), font, 4,(0,0,0),2,cv2.LINE_AA)
cv2.putText(tempFr,'Written {} frames in total to file.'.format(allFramesCompleted+3),(10,700), font, 4,(0,0,0),2,cv2.LINE_AA)
vidOut.write(tempFr)
allFramesCompleted+=1
ret,fr=vidIn.read()
vidOut.write(fr)
allFramesCompleted+=1
videoFramesCompleted+=1
if allFramesCompleted%100==0:
print("Completed {} frames including {} video frames.".format(allFramesCompleted,videoFramesCompleted))
if videoFramesCompleted==1000:
break
vidOut.release()
vidIn.release()
print("FINISHED: Read from {} and written to {}".format(INPUT_VIDEO_FILE,OUTPUT_VIDEO_FILE))
print("Written {} total frames including {} video frames in addition to {} preamble".format(allFramesCompleted,videoFramesCompleted,3))
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