summaryrefslogtreecommitdiff
path: root/run.py
diff options
context:
space:
mode:
authorJules Laplace <julescarbon@gmail.com>2018-06-25 20:21:33 +0200
committerJules Laplace <julescarbon@gmail.com>2018-06-25 20:21:33 +0200
commit286640c558a1266d6e842b8e129cee39af93cec2 (patch)
treefc8559941357fc7b5c4a886f9f76f51180568b6b /run.py
parentab6368872d2c99fd1880a2615080ed5aeda911c5 (diff)
smooth sequences
Diffstat (limited to 'run.py')
-rw-r--r--run.py32
1 files changed, 31 insertions, 1 deletions
diff --git a/run.py b/run.py
index 397475f..6563b43 100644
--- a/run.py
+++ b/run.py
@@ -26,6 +26,7 @@ arguments_smooth = False
arguments_aOffset = 0
arguments_bOffset = 0
arguments_mixVideos = False
+arguments_averageVideos = False
for strOption, strArgument in getopt.getopt(sys.argv[1:], '', [ strParameter[2:] + '=' for strParameter in sys.argv[1::2] ])[0]:
print("{}: {}".format(strOption, strArgument))
@@ -49,6 +50,8 @@ for strOption, strArgument in getopt.getopt(sys.argv[1:], '', [ strParameter[2:]
arguments_smooth = bool(strArgument)
elif strOption == '--mix-videos':
arguments_mixVideos = bool(strArgument)
+ elif strOption == '--average-videos':
+ arguments_averageVideos = bool(strArgument)
elif strOption == '--a-offset':
arguments_aOffset = int(strArgument)
elif strOption == '--b-offset':
@@ -108,6 +111,26 @@ def process_two_videos(moduleNetwork, tensorOutput, a, b, a_offset, b_offset, st
steps *= dilate
return recurse_videos(moduleNetwork, tensorOutput, a, b, a_offset, b_offset, steps, steps, steps/2, dilate)
+def average_two_videos(moduleNetwork, tensorOutput, a, b, a_offset, b_offset, steps, dilate):
+ global index
+ index += 1
+ if (index % 10) == 0:
+ print("{}...".format(index))
+ frames = []
+ steps *= dilate
+ for i in range(0, steps * dilate, dilate):
+ a_fn = os.path.join(a, "frame_{:0>5}.png".format(int(frame_index + a_offset)))
+ b_fn = os.path.join(b, "frame_{:0>5}.png".format(int(frame_index + b_offset)))
+ print("{} => {}".format(a_fn, b_fn))
+ a_np = load_image(a_fn)
+ b_np = load_image(b_fn)
+ tensorInputFirst = torch.FloatTensor(a_np)
+ tensorInputSecond = torch.FloatTensor(b_np)
+ process(moduleNetwork, tensorInputFirst, tensorInputSecond, tensorOutput)
+ middle_np = tensorOutput.clamp(0.0, 1.0).numpy()
+ frames.append(middle_np)
+ return frames
+
def process_tree(moduleNetwork, a, b, tensorOutput, steps, dilate):
global index
index += 1
@@ -201,7 +224,14 @@ elif arguments_mixVideos:
outputPath = './renders/' + arguments_strVideoOut
frames = process_two_videos(moduleNetwork, tensorOutput, arguments_strFirst, arguments_strSecond, arguments_aOffset, arguments_bOffset, arguments_steps, arguments_dilate)
frames = smooth_frames(moduleNetwork, tensorOutput, frames, arguments_smooth)
- print("dilate... {}".format(arguments_dilate))
+ frames = dilate_frames(moduleNetwork, tensorOutput, frames, arguments_dilate)
+ store_frames(frames, outputPath)
+elif arguments_averageVideos:
+ print("average two videos...")
+ print("{} => {}".format(arguments_strFirst, arguments_strSecond))
+ outputPath = './renders/' + arguments_strVideoOut
+ frames = average_two_videos(moduleNetwork, tensorOutput, arguments_strFirst, arguments_strSecond, arguments_aOffset, arguments_bOffset, arguments_steps, arguments_dilate)
+ frames = smooth_frames(moduleNetwork, tensorOutput, frames, arguments_smooth)
frames = dilate_frames(moduleNetwork, tensorOutput, frames, arguments_dilate)
store_frames(frames, outputPath)
elif arguments_steps == 0: