User's Manual

Post Processing
29 User Guide
** Applicable for stereo-based depth cameras (D4XX).
Note: Even though the filters order in the demos is predefined, each filter is controlled
individually and can be toggled on/off at run-time.
Demos and tools that have the post-processing code blocks:
1. RealSense-Viewer
2. Depth Quality Tool
3. Post-Processing
Filter initialization and activation flows:
// Establishing a frame_queue object for each processing block that
will receive the processed frames
rs2_frame_queue* decimated_queue = rs2_create_frame_queue(1, NULL);
rs2_frame_queue* spatial_queue = rs2_create_frame_queue(1, NULL);
...
// Creating processing blocks/ filters
rs2_processing_block* decimation_filter =
rs2_create_decimation_filter_block(NULL);
rs2_processing_block* spatial_filter =
rs2_create_spatial_filter_block(NULL);
...
// Direct the output of the filters to a dedicated queue
rs2_start_processing_queue(decimation_filter, decimated_queue, NULL);
rs2_start_processing_queue(spatial_filter, spatial_queue, NULL);
...
// Get depth frame from the device
rs2_frame* depth_frame = ...
// Apply decimation filter
rs2_process_frame(decimation_filter, depth_frame, NULL);
rs2_frame* decimated_frame = rs2_wait_for_frame(decimated_queue, 5000,
NULL);
// Inject the decimated frame to spatial filter
rs2_process_frame(spatial_filter, decimated_frame, NULL);
// Get the filtered frame
rs2_frame* spatial_filter_frame = rs2_wait_for_frame(spatial_queue,
5000, NULL);
// Use the filtered data
...
// Control filter options
rs2_set_option((rs2_options*)decimation_filter,
RS2_OPTION_FILTER_MAGNITUDE, 3, NULL);
rs2_set_option((rs2_options*)spatial_filter,
RS2_OPTION_FILTER_SMOOTH_ALPHA, 0.5f, NULL);
Using C++ API
// Streaming initialization
rs2::pipeline pipe;