Skip to content

Enable rotate frames for RGB camera - #13733

Merged
OhadMeir merged 5 commits into
realsenseai:developmentfrom
noacoohen:rotation_filter_for_color_frames
Feb 10, 2025
Merged

Enable rotate frames for RGB camera#13733
OhadMeir merged 5 commits into
realsenseai:developmentfrom
noacoohen:rotation_filter_for_color_frames

Conversation

@noacoohen

@noacoohen noacoohen commented Feb 3, 2025

Copy link
Copy Markdown
Contributor

Tracked on RSDSO-19999

@noacoohen
noacoohen requested review from Nir-Az and OhadMeir February 3, 2025 06:46
@Nir-Az

Nir-Az commented Feb 3, 2025

Copy link
Copy Markdown
Collaborator

Please check CI failures

Comment thread src/proc/rotation-filter.cpp Outdated

auto src = f.as< rs2::video_frame >();
rs2::stream_profile profile = f.get_profile();
auto format = f.get_profile().format();

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

We already have the profile from 1 line above, you can do profile.format() here right?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed

Comment thread src/proc/rotation-filter.cpp Outdated
if( ! frame || frame.is< rs2::frameset >() )
return false;
auto type = frame.get_profile().stream_type();
/// change extrinsics

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

What is this comment for?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Removed

return false;
auto type = frame.get_profile().stream_type();
/// change extrinsics
for( auto & stream_type : _streams_to_rotate ){

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

No need for { } for one line if/for. Where you are using, { should be placed on a new line.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed

register_option( RS2_OPTION_ROTATION, rotation_control );
}

rotation_filter::rotation_filter( std::vector< rs2_stream > streams_to_rotate )

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code duplication. Is default constructor needed? If so have it call the other constructor with an empty vector {}.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed

Comment thread src/proc/rotation-filter.cpp Outdated
if( ! strong_rotation_control )
return;

std::lock_guard< std::mutex > lock( _mutex );

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Lock after validating if valid value.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done

Comment thread src/proc/rotation-filter.cpp Outdated

rs2::frame rotation_filter::process_frame(const rs2::frame_source& source, const rs2::frame& f)
{
if( _value == rotation_default_val )

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should lock _mutex or place _value in a local variable and use it all over this function.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Same for update_output_profile and rotate_frame.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done

Comment thread src/proc/rotation-filter.cpp Outdated
{
if( _value == 90 || _value == -90 )
{
LOG_ERROR( "Rotating YUYV format is disabled for 90 or -90 degrees" );

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Do we intend to support this at a future PR?

@noacoohen noacoohen Feb 6, 2025

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

No support for 90 and 270 degrees rotation for YUYV format

Comment thread src/proc/rotation-filter.cpp Outdated
}


void rotation_filter::rotate_YUYV_frame(uint8_t* const out, const uint8_t* source, int width, int height) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please use formatter. Spaces, { at new line, etc...

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done

Comment thread src/proc/rotation-filter.cpp Outdated
break;
}
case 3: {
rotate_frame< 3 >( static_cast< uint8_t * >( const_cast< void * >( tgt.get_data() ) ),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Seems that using bpp as a normal function parameter instead of template will reduce code duplication.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done

Comment thread src/proc/rotation-filter.cpp Outdated
if (auto tgt = prepare_target_frame(f, source, tgt_type))
{
switch( bpp )
if( format == RS2_FORMAT_YUYV && ( _value == 90 || _value == -90 ) )

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should also use local_value

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done

Comment thread src/proc/rotation-filter.cpp Outdated
@@ -193,33 +188,64 @@ namespace librealsense {
int height_out = ( _value == 90 || _value == -90 ) ? width : height; // rotate by 180 will keep the values as is

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should use value, not the member

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done

Comment thread src/proc/rotation-filter.cpp Outdated

// Determine output index based on rotation angle
size_t out_index;
if( _value == 90 )

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Same in this if/else, use variable value

Comment thread src/proc/rotation-filter.cpp Outdated
throw invalid_value_exception( rsutils::string::from()
<< "Unsupported rotation scale " << val << " is out of range." );

std::lock_guard< std::mutex > lock( _mutex );

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can remove the lock, using local variable elsewhere in the file

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Removed

@OhadMeir
OhadMeir merged commit cbc6902 into realsenseai:development Feb 10, 2025
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

Successfully merging this pull request may close these issues.

3 participants