Skip to content

Commit

Permalink
no message
Browse files Browse the repository at this point in the history
  • Loading branch information
Simon Niklaus committed Feb 9, 2024
1 parent ca1e878 commit e629394
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 26 deletions.
24 changes: 15 additions & 9 deletions autozoom.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,24 @@

##########################################################

arguments_strIn = './images/doublestrike.jpg'
arguments_strOut = './autozoom.mp4'

for strOption, strArgument in getopt.getopt(sys.argv[1:], '', [ strParameter[2:] + '=' for strParameter in sys.argv[1::2] ])[0]:
if strOption == '--in' and strArgument != '': arguments_strIn = strArgument # path to the input image
if strOption == '--out' and strArgument != '': arguments_strOut = strArgument # path to where the output should be stored
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=arguments_strIn, flags=cv2.IMREAD_COLOR)
npyImage = cv2.imread(filename=args_strIn, flags=cv2.IMREAD_COLOR)

intWidth = npyImage.shape[1]
intHeight = npyImage.shape[0]
Expand All @@ -70,7 +76,7 @@

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

process_load(npyImage, {})
process_load(npyImage, {} if args_strDepth is None else {'npyDepth': numpy.load(args_strDepth)})

objFrom = {
'fltCenterU': intWidth / 2.0,
Expand All @@ -92,5 +98,5 @@
'boolInpaint': True
})

moviepy.editor.ImageSequenceClip(sequence=[ npyFrame[:, :, ::-1] for npyFrame in npyResult + list(reversed(npyResult))[1:-1] ], fps=25).write_videofile(arguments_strOut)
moviepy.editor.ImageSequenceClip(sequence=[ npyFrame[:, :, ::-1] for npyFrame in npyResult + list(reversed(npyResult))[1:-1] ], fps=25).write_videofile(args_strOut)
# end
23 changes: 16 additions & 7 deletions common.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,20 @@ def process_load(npyImage, objSettings):
objCommon['intHeight'] = npyImage.shape[0]

tenImage = torch.FloatTensor(numpy.ascontiguousarray(npyImage.transpose(2, 0, 1)[None, :, :, :].astype(numpy.float32) * (1.0 / 255.0))).cuda()
tenDisparity = disparity_estimation(tenImage)
tenDisparity = disparity_adjustment(tenImage, tenDisparity)
tenDisparity = disparity_refinement(tenImage, tenDisparity)
tenDisparity = tenDisparity / tenDisparity.max() * objCommon['fltBaseline']
tenDepth = (objCommon['fltFocal'] * objCommon['fltBaseline']) / (tenDisparity + 0.0000001)

if 'npyDepth' not in objSettings:
tenDisparity = disparity_estimation(tenImage)
tenDisparity = disparity_adjustment(tenImage, tenDisparity)
tenDisparity = disparity_refinement(tenImage, tenDisparity)
tenDisparity = tenDisparity / tenDisparity.max() * objCommon['fltBaseline']
tenDepth = (objCommon['fltFocal'] * objCommon['fltBaseline']) / (tenDisparity + 0.0000001)

elif 'npyDepth' in objSettings:
tenDepth = torch.FloatTensor(numpy.ascontiguousarray(numpy.atleast_3d(objSettings['npyDepth']).astype(numpy.float32).transpose(2, 0, 1)[None, :, :, :])).cuda()
tenDisparity = (objCommon['fltFocal'] * objCommon['fltBaseline']) / (tenDepth + 0.0000001)

# end

tenValid = (spatial_filter(tenDisparity / tenDisparity.max(), 'laplacian').abs() < 0.03).float()
tenPoints = depth_to_points(tenDepth * tenValid, objCommon['fltFocal'])
tenUnaltered = depth_to_points(tenDepth, objCommon['fltFocal'])
Expand Down Expand Up @@ -61,7 +70,7 @@ def process_shift(objSettings):
fltShiftY = fltClosestFromY - fltClosestToY
fltShiftZ = objSettings['fltDepthTo'] - objSettings['fltDepthFrom']

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

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

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

for fltStep in [ 0.0, 1.0 ]:
for fltStep in [ 1.0 ]:
fltFrom = 1.0 - fltStep
fltTo = 1.0 - fltFrom

Expand Down
21 changes: 12 additions & 9 deletions depthestim.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,21 @@

##########################################################

arguments_strIn = './images/doublestrike.jpg'
arguments_strOut = './depthestim.npy'

for strOption, strArgument in getopt.getopt(sys.argv[1:], '', [ strParameter[2:] + '=' for strParameter in sys.argv[1::2] ])[0]:
if strOption == '--in' and strArgument != '': arguments_strIn = strArgument # path to the input image
if strOption == '--out' and strArgument != '': arguments_strOut = strArgument # path to where the output should be stored
args_strIn = './images/doublestrike.jpg'
args_strOut = './depthestim.npy'

for strOption, strArg in getopt.getopt(sys.argv[1:], '', [
'in=',
'out=',
])[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
# end

##########################################################

if __name__ == '__main__':
npyImage = cv2.imread(filename=arguments_strIn, flags=cv2.IMREAD_COLOR)
npyImage = cv2.imread(filename=args_strIn, flags=cv2.IMREAD_COLOR)

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

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

numpy.save(arguments_strOut, npyDepth)
numpy.save(args_strOut, npyDepth)
# end
2 changes: 1 addition & 1 deletion interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def load_image():
process_load(objPlayback['npyImage'], {})

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

return ''
Expand Down

0 comments on commit e629394

Please sign in to comment.