SysCV / shift-dev

SHIFT Dataset DevKit - CVPR2022
https://www.vis.xyz/shift
MIT License
101 stars 10 forks source link

How to read the depth image #2

Closed xiaoxTM closed 2 years ago

xiaoxTM commented 2 years ago

Hi, all: I noticed that the depth convertion formula is Depth (meters) = (256 256 R + 256 * G + B) / 1000. according to the description here however, I plot the depth image and found that the depth is not correct: the value goes up and down in the depth direction. Did the formula changed or did I missed something somewhere ?

Thanks

suniique commented 2 years ago

Hey @xiaoxTM, could you please attach the relevant codes you use for reading and conversion?

amitshomer commented 2 years ago

Hi,

I cam accros the same problem. Here the relevant code:

with open(gt_name, 'rb') as f: gt = (Image.open(f).convert('RGB')) depth_png = np.array(gt, dtype=int) depth = (256 256 depth_png[:,:,0] + 256 * depth_png[:,:,1] + depth_png[:,:,2]) / 1000

Thanks

suniique commented 2 years ago

Hi, @xiaoxTM and @amitshomer! Thanks for telling us about this issue. Apparently, the description on the webpage is outdated. We will update it asap. Below is the code for reading depth,

DEPTH_C = np.array(1000.0 / (256 * 256 * 256 - 1), np.float32)
depth = (256 * 256 * img[:, :, 2] +  256 * img[:, :, 1] + img[:, :, 0]) * DEPTH_C  # in meters
mwdotzom commented 1 year ago

for anyone stuck with this issue, please choose either of the two:

  1. use img = PIL.Image.open(img_path), or:
  2. use img = cv2.imread(img_path), then img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB) afterwards, img = np.array(img, dtype=int) then you can use the calculation provided by @suniique and you will get the correct result