Skip to content

Commit

Permalink
pyrealdds.image_msg.data as a memoryview; fps.py --save-frames
Browse files Browse the repository at this point in the history
  • Loading branch information
maloel committed Oct 20, 2024
1 parent 473609c commit f5f50a7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion third-party/realdds/py/pyrealdds.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,7 @@ PYBIND11_MODULE(NAME, m) {
.def_static( "create_topic", &image_msg::create_topic )
.def_property(
"data",
[]( image_msg const & self ) { return self.raw().data(); },
[]( image_msg const & self ) { return py::memoryview::from_memory( self.raw().data().data(), self.raw().data().size() ); },
[]( image_msg & self, std::vector< uint8_t > bytes ) { self.raw().data( std::move( bytes ) ); } )
.def_property( "width", &image_msg::width, &image_msg::set_width )
.def_property( "height", &image_msg::height, &image_msg::set_height )
Expand Down
5 changes: 5 additions & 0 deletions third-party/realdds/scripts/fps.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
args.add_argument( '--debug', action='store_true', help='enable debug mode' )
args.add_argument( '--quiet', action='store_true', help='No output; just the minimum FPS as a number' )
args.add_argument( '--debug-frames', action='store_true', help='Output frame signatures as we get them' )
args.add_argument( '--save-frames', action='store_true', help='Save each image data on disk, as <stream-name>_<frame-number>' )
args.add_argument( '--device', metavar='<path>', required=True, help='the topic root for the device' )
def time_arg(x):
t = int(x)
Expand Down Expand Up @@ -97,6 +98,10 @@ def on_image( stream, image, sample ):
global n_stream_frames, capturing
if capturing:
n_stream_frames[stream.name()] += 1
if args.save_frames:
filename = f'{stream.name().lower()}_{image.frame_id or n_stream_frames[stream.name()]}'
with open( filename, 'wb' ) as f:
f.write( image.data )

fps = args.fps
width = args.res[0]
Expand Down

0 comments on commit f5f50a7

Please sign in to comment.