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

what is the correct way of changing depth_scale? #2385

Closed
ywjia opened this issue Sep 12, 2018 · 4 comments
Closed

what is the correct way of changing depth_scale? #2385

ywjia opened this issue Sep 12, 2018 · 4 comments
Assignees

Comments

@ywjia
Copy link

ywjia commented Sep 12, 2018

  • Before opening a new issue, we wanted to provide you with some useful suggestions (Click "Preview" above for a better view):

  • All users are welcomed to report bugs, ask questions, suggest or request enhancements and generally feel free to open new issue, even if they haven't followed any of the suggestions above :)


Required Info
Camera Model D435
Firmware Version 5.10.3.0
Operating System & Version Ubuntu 16
Kernel Version (Linux Only) 4.15.0-34
Platform PC
SDK Version 2.16.0
Language C++
Segment VR}

Issue Description

What is the correct way of setting depth_scale? I have the following code running, but the output puzzles me. See below. I would expect depth_scale_2 be the updated value 0.0001, not the original one (0.001).

int main()
{
rs2::context ctx;
auto list = ctx.query_devices();
if (list.size() == 0) throw std::runtime_error("No device detected. Is it plugged in?");
rs2::pipeline pipe;
rs2::config cfg;
cfg.enable_stream(RS2_STREAM_COLOR, 1920, 1080, RS2_FORMAT_BGR8, 15);
cfg.enable_stream(RS2_STREAM_DEPTH, 1280, 720, RS2_FORMAT_Z16, 15);
rs2::pipeline_profile profile = pipe.start(cfg);
rs2::depth_sensor depth_sensor = profile.get_device().firstrs2::depth_sensor();
auto original_scale = depth_sensor.get_option(RS2_OPTION_DEPTH_UNITS);
std::cout << "original scale: " << original_scale << std::endl;
float depth_scale_1 = get_depth_scale(profile.get_device());
std::cout << "depth_scale_1 = " << depth_scale_1 << std::endl;
depth_sensor.set_option(RS2_OPTION_DEPTH_UNITS, 0.0001);
auto updated_scale = depth_sensor.get_option(RS2_OPTION_DEPTH_UNITS);
std::cout << "updated scale: " << updated_scale << std::endl;
float depth_scale_2 = get_depth_scale(profile.get_device());
std::cout << "depth_scale_2 = " << depth_scale << std::endl;
return EXIT_SUCCESS;
}

output:

original scale: 0.001
depth_scale_1 = 0.001
updated scale: 0.0001
depth_scale_2 = 0.001

@RealSense-Customer-Engineering
Copy link
Collaborator

[Realsense Customer Engineering Team Comment]
Hi @ywjia,

Check below code. It should be no problem to modify the depth scale.

auto sensor = profile.get_device().firstrs2::depth_sensor();
auto depth_unit = sensor.get_option(RS2_OPTION_DEPTH_UNITS);
auto scale = sensor.get_depth_scale();
printf("[Before]Depth Scale: %f\r\n", scale);
sensor.set_option(RS2_OPTION_DEPTH_UNITS, 0.0001);
depth_unit = sensor.get_option(RS2_OPTION_DEPTH_UNITS);
scale = sensor.get_depth_scale();
printf("[After]Depth Scale: %f\r\n", scale);

@ywjia
Copy link
Author

ywjia commented Sep 13, 2018

Hi @RealSense-Customer-Engineering,

I copy&paste and run your code above, but depth_scale was not changed, as output below:

[Before]Depth Scale: 0.001000
[After]Depth Scale: 0.001000

Of course, the first line was changed to
auto sensor = profile.get_device().first < rs2::depth_sensor >();

Also, what is the difference between "sensor.get_option(RS2_OPTION_DEPTH_UNITS)" and " get_depth_scale(profile.get_device())"?

Thanks.

@RealSense-Customer-Engineering
Copy link
Collaborator

[Realsense Customer Engineering Team Comment]
Hi @ywjia,

"RS2_OPTION_DEPTH_UNITS" and "get_depth_scale" can be used to get the value. But, you can use "RS2_OPTION_DEPTH_UNITS" before stream starts.
So, suggest to set the depth unit first, and then you should be able to get the correct scale value after pipe start. The example code like below:

rs2::context ctx; // Create librealsense context for managing devices
auto list = ctx.query_devices(); // Get a snapshot of currently connected devices
rs2::device dev = list.front();
auto depthSensor = dev.firstrs2::depth_sensor();
// set depth unit
depthSensor.set_option(RS2_OPTION_DEPTH_UNITS, 0.0001); // 0.0001

@ywjia
Copy link
Author

ywjia commented Sep 14, 2018

thanks. I understood it now. the key is to apply set_option() before starting the pipeline.

issue closed.

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

2 participants