Commit 89329fb6 authored by Gihan Jayatilaka's avatar Gihan Jayatilaka

deepcode complete

parent 9d55ae16
......@@ -12,6 +12,9 @@ def rowToChar(row):
c=np.sum(bin*np.power(np.full((8),2),np.arange(0,8)))
if not isinstance(c,int):
return chr(0)
return chr(c)
......
import sys
import numpy as np
import cv2
from keras.models import load_model
import math
if __name__ == "__main__":
print("python video-decoding.py cropped.mp4 decoding-model.h5 msg-bits.npz")
INPUT_VIDEO_FILE=sys.argv[1]
DECODING_MODEL_FILE=sys.argv[2]
OUTPUT_MSG_FILE=sys.argv[3]
vidIn=cv2.VideoCapture(INPUT_VIDEO_FILE)
model=load_model(DECODING_MODEL_FILE)
msg=[]
while vidIn.isOpened():
ret,fr=vidIn.read()
if not ret:
break
if fr.shape[0]!=299 or fr.shape[1]!=299:
fr=cv2.resize(fr,(299,299))
fr=np.reshape(fr,newshape=(1,299,299,3))
thisMsg=model.predict(fr)
# print(thisMsg.shape)
cellsPerHeight=int(math.sqrt(thisMsg.shape[1]))
#assert isinstance(math.sqrt(thisMsg.shape[1]),int),"The number of bits in a frame is not a square number!!"
assert cellsPerHeight*cellsPerHeight==thisMsg.shape[1],"The number of bits in a frame is not a square number!!"
thisMsg=np.reshape(thisMsg,newshape=(cellsPerHeight,cellsPerHeight))
msg.append(thisMsg)
msg=np.array(msg)
np.savez(OUTPUT_MSG_FILE,ar=msg)
print("Finished saving message to {}".format(OUTPUT_MSG_FILE))
#!/usr/bin/env bash
python video-cropping-1.py ./deepcode-dump/recorded.mp4 screen-detection-model.h5 ./deepcode-dump/cropped.mp4 200
python msg-decoding-1.py ./deepcode-dump/msg-bits.npz ./deepcode-dump/decoded-msg.txt
python ./code/video-cropping-1.py ./input/recorded.mp4 ./models/screen-detection.h5 ./dump/cropped.mp4 200
python ./code/video-decoding-1.py ./dump/cropped.mp4 ./models/bit-decoding.h5 ./dump/msg-bits.npz
python ./code/msg-decoding-1.py ./dump/msg-bits.npz ./output/decoded-msg.txt
#!/usr/bin/env bash
python msg-encoding-1.py ./deepcode-dump/msg.txt ./deepcode-dump/temp.npz 10 10
python video-encoding-1.py ./video/screen-detection/red-ori.mp4 ./deepcode-dump/temp.npz ./deepcode-dump/encoded.mp4 1000
python ./code/msg-encoding-1.py ./input/msg.txt ./dump/temp.npz 10 10
python ./code/video-encoding-1.py ./input/original.mp4 ./dump/temp.npz ./output/encoded.mp4 1000
#!/usr/bin/env bash
rm input/*
rm output/*
rm dump/*
echo "Add original.mp4 and msg.txt to input/"
echo "Run deepcode-transmitter.sh"
echo "Play output/encoded.mp4 and record it"
echo "Add recorded.mp4 to input/"
echo "Run deepcode-transmitter.sh"
echo "The message is in output/decoded-msg.txt"
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