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

Set depth clamp min/max from C++ and python code #2199

Closed
baptiste-mnh opened this issue Aug 6, 2018 · 3 comments
Closed

Set depth clamp min/max from C++ and python code #2199

baptiste-mnh opened this issue Aug 6, 2018 · 3 comments

Comments

@baptiste-mnh
Copy link
Contributor

baptiste-mnh commented Aug 6, 2018

Hi,
I would like to set depth clamp min/max from my code without exporting a .json from the viewer and without decease of the depth quality.
Thanks!

I tried without success :
sensor.set_option(RS2_OPTION_MAX_DISTANCE, 1.f);

@AntoineWefit
Copy link

You can set the sensors options with that, from this file (I don't know if this is going to help) :

 static void change_sensor_option(const rs2::sensor& sensor, rs2_option option_type)
    {
        // Sensors usually have several options to control their properties
        //  such as Exposure, Brightness etc.

        // To control an option, use the following api:

        // First, verify that the sensor actually supports this option
        if (!sensor.supports(option_type))
        {
            std::cerr << "This option is not supported by this sensor" << std::endl;
            return;
        }

        // Each option provides its rs2::option_range to provide information on how it can be changed
        // To get the supported range of an option we do the following:

        std::cout << "Supported range for option " << option_type << ":" << std::endl;

        rs2::option_range range = sensor.get_option_range(option_type);
        float default_value = range.def;
        float maximum_supported_value = range.max;
        float minimum_supported_value = range.min;
        float difference_to_next_value = range.step;
        std::cout << "  Min Value     : " << minimum_supported_value << std::endl;
        std::cout << "  Max Value     : " << maximum_supported_value << std::endl;
        std::cout << "  Default Value : " << default_value << std::endl;
        std::cout << "  Step          : " << difference_to_next_value << std::endl;

        bool change_option = false;
        change_option = prompt_yes_no("Change option's value?");

        if (change_option)
        {
            std::cout << "Enter the new value for this option: ";
            float requested_value;
            std::cin >> requested_value;
            std::cout << std::endl;

            // To set an option to a different value, we can call set_option with a new value
            try
            {
                sensor.set_option(option_type, requested_value);
            }
            catch (const rs2::error& e)
            {
                // Some options can only be set while the camera is streaming,
                // and generally the hardware might fail so it is good practice to catch exceptions from set_option
                std::cerr << "Failed to set option " << option_type << ". (" << e.what() << ")" << std::endl;
            }
        }
}

@dorodnic
Copy link
Contributor

dorodnic commented Aug 6, 2018

Depth clamp controls for the D400 are exposed as part of "advanced mode" API, please take a look at python-rs400-advanced-mode-example.py, the relevant properties are part of advnc_mode.get_depth_table().

@baptiste-mnh
Copy link
Contributor Author

Thanks for your help, it works (also in C++).

The code (based on multicam exemple)

void DeviceWrapper::enable_device(Camera &camera, unsigned int export_flag) {
    std::string serial_number(camera.getSerial());
    std::lock_guard<std::mutex> lock(_mutex);

    if (_devices.find(serial_number) != _devices.end()) {
        std::cout << "Camera already enabled : " << serial_number << std::endl;
        return; //already in
    }
    // Create a pipeline from the given device
    rs2::pipeline p;
    rs2::config cfg;
    cfg.enable_device(serial_number);

    rs400::advanced_mode advanced_device(camera.getDevice());
    auto depth_table = advanced_device.get_depth_table();
    depth_table.depthClampMax = 1300; // 1m30 if depth unit at 0.001
    advanced_device.set_depth_table(depth_table);


    // Start the pipeline with the configuration
    rs2::pipeline_profile profile = p.start(cfg);

    //apply the chosen preset
    applyPresetFromFlag(preset_flag, camera.getDevice());

    camera.deviceContent = DeviceContent{{}, {}, p, profile, {}, {}};

    // Hold it internally
    _devices.emplace(serial_number, &(camera.deviceContent));
}

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

No branches or pull requests

4 participants