How to change depth units in python
| Required Info | |
|---|---|
| Camera Model | D415 |
| Firmware Version | 05.08.15.00 |
| Operating System & Version | Linux (Ubuntu 16.04) |
| Kernel Version (Linux Only) | 4.13.0-45-generic |
| Platform | PC |
| SDK Version | ? |
| Language | python |
Hi,
As explained here, I am trying to change the depth units from millimeter (depth_units = 1000) to a tenth of that (depth_units = 100).
I couldn't find how to use 'rs2_set_option' in python.
Could you please send some example?
Also, will the minimum distance of depth images be affected by this change?
Thank you!
Options are set on a sensor level. Therefore, options are set on sensor objects. The procedure is outlined in a script I wrote: https://github.com/0xLeon/StereoImageProcessing/blob/master/Lab/GetDepthFrames.py#L55
Instead of rs.option.emitter_enabled you would set rs.option.depth_units. Also, keep in mind, depth units are always specified in meter. The depth unit option controls the meaning of one unit in the depth stream data format.
Hi @0xLeon.
Thanks for answering my question.
I've tried what you said and got an error.
This is the code:
profile = pipeline.start() depth_sensor = profile.get_device().first_depth_sensor() if depth_sensor.supports(rs.option.depth_units): depth_sensor.set_option(rs.option.depth_units, 100.0)
And this is the error:
RuntimeError: OpCodes do not match! Sent 43 but received -6!
If I try to change the depth units in realsense-viewer it works.
Do you have some suggestion?
I think the example is not up-to-date (can't say if it was ever true, I'm not that long into RealSense development). If you have a look at depth_sensor.get_option(rs.option.depth_units), you can see the returned value is a float with a default value of around 0.001. This corresponds to the default depth unit of 1 mm expressed in meters. So if you want to have a depth unit of 0.1 mm, you would pass this in meters to the call, which would be 0.0001: depth_sensor.set_option(rs.option.depth_units, 0.0001).
I'm not completely sure if this is actually true, I didn't dive into the C++ code so far, only worked with the higher level Python bindings. And I haven't checked on the outcome of changing rs.option.depth_units so far. Maybe you can have a look at this, I'd be happy to read about your results.
It worked!
Exactly as you described it.
Thanks a lot @0xLeon !
If you have the time, please see if you could help me with another issue I submitted - Transforming pixel from a depth image to world coordinates
Got an error when trying to set this option: RuntimeError: This option is read-only!
Please open a new issue with a full description of what didn't work
Just a heads up to everyone, for me the solution was much simpler, the cable I was using was not good enough, switching to a higher quality cable improved performance massively.
Also make sure the the camera is at least 20cm away from everything your measuring or all the depth information will be wrong!