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

Add new post processing filter - rotation filter #13499

Merged
merged 13 commits into from
Nov 18, 2024
5 changes: 3 additions & 2 deletions common/subdevice-model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,6 @@ namespace rs2
}
catch (...) {}

auto filters = s->get_recommended_filters();

for (auto&& f : s->get_recommended_filters())
{
auto shared_filter = std::make_shared<filter>(f);
Expand All @@ -215,6 +213,9 @@ namespace rs2
model->enable(false);
}

if( shared_filter->is< rotation_filter >() )
model->enable( false );

if (shared_filter->is<threshold_filter>())
{
if (s->supports(RS2_CAMERA_INFO_PRODUCT_ID))
Expand Down
33 changes: 27 additions & 6 deletions examples/post-processing/rs-post-processing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ int main(int argc, char * argv[]) try

// Declare filters
rs2::decimation_filter dec_filter; // Decimation - reduces depth frame density
rs2::rotation_filter rot_filter; // Rotation - rotates frames
rs2::threshold_filter thr_filter; // Threshold - removes values outside recommended range
rs2::spatial_filter spat_filter; // Spatial - edge-preserving spatial smoothing
rs2::temporal_filter temp_filter; // Temporal - reduces temporal noise
Expand All @@ -85,6 +86,7 @@ int main(int argc, char * argv[]) try

// The following order of emplacement will dictate the orders in which filters are applied
filters.emplace_back("Decimate", dec_filter);
filters.emplace_back( "Rotate", rot_filter );
Nir-Az marked this conversation as resolved.
Show resolved Hide resolved
filters.emplace_back("Threshold", thr_filter);
filters.emplace_back(disparity_filter_name, depth_to_disparity);
filters.emplace_back("Spatial", spat_filter);
Expand Down Expand Up @@ -115,11 +117,12 @@ int main(int argc, char * argv[]) try
/* Apply filters.
The implemented flow of the filters pipeline is in the following order:
1. apply decimation filter
2. apply threshold filter
3. transform the scene into disparity domain
4. apply spatial filter
5. apply temporal filter
6. revert the results back (if step Disparity filter was applied
2. apply rotation filter
3. apply threshold filter
4. transform the scene into disparity domain
5. apply spatial filter
6. apply temporal filter
7. revert the results back (if step Disparity filter was applied
to depth domain (each post processing block is optional and can be applied independantly).
*/
bool revert_disparity = false;
Expand Down Expand Up @@ -269,11 +272,29 @@ void render_ui(float w, float h, std::vector<filter_options>& filters)
ImGui::Checkbox(filter.filter_name.c_str(), &tmp_value);
filter.is_enabled = tmp_value;
ImGui::PopStyleColor();


if( filter.filter_name == "Rotate" ) // Combo box specifically for the rotation filter
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder why rotate is the only one needs special handling,
Is it because we added a special option for it?
What is the value of RS2_OPTION_FILTER_MAGNITUDE for other filters?
Is it always 1,2,3,4 ?
If not maybe we could have used it for 90/-90/180?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because the rest of the options use filter_slider_ui which is set up for continuous values, but we need discrete 90-degree increments.

{
offset_y += elements_margin;
ImGui::PushItemWidth( w / 4 );
ImGui::SetCursorPos( { offset_x, offset_y } );
static const char * rotation_modes[] = { "0", "90", "180", "270" };
static int current_rotation_mode = 0;
if( ImGui::Combo( "Rotation Angle", &current_rotation_mode, rotation_modes, 4 ) )
{
float rotation_value = std::stof( rotation_modes[current_rotation_mode] );
filter.supported_options[RS2_OPTION_ROTATION].value = rotation_value;

if (filter.supported_options.size() == 0)
// Set the filter's option using the new value
filter.filter.set_option( RS2_OPTION_ROTATION, rotation_value );
}
}
if( filter.supported_options.size() == 0 )
{
offset_y += elements_margin;
}

// Draw a slider for each of the filter's options
for (auto& option_slider_pair : filter.supported_options)
{
Expand Down
1 change: 1 addition & 0 deletions include/librealsense2/h/rs_option.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ extern "C" {
RS2_OPTION_SOC_PVT_TEMPERATURE, /**< Temperature of PVT SOC */
RS2_OPTION_GYRO_SENSITIVITY,/**< Control of the gyro sensitivity level, see rs2_gyro_sensitivity for values */
RS2_OPTION_REGION_OF_INTEREST,/**< The rectangular area used from the streaming profile */
RS2_OPTION_ROTATION,/**Rotates frames*/
Nir-Az marked this conversation as resolved.
Show resolved Hide resolved
RS2_OPTION_COUNT /**< Number of enumeration values. Not a valid input: intended to be used in for-loops. */
} rs2_option;

Expand Down
6 changes: 6 additions & 0 deletions include/librealsense2/h/rs_processing.h
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,12 @@ rs2_processing_block* rs2_create_align(rs2_stream align_to, rs2_error** error);
*/
rs2_processing_block* rs2_create_decimation_filter_block(rs2_error** error);

/**
* Creates post-processing filter block. This block accepts frames and applies rotation filter
* \param[out] error if non-null, receives any error that occurs during this call, otherwise, errors are ignored
*/
rs2_processing_block * rs2_create_rotation_filter_block( rs2_error ** error );

/**
* Creates Depth post-processing filter block. This block accepts depth frames, applies temporal filter
* \param[out] error if non-null, receives any error that occurs during this call, otherwise, errors are ignored
Expand Down
1 change: 1 addition & 0 deletions include/librealsense2/h/rs_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ typedef enum rs2_extension
RS2_EXTENSION_SOFTWARE_DEVICE,
RS2_EXTENSION_SOFTWARE_SENSOR,
RS2_EXTENSION_DECIMATION_FILTER,
RS2_EXTENSION_ROTATION_FILTER,
RS2_EXTENSION_THRESHOLD_FILTER,
RS2_EXTENSION_DISPARITY_FILTER,
RS2_EXTENSION_SPATIAL_FILTER,
Expand Down
42 changes: 42 additions & 0 deletions include/librealsense2/hpp/rs_processing.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -851,6 +851,48 @@ namespace rs2
}
};

class rotation_filter : public filter
{
public:
/**
* Create rotation filter
* Rotation filter performs rotation of the frames
*/
rotation_filter()
: filter( init(), 1 )
Nir-Az marked this conversation as resolved.
Show resolved Hide resolved
{
}

rotation_filter( float value )
: filter( init(), 1 )
{
set_option( RS2_OPTION_ROTATION, value );
}

rotation_filter( filter f )
: filter( f )
{
rs2_error * e = nullptr;
if( ! rs2_is_processing_block_extendable_to( f.get(), RS2_EXTENSION_ROTATION_FILTER, &e ) && ! e )
{
_block.reset();
}
error::handle( e );
}

private:
friend class context;

std::shared_ptr< rs2_processing_block > init()
{
rs2_error * e = nullptr;
auto block = std::shared_ptr< rs2_processing_block >( rs2_create_rotation_filter_block( &e ),
rs2_delete_processing_block );
error::handle( e );
return block;
}
};

class temporal_filter : public filter
{
public:
Expand Down
2 changes: 2 additions & 0 deletions src/media/ros/ros_writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Copyright(c) 2019 Intel Corporation. All Rights Reserved.

#include "proc/decimation-filter.h"
#include "proc/rotation-filter.h"
#include "proc/threshold.h"
#include "proc/disparity-transform.h"
#include "proc/spatial-filter.h"
Expand Down Expand Up @@ -513,6 +514,7 @@ namespace librealsense
RETURN_IF_EXTENSION(block, RS2_EXTENSION_HOLE_FILLING_FILTER);
RETURN_IF_EXTENSION(block, RS2_EXTENSION_HDR_MERGE);
RETURN_IF_EXTENSION(block, RS2_EXTENSION_SEQUENCE_ID_FILTER);
RETURN_IF_EXTENSION(block, RS2_EXTENSION_ROTATION_FILTER);

#undef RETURN_IF_EXTENSION

Expand Down
2 changes: 2 additions & 0 deletions src/proc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ target_sources(${LRS_TARGET}
"${CMAKE_CURRENT_LIST_DIR}/synthetic-stream.cpp"
"${CMAKE_CURRENT_LIST_DIR}/syncer-processing-block.cpp"
"${CMAKE_CURRENT_LIST_DIR}/decimation-filter.cpp"
"${CMAKE_CURRENT_LIST_DIR}/rotation-filter.cpp"
"${CMAKE_CURRENT_LIST_DIR}/spatial-filter.cpp"
"${CMAKE_CURRENT_LIST_DIR}/temporal-filter.cpp"
"${CMAKE_CURRENT_LIST_DIR}/hdr-merge.cpp"
Expand Down Expand Up @@ -49,6 +50,7 @@ target_sources(${LRS_TARGET}
"${CMAKE_CURRENT_LIST_DIR}/occlusion-filter.h"
"${CMAKE_CURRENT_LIST_DIR}/synthetic-stream.h"
"${CMAKE_CURRENT_LIST_DIR}/decimation-filter.h"
"${CMAKE_CURRENT_LIST_DIR}/rotation-filter.h"
"${CMAKE_CURRENT_LIST_DIR}/spatial-filter.h"
"${CMAKE_CURRENT_LIST_DIR}/temporal-filter.h"
"${CMAKE_CURRENT_LIST_DIR}/hdr-merge.h"
Expand Down
Loading
Loading