Skip to content

Commit

Permalink
update style-tranfer.ipynb
Browse files Browse the repository at this point in the history
  • Loading branch information
Kautenja committed Feb 17, 2018
1 parent f5ecae5 commit 6789a09
Show file tree
Hide file tree
Showing 12 changed files with 401 additions and 83 deletions.
4 changes: 3 additions & 1 deletion Makefile
Expand Up @@ -10,6 +10,8 @@ BUILD=build
PDFLATEX=pdflatex
# the pointer to the bibilography engine (bibtex)
BIBTEX=bibtex
# the number of frames of interpolation to use in videos
INTER_FRAMES=3

# install Python dependencies in the requirements.txt
install:
Expand Down Expand Up @@ -52,7 +54,7 @@ review_w_ref: build
# Args:
# 1: the name of the directory in the build directory to find frames in
define frames_to_video
${PYTHON} frames_to_video.py build/$(1) build/$(1).mp4
${PYTHON} frames_to_video.py build/$(1) build/$(1).mp4 ${INTER_FRAMES}
endef

# make all the content reconstruction videos
Expand Down
38 changes: 35 additions & 3 deletions frames_to_video.py
Expand Up @@ -5,9 +5,30 @@
from os import listdir


# get the directory from the command line input
def pairs(iterable):
"""
Return a new iterable over sequential pairs in the given iterable.
i.e. (0,1), (1,2), ..., (n-2,n-1)
Args:
iterable: the iterable to iterate over the pairs of
Returns: a new iterator over the pairs of the given iterator
"""
# lazily import tee from `itertools`
from itertools import tee
# split the iterator into 2 identical iterators
a, b = tee(iterable)
# retrieve the next item from the b iterator
next(b, None)
# zip up the iterators of current and next items
return zip(a, b)


# the directory of png files to make into a video
directory = argv[1]
# the name of the video file to write
video_name = argv[2]
# the number of frames to use for interpolation
interpolation_frames = int(argv[3])

# get the frames from the given directory in sorted order
frames = [filename for filename in listdir(directory) if '.png' in filename]
Expand All @@ -23,8 +44,19 @@
out = cv2.VideoWriter(video_name, fourcc, 20.0, (width, height))

# write the frames to the video file
for frame in frames:
out.write(frame)
for frame, next_frame in pairs(frames):
# write the current frame
out.write(frame)
# iterate over the number of interpolation frames
for i in range(1, interpolation_frames + 1):
# calculate a frame between current and next frames
w = i / interpolation_frames
mid_frame = cv2.addWeighted(frame, 1 - w, next_frame, w, 0)
# write this mid frame to the video
out.write(mid_frame)

# the last frame still needs written
out.write(frames[-1])

# cleanup and release the video
out.release()
Expand Down
442 changes: 363 additions & 79 deletions style-transfer.ipynb

Large diffs are not rendered by default.

Binary file modified tex/img/transfer/kandinsky.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tex/img/transfer/monet-tv-1e-3.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tex/img/transfer/monet-tv-1e0.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tex/img/transfer/monet-tv-1e1.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tex/img/transfer/monet.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tex/img/transfer/scream.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tex/img/transfer/seated-nudes.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tex/img/transfer/shipwreck.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tex/img/transfer/starry-starry-night.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 6789a09

Please sign in to comment.