dwofk / fast-depth

ICRA 2019 "FastDepth: Fast Monocular Depth Estimation on Embedded Systems"
MIT License
930 stars 188 forks source link

How to get the absolute distance from the camera to the object based on depth map? #13

Closed MRinel closed 5 years ago

MRinel commented 5 years ago

Hi,everyone. I saw how to draw a depth map from these line in source code: image But does the parameter "depth" represent absolute distance from the camera to the object?And what is the unit of distance? If I'm wrong, how can I get the absolute distance? Thank you a lot~

dwofk commented 5 years ago

Hi @MRinel,

The depth output by the network, when running pred = model(input), is in meters.

The colored_depthmap function simply scales the depth for visualization purposes.

MRinel commented 5 years ago

Thank you for your explanation! @dwofk There is another issue I don't quite understand. On TX2, when I use the example image, the prediction was really good [like the first image], but not so good using my own input [like the second image].I compared the input images' information, they have different depth bit, one is 32 bits, the other is 24 bits, does the last 8 bits representing transparency have any impact on prediction? rgb_pred 13

dwofk commented 5 years ago

Hi @MRinel,

If there is an alpha/transparency channel present (i.e. if your current input is in RGBA color space), that channel needs to be removed first, so that the correct R, G, and B channels can then be fed into the network.

You could try converting your input from RGBA to RGB to see if this was the issue.

MRinel commented 5 years ago

Hi @dwofk , Maybe I didn't describe it clearly. I have transformed "deploy/data/rgb.npy,pred.npy,depth.npy" to "rgb.png,pred.png,GT-depth.png" by "data/visualize.py", they are normal like what posted on fast-depth paper. But when using my current input (without alpha channel), the outputs of visualize.py seems strange. Like next pictures. The first image is original without alpha channel, second is "visualize.py-->rgb",third is "visualize.py-->pred", I'm confused why the RGB image cannot be restored with visualize.py .Am I getting the npy file the right way? I get the npy file this way:

  from PIL import Image
  import numpy as np

  im = Image.open('./data/test_0902.png')
  im = im.resize((224,224),Image.ANTIALIAS)
  im_array = np.array(im)
  np.save('./data/test_0902.npy',im_array)

test_0902 test_0902 (1) test_0902_pred

MRinel commented 5 years ago

I've solved the problem,thanks a lot! @dwofk

aghasaadmohammad commented 4 years ago

@MRinel how did u solve this issue?

MRinel commented 4 years ago

@aghasaadmohammad , the strange visualization of depth image seems to be related with normalization of input image. Use matplotlib for reading input or /255. have a try :)