Skip to content

Commit

Permalink
add rotate frame
Browse files Browse the repository at this point in the history
  • Loading branch information
noacoohen committed Oct 16, 2024
1 parent 52c8db2 commit af35428
Show file tree
Hide file tree
Showing 14 changed files with 824 additions and 1 deletion.
12 changes: 12 additions & 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,
RS2_OPTION_COUNT /**< Number of enumeration values. Not a valid input: intended to be used in for-loops. */
} rs2_option;

Expand Down Expand Up @@ -303,6 +304,17 @@ extern "C" {
} rs2_gyro_sensitivity;
const char * rs2_gyro_sensitivity_to_string( rs2_gyro_sensitivity mode );

/** \brief values for RS2_OPTION_ROTATION option. */
//typedef enum rs2_rotation
//{
// RS2_ROTATION_90_DEG_LEFT = 0,
// RS2_ROTATION_0_DEG = 1,
// RS2_ROTATION_90_DEG_RIGHT = 2,
// RS2_ROTATION_180_DEG = 3,
// RS2_ROTATION_COUNT
//} rs2_rotation;
//const char * rs2_rotation_to_string( rs2_rotation mode );

/**
* check if an option is read-only
* \param[in] options the options container
Expand Down
8 changes: 8 additions & 0 deletions include/librealsense2/h/rs_processing.h
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,14 @@ 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 Depth post-processing filter block. This block accepts depth frames, applies decimation filter and plots
* modified prames Note that due to the modifiedframe size, the decimated frame repaces the original one \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
50 changes: 50 additions & 0 deletions include/librealsense2/hpp/rs_processing.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -851,6 +851,56 @@ namespace rs2
}
};

class rotation_filter : public filter
{
public:
/**
* Create rotation filter
* Rotation filter performs rotation of the frames
*/
rotation_filter()
: filter( init(), 1 )
{
}
/**
* Create rotation filter
* Rotation filter performs rotation of the frames
* \param[in] magnitude - number of filter iterations.
*/
//rotation_filter( float magnitude )
// : filter( init(), 1 )
// {
// set_option( RS2_OPTION_FILTER_MAGNITUDE, magnitude );
// }

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 );

// Redirect options API to the processing block
// options::operator=(this);

return block;
}
};

class temporal_filter : public filter
{
public:
Expand Down
56 changes: 56 additions & 0 deletions src/ds/d400/d400-options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -480,5 +480,61 @@ namespace librealsense
}




// void librealsense::rotation_option::set( float value )
// {
// auto strong = _sensor.lock();
// if( ! strong )
// throw invalid_value_exception( "Sensor is not alive for setting" );

// //if( strong->is_streaming() )
// // throw invalid_value_exception( "setting this option during streaming is not allowed!" );

// if( ! is_valid( value ) )
// throw invalid_value_exception( "set(rotation) failed! Invalid rotation request "
// + std::to_string( value ) );

// _value = value;
// }

// float librealsense::rotation_option::query() const
// {
// return _value;
// }


// const char * librealsense::rotation_option::get_value_description( float val ) const
// {
// switch( static_cast< int >( val ) )
// {
// case RS2_ROTATION_90_DEG_LEFT: {
// return "-90 Deg";
// }
// case RS2_ROTATION_0_DEG: {
// return "0 Deg";
// }
// case RS2_ROTATION_90_DEG_RIGHT: {
// return "90 Deg";
// }
// case RS2_ROTATION_180_DEG: {
// return "180 Deg";
// }
// default:
// throw invalid_value_exception( "value not found" );
// }
// }

// const char * librealsense::rotation_option::get_description() const
// {
// return "rotate frames";
// }

// bool librealsense::rotation_option::is_read_only() const
// {
// if( auto strong = _sensor.lock() )
// return strong->is_opened();
// return false;
// }
}

32 changes: 31 additions & 1 deletion src/ds/d400/d400-options.h
Original file line number Diff line number Diff line change
Expand Up @@ -189,4 +189,34 @@ namespace librealsense
std::function< void( const option & ) > _record_action = []( const option & ) {};

};
}

/* class sensor_base;
class rotation_option : public option_base
{
public:
rotation_option( const std::weak_ptr< sensor_base > & sensor, const option_range & opt_range )
: option_base( opt_range )
, _value( opt_range.def )
, _sensor( sensor )
{
set( _value );
}
virtual ~rotation_option() = default;
virtual void set( float value ) override;
virtual float query() const override;
virtual bool is_enabled() const override { return true; }
virtual const char * get_description() const override;
const char * get_value_description( float value ) const override;
virtual void enable_recording( std::function< void( const option & ) > record_action ) override
{
_record_action = record_action;
}
virtual bool is_read_only() const override;
private:
float _value;
std::weak_ptr< sensor_base > _sensor;
std::function< void( const option & ) > _record_action = []( const option & ) {
};
};*/
}
1 change: 1 addition & 0 deletions src/ds/ds-device-common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "proc/spatial-filter.h"
#include "proc/colorizer.h"
#include "proc/temporal-filter.h"
#include "proc/rotation-filter.h"

#include <src/backend.h>
#include <librealsense2/h/rs_internal.h>
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

0 comments on commit af35428

Please sign in to comment.