IntelRealSense / librealsense

Intel® RealSense™ SDK
https://www.intelrealsense.com/
Apache License 2.0
7.44k stars 4.8k forks source link

Setting options, histogram equalization or max/min distance #1674

Closed stekla79 closed 6 years ago

stekla79 commented 6 years ago
Required Info
Camera Model { D400 }
Firmware Version 05.09.09.02
Operating System & Version {Win (8.1/10)
Platform PC
SDK Version { 2.0 }

Is there any way to set RS2_OPTION_HISTOGRAM_EQUALIZATION_ENABLED or RS2_OPTION_MIN_DISTANCE in C++?

I would like to get a fixed scale of the depth visualisation from the depth frame. I have loaded a preset json file I created in Realsense Viewer and are trying to set the options in the code but it throws a wrong_api_call_sequence_error.

When looking at the settable options querying the sensor it displays the following: 32: Histogram Equalization Enabled is not supported 33: Min Distance is not supported 34: Max Distance is not supported

I can alter other options that are supported like RS2_OPTION_EMITTER_ENABLED for instance.

Below is some code

//Contruct a pipeline which abstracts the device
rs2::pipeline pipe;

//Create a configuration for configuring the pipeline with a non default profile
rs2::config cfg;

//Add desired streams to configuration
cfg.enable_stream(RS2_STREAM_COLOR, 640, 480, RS2_FORMAT_BGR8, 6);
cfg.enable_stream(RS2_STREAM_INFRARED, 640, 480, RS2_FORMAT_Y8, 6);
cfg.enable_stream(RS2_STREAM_DEPTH, 640, 480, RS2_FORMAT_Z16, 6);

rs2::context cxt;
auto device = cxt.query_devices().back();
auto advanced_mode_dev = device.as<rs400::advanced_mode>();
if (device.is<rs400::advanced_mode>())
    if (!advanced_mode_dev.is_enabled())
        advanced_mode_dev.toggle_advanced_mode(true);

std::ifstream t("D:\\preset.json");
std::string preset_json((std::istreambuf_iterator<char>(t)),
std::istreambuf_iterator<char>());
advanced_mode_dev.load_json(preset_json);

rs2::pipeline_profile pipe_profile = cfg.resolve(pipe);
std::vector<rs2::sensor> sensors = device.query_sensors();
for (rs2::sensor element : sensors) {
    std::string module_name = element.get_info(RS2_CAMERA_INFO_NAME);

    if ("Stereo Module" == module_name) {
        element.set_option(rs2_option::RS2_OPTION_HISTOGRAM_EQUALIZATION_ENABLED, 0.f);
    }
    get_sensor_option(element);
}

rs2::pipeline_profile profile = pipe.start(cfg);

What I would like to accomplish is a fixed color on the depth map for background subtraction in OpenCV. Maybe there is a better way? When I use the colorizer the intensity of the color scheme changes when a object gets closer to the camera.

dorodnic commented 6 years ago

Hi @stekla79 Histogram equalization options are not really part of the sensor, it is all done in software by the colorizer class. As a result, these options are configurable on the colorizer object itself:

colorizer c;
c.set_option(RS2_OPTION_HISTOGRAM_EQUALIZATION_ENABLED, 0.f);
//...
c.colorize(depth_frame);

At the moment, the viewer is not saving post-processing settings to JSON (since originally the file format was designed to capture only hardware settings). We are planning to extend the Viewer to include these.

dorodnic commented 6 years ago

Hi @stekla79 Do you need further assistance?

stekla79 commented 6 years ago

No, you solved my problem!

Thanks a lot!