Skip to content

Commit 8e84dba

Browse files
committed
Get color frame according to index (there can be more than one)
1 parent 5bab736 commit 8e84dba

File tree

2 files changed

+21
-6
lines changed

2 files changed

+21
-6
lines changed

common/post-processing-filters.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,10 @@ void post_processing_filters::map_id_frameset_to_frameset(rs2::frameset first, r
131131
{
132132
second_f = second.get_infrared_frame(f.get_profile().stream_index());
133133
}
134+
else if( f.get_profile().stream_type() == RS2_STREAM_COLOR )
135+
{
136+
second_f = second.get_color_frame( f.get_profile().stream_index() );
137+
}
134138
else
135139
{
136140
second_f = second.first_or_default(f.get_profile().stream_type());

include/librealsense2/hpp/rs_frame.hpp

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1135,16 +1135,27 @@ namespace rs2
11351135
* Retrieve the first color frame, if no frame is found, search for the color frame from IR stream. If one still can't be found, return an empty frame instance.
11361136
* \return video_frame - first found color frame.
11371137
*/
1138-
video_frame get_color_frame() const
1138+
video_frame get_color_frame( const size_t index = 0 ) const
11391139
{
1140-
auto f = first_or_default(RS2_STREAM_COLOR);
1140+
frame f;
1141+
1142+
foreach_rs( [&f, index]( const frame & frm ) {
1143+
if( frm.get_profile().stream_type() == RS2_STREAM_COLOR &&
1144+
frm.get_profile().stream_index() == index )
1145+
f = frm;
1146+
} );
11411147

1142-
if (!f)
1148+
if( ! f )
11431149
{
1144-
auto ir = first_or_default(RS2_STREAM_INFRARED);
1145-
if (ir && ir.get_profile().format() == RS2_FORMAT_RGB8)
1146-
f = ir;
1150+
// Color frame can also come from infrared sensor
1151+
foreach_rs( [&f, index]( const frame & frm ) {
1152+
if( frm.get_profile().stream_type() == RS2_STREAM_INFRARED &&
1153+
frm.get_profile().stream_index() == index &&
1154+
frm.get_profile().format() == RS2_FORMAT_RGB8 )
1155+
f = frm;
1156+
} );
11471157
}
1158+
11481159
return f;
11491160
}
11501161

0 commit comments

Comments
 (0)