-
Notifications
You must be signed in to change notification settings - Fork 225
/
autozoom.py
102 lines (80 loc) · 2.67 KB
/
autozoom.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#!/usr/bin/env python
import base64
import cupy
import cv2
import flask
import getopt
import gevent
import gevent.pywsgi
import glob
import h5py
import io
import math
import moviepy
import moviepy.editor
import numpy
import os
import random
import re
import scipy
import scipy.io
import shutil
import sys
import tempfile
import time
import torch
import torchvision
import urllib
import zipfile
##########################################################
torch.set_grad_enabled(False) # make sure to not compute gradients for computational performance
torch.backends.cudnn.enabled = True # make sure to use cudnn for computational performance
##########################################################
objCommon = {}
exec(open('./common.py', 'r').read())
exec(open('./models/disparity-estimation.py', 'r').read())
exec(open('./models/disparity-adjustment.py', 'r').read())
exec(open('./models/disparity-refinement.py', 'r').read())
exec(open('./models/pointcloud-inpainting.py', 'r').read())
##########################################################
args_strIn = './images/doublestrike.jpg'
args_strOut = './autozoom.mp4'
args_strDepth = None
for strOption, strArg in getopt.getopt(sys.argv[1:], '', [
'in=',
'out=',
'depth=',
])[0]:
if strOption == '--in' and strArg != '': args_strIn = strArg # path to the input image
if strOption == '--out' and strArg != '': args_strOut = strArg # path to where the output should be stored
if strOption == '--depth' and strArg != '': args_strDepth = strArg # optional path to a depth map in numpy format
# end
##########################################################
if __name__ == '__main__':
npyImage = cv2.imread(filename=args_strIn, flags=cv2.IMREAD_COLOR)
intWidth = npyImage.shape[1]
intHeight = npyImage.shape[0]
fltRatio = float(intWidth) / float(intHeight)
intWidth = min(int(1024 * fltRatio), 1024)
intHeight = min(int(1024 / fltRatio), 1024)
npyImage = cv2.resize(src=npyImage, dsize=(intWidth, intHeight), fx=0.0, fy=0.0, interpolation=cv2.INTER_AREA)
process_load(npyImage, {} if args_strDepth is None else {'npyDepth': numpy.load(args_strDepth)})
objFrom = {
'fltCenterU': intWidth / 2.0,
'fltCenterV': intHeight / 2.0,
'intCropWidth': int(math.floor(0.97 * intWidth)),
'intCropHeight': int(math.floor(0.97 * intHeight))
}
objTo = process_autozoom({
'fltShift': 100.0,
'fltZoom': 1.25,
'objFrom': objFrom
})
npyResult = process_kenburns({
'fltSteps': numpy.linspace(0.0, 1.0, 75).tolist(),
'objFrom': objFrom,
'objTo': objTo,
'boolInpaint': True
})
moviepy.editor.ImageSequenceClip(sequence=[ npyFrame[:, :, ::-1] for npyFrame in npyResult + list(reversed(npyResult))[1:-1] ], fps=25).write_videofile(args_strOut)
# end