Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to change depth units in python #1905

Closed
Litvak1 opened this issue Jun 18, 2018 · 7 comments
Closed

How to change depth units in python #1905

Litvak1 opened this issue Jun 18, 2018 · 7 comments
Assignees

Comments

@Litvak1
Copy link

Litvak1 commented Jun 18, 2018

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!

@0xLeon
Copy link

0xLeon commented Jun 18, 2018

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.

@Litvak1
Copy link
Author

Litvak1 commented Jun 19, 2018

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?

@0xLeon
Copy link

0xLeon commented Jun 19, 2018

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.

@Litvak1
Copy link
Author

Litvak1 commented Jun 19, 2018

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

@xkunwu
Copy link

xkunwu commented Nov 28, 2018

Got an error when trying to set this option:
RuntimeError: This option is read-only!

@lramati
Copy link
Contributor

lramati commented Nov 28, 2018 via email

@RyanPaulMcKenna
Copy link

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants