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

Customize Colormaps on USB Live Streaming Mode #57

Open LaThanhTrong opened 1 year ago

LaThanhTrong commented 1 year ago

When I am running demo-main.py, depth from cv2 shows only black, gray and white colormap. I tried to switch other colormaps in the settings, but it does not work. It only works when streaming mode is turned off. Is there anything I have to do in the settings or lines of code can solve this issue?

marek-simonik commented 1 year ago

Do you mean that you see the depth map in shades of gray instead of colored by the currently selected colormap from the Settings section? It is not a bug, but the expected behavior; the USB streaming mode is supposed to stream unaltered RGBD data and it is the responsibility of the receiver (e.g. the Python script) to post-process the raw output into the desired output.

I would advise to adjust the Python script and apply color mapping (or other post-processing you need) to the depth map via Python. Note that the depth map contains float32 numbers and invalid values are stored as NaNs (something to be aware of when implementing color mapping).

LaThanhTrong commented 1 year ago

Do you mean that you see the depth map in shades of gray instead of colored by the currently selected colormap from the Settings section? It is not a bug, but the expected behavior; the USB streaming mode is supposed to stream unaltered RGBD data and it is the responsibility of the receiver (e.g. the Python script) to post-process the raw output into the desired output.

I would advise to adjust the Python script and apply color mapping (or other post-processing you need) to the depth map via Python. Note that the depth map contains float32 numbers and invalid values are stored as NaNs (something to be aware of when implementing color mapping).

Do python also support shading aswell?

marek-simonik commented 1 year ago

You can implement arbitrary post-processing in Python, but there is no out-of-the-box support for shading per se; you will have to implement your own filters/post-processing from scratch (it is unrelated to Record3D).

pcktm commented 1 year ago

An example of color mapping:

self.max_depth_ever = max(self.max_depth_ever, np.nanmax(depth))
depth[np.isnan(depth)] = self.max_depth_ever
depth = depth / self.max_depth_ever * 255
depth = depth.astype(np.uint8)

depth = cv2.applyColorMap(depth, cv2.COLORMAP_JET)