Skip to content

Commit e629394

Browse files
author
Simon Niklaus
committed
no message
1 parent ca1e878 commit e629394

File tree

4 files changed

+44
-26
lines changed

4 files changed

+44
-26
lines changed

autozoom.py

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,18 +47,24 @@
4747

4848
##########################################################
4949

50-
arguments_strIn = './images/doublestrike.jpg'
51-
arguments_strOut = './autozoom.mp4'
52-
53-
for strOption, strArgument in getopt.getopt(sys.argv[1:], '', [ strParameter[2:] + '=' for strParameter in sys.argv[1::2] ])[0]:
54-
if strOption == '--in' and strArgument != '': arguments_strIn = strArgument # path to the input image
55-
if strOption == '--out' and strArgument != '': arguments_strOut = strArgument # path to where the output should be stored
50+
args_strIn = './images/doublestrike.jpg'
51+
args_strOut = './autozoom.mp4'
52+
args_strDepth = None
53+
54+
for strOption, strArg in getopt.getopt(sys.argv[1:], '', [
55+
'in=',
56+
'out=',
57+
'depth=',
58+
])[0]:
59+
if strOption == '--in' and strArg != '': args_strIn = strArg # path to the input image
60+
if strOption == '--out' and strArg != '': args_strOut = strArg # path to where the output should be stored
61+
if strOption == '--depth' and strArg != '': args_strDepth = strArg # optional path to a depth map in numpy format
5662
# end
5763

5864
##########################################################
5965

6066
if __name__ == '__main__':
61-
npyImage = cv2.imread(filename=arguments_strIn, flags=cv2.IMREAD_COLOR)
67+
npyImage = cv2.imread(filename=args_strIn, flags=cv2.IMREAD_COLOR)
6268

6369
intWidth = npyImage.shape[1]
6470
intHeight = npyImage.shape[0]
@@ -70,7 +76,7 @@
7076

7177
npyImage = cv2.resize(src=npyImage, dsize=(intWidth, intHeight), fx=0.0, fy=0.0, interpolation=cv2.INTER_AREA)
7278

73-
process_load(npyImage, {})
79+
process_load(npyImage, {} if args_strDepth is None else {'npyDepth': numpy.load(args_strDepth)})
7480

7581
objFrom = {
7682
'fltCenterU': intWidth / 2.0,
@@ -92,5 +98,5 @@
9298
'boolInpaint': True
9399
})
94100

95-
moviepy.editor.ImageSequenceClip(sequence=[ npyFrame[:, :, ::-1] for npyFrame in npyResult + list(reversed(npyResult))[1:-1] ], fps=25).write_videofile(arguments_strOut)
101+
moviepy.editor.ImageSequenceClip(sequence=[ npyFrame[:, :, ::-1] for npyFrame in npyResult + list(reversed(npyResult))[1:-1] ], fps=25).write_videofile(args_strOut)
96102
# end

common.py

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,20 @@ def process_load(npyImage, objSettings):
55
objCommon['intHeight'] = npyImage.shape[0]
66

77
tenImage = torch.FloatTensor(numpy.ascontiguousarray(npyImage.transpose(2, 0, 1)[None, :, :, :].astype(numpy.float32) * (1.0 / 255.0))).cuda()
8-
tenDisparity = disparity_estimation(tenImage)
9-
tenDisparity = disparity_adjustment(tenImage, tenDisparity)
10-
tenDisparity = disparity_refinement(tenImage, tenDisparity)
11-
tenDisparity = tenDisparity / tenDisparity.max() * objCommon['fltBaseline']
12-
tenDepth = (objCommon['fltFocal'] * objCommon['fltBaseline']) / (tenDisparity + 0.0000001)
8+
9+
if 'npyDepth' not in objSettings:
10+
tenDisparity = disparity_estimation(tenImage)
11+
tenDisparity = disparity_adjustment(tenImage, tenDisparity)
12+
tenDisparity = disparity_refinement(tenImage, tenDisparity)
13+
tenDisparity = tenDisparity / tenDisparity.max() * objCommon['fltBaseline']
14+
tenDepth = (objCommon['fltFocal'] * objCommon['fltBaseline']) / (tenDisparity + 0.0000001)
15+
16+
elif 'npyDepth' in objSettings:
17+
tenDepth = torch.FloatTensor(numpy.ascontiguousarray(numpy.atleast_3d(objSettings['npyDepth']).astype(numpy.float32).transpose(2, 0, 1)[None, :, :, :])).cuda()
18+
tenDisparity = (objCommon['fltFocal'] * objCommon['fltBaseline']) / (tenDepth + 0.0000001)
19+
20+
# end
21+
1322
tenValid = (spatial_filter(tenDisparity / tenDisparity.max(), 'laplacian').abs() < 0.03).float()
1423
tenPoints = depth_to_points(tenDepth * tenValid, objCommon['fltFocal'])
1524
tenUnaltered = depth_to_points(tenDepth, objCommon['fltFocal'])
@@ -61,7 +70,7 @@ def process_shift(objSettings):
6170
fltShiftY = fltClosestFromY - fltClosestToY
6271
fltShiftZ = objSettings['fltDepthTo'] - objSettings['fltDepthFrom']
6372

64-
tenShift = torch.FloatTensor([ fltShiftX, fltShiftY, fltShiftZ ]).view(1, 3, 1).cuda()
73+
tenShift = torch.tensor(data=[[[fltShiftX], [fltShiftY], [fltShiftZ]]], dtype=torch.float32, device=torch.device('cuda'))
6574

6675
tenPoints = objSettings['tenPoints'].clone()
6776

@@ -140,7 +149,7 @@ def process_kenburns(objSettings):
140149
objCommon['tenInpaDepth'] = objCommon['tenRawDepth'].view(1, 1, -1)
141150
objCommon['tenInpaPoints'] = objCommon['tenRawPoints'].view(1, 3, -1)
142151

143-
for fltStep in [ 0.0, 1.0 ]:
152+
for fltStep in [ 1.0 ]:
144153
fltFrom = 1.0 - fltStep
145154
fltTo = 1.0 - fltFrom
146155

depthestim.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,18 +47,21 @@
4747

4848
##########################################################
4949

50-
arguments_strIn = './images/doublestrike.jpg'
51-
arguments_strOut = './depthestim.npy'
52-
53-
for strOption, strArgument in getopt.getopt(sys.argv[1:], '', [ strParameter[2:] + '=' for strParameter in sys.argv[1::2] ])[0]:
54-
if strOption == '--in' and strArgument != '': arguments_strIn = strArgument # path to the input image
55-
if strOption == '--out' and strArgument != '': arguments_strOut = strArgument # path to where the output should be stored
50+
args_strIn = './images/doublestrike.jpg'
51+
args_strOut = './depthestim.npy'
52+
53+
for strOption, strArg in getopt.getopt(sys.argv[1:], '', [
54+
'in=',
55+
'out=',
56+
])[0]:
57+
if strOption == '--in' and strArg != '': args_strIn = strArg # path to the input image
58+
if strOption == '--out' and strArg != '': args_strOut = strArg # path to where the output should be stored
5659
# end
5760

5861
##########################################################
5962

6063
if __name__ == '__main__':
61-
npyImage = cv2.imread(filename=arguments_strIn, flags=cv2.IMREAD_COLOR)
64+
npyImage = cv2.imread(filename=args_strIn, flags=cv2.IMREAD_COLOR)
6265

6366
fltFocal = max(npyImage.shape[1], npyImage.shape[0]) / 2.0
6467
fltBaseline = 40.0
@@ -72,7 +75,7 @@
7275
npyDisparity = tenDisparity[0, 0, :, :].cpu().numpy()
7376
npyDepth = tenDepth[0, 0, :, :].cpu().numpy()
7477

75-
cv2.imwrite(filename=arguments_strOut.replace('.npy', '.png'), img=(npyDisparity / fltBaseline * 255.0).clip(0.0, 255.0).astype(numpy.uint8))
78+
cv2.imwrite(filename=args_strOut.replace('.npy', '.png'), img=(npyDisparity / fltBaseline * 255.0).clip(0.0, 255.0).astype(numpy.uint8))
7679

77-
numpy.save(arguments_strOut, npyDepth)
80+
numpy.save(args_strOut, npyDepth)
7881
# end

interface.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def load_image():
8484
process_load(objPlayback['npyImage'], {})
8585

8686
for fltX, fltY in [ (100.0, 0.0), (-100.0, 0.0), (0.0, 100.0), (0.0, -100.0) ]:
87-
process_inpaint(torch.FloatTensor([ fltX, fltY, 0.0 ]).view(1, 3, 1).cuda())
87+
process_inpaint(torch.tensor(data=[[[fltX], [fltY], [0.0]]], dtype=torch.float32, device=torch.device('cuda')))
8888
# end
8989

9090
return ''

0 commit comments

Comments
 (0)