marek-simonik / record3d

Accompanying library for the Record3D iOS app (https://record3d.app/). Allows you to receive RGBD stream from iOS devices with TrueDepth camera(s).
https://record3d.app/
GNU Lesser General Public License v2.1
379 stars 55 forks source link

How to process depth confidence map files? #39

Closed knsjoon closed 2 years ago

knsjoon commented 2 years ago

Hello Marek! Thank you for a great app (once again! --> I emailed you before for other issues). I wonder how to process the depth confidence map that is outputted on .r3d files?

   def load_confidence(filepath):
    with open(filepath, 'rb') as confidence_fh:
        raw_bytes = confidence_fh.read()
        decompressed_bytes = liblzfse.decompress(raw_bytes)
        confidence_img = np.frombuffer(decompressed_bytes, dtype=np.float32)
        print (raw_bytes)
        print (confidence_img)

    confidence_img = confidence_img.reshape((256, 192))  # For a LiDAR 3D Video

    return confidence_img

I tried to process it the same way as processing the depth map but I get the following error: ValueError: cannot reshape array of size 12288 into shape (256,192)

Thank you in advance!

marek-simonik commented 2 years ago

Hello, thank you for still using Record3D :).

The reason you get this error is that the confidence maps hold uint8 pixels, but you are attempting to load them as float32. Using this to load the confidece should fix the error:

confidence_img = np.frombuffer(decompressed_bytes, dtype=np.uint8)

Please see https://github.com/marek-simonik/record3d/issues/7#issuecomment-736573410 for more details.

I'm closing this issue as I believe my comment will fix the error, but feel free to comment / reopen this issue if you would encounter any further problems.

sandeepnmenon commented 1 year ago

How to get the confidence map while streaming? I am trying to run an algorithm on point clouds where I construct it from the image, depth and instrinsic information. However the one I construct from the exported data files is vastly better than the one from the data in the stream. I am suspecting this because I am not using confidence maps in the stream. How to get that? Or is there any other thing to be considered while streaming