rs_frame_image.h
Go to the documentation of this file.
1 // License: Apache 2.0. See LICENSE file in root directory.
2 // Copyright(c) 2019 Intel Corporation. All Rights Reserved.
3 
4 #pragma once
5 
6 
7 /*
8  This encapsulates data needed for a dlib-compatible image that originates
9  in a librealsense color frame.
10 
11  The data from the color frame is not copied, and so this object should not
12  live beyond the lifetime of the frame.
13 */
14 template <
15  typename pixel_type, // The dlib type, e.g. rgb_pixel
16  int RS_FORMAT // The corresponding RS2_FORMAT, e.g. RS2_FORMAT_RGB8
17 >
19 {
20  void * _data;
21  long _nr;
22  long _nc;
23  rs2::video_frame _frame; // To keep the frame data alive
24 
25 public:
27  : _data( const_cast< void * >( f.get_data() ))
28  , _nc( f.get_width() )
29  , _nr( f.get_height() )
30  , _frame( f )
31  {
32  if( f.get_profile().format() != RS_FORMAT )
33  {
34  throw std::runtime_error( "unsupported Frame format" );
35  }
36  }
37 
38  rs_frame_image() : _data( nullptr ), _nr( 0 ), _nc( 0 ) {}
39 
40  size_t size() const { return static_cast<size_t>(_nr *_nc); }
41  void * data() { return _data; }
42  void const * data() const { return _data; }
43 
44  long nr() const { return _nr; }
45  long nc() const { return _nc; }
46  long width_step() const { return _nc * sizeof( pixel_type ); }
47 
48  pixel_type const * operator[]( unsigned const row ) const
49  {
50  return reinterpret_cast< const pixel_type * >( _data + width_step() * row );
51  }
52 
53  rs_frame_image & operator=( const rs_frame_image & ) = default;
54 };
55 
56 
90 namespace dlib
91 {
92 
93  // Define the global functions that make rs_frame_image a proper "generic image" according to
94  // $(DLIB_DIR)/image_processing/generic_image.h
95  // These are all template specializations for existing classes/structs/functions to adapt to the
96  // new class rs_frame_image that we defined above.
97  template <typename T, int RS>
98  struct image_traits< rs_frame_image< T, RS > >
99  {
100  typedef T pixel_type;
101  };
102 
103  template <typename T, int RS>
104  inline long num_rows( const rs_frame_image<T,RS>& img ) { return img.nr(); }
105  template <typename T, int RS>
106  inline long num_columns( const rs_frame_image<T,RS>& img ) { return img.nc(); }
107 
108  template <typename T, int RS>
109  inline void* image_data(
111  )
112  {
113  return img.data();
114  }
115 
116  template <typename T, int RS>
117  inline const void* image_data(
119  )
120  {
121  return img.data();
122  }
123 
124  template <typename T, int RS>
125  inline long width_step(
127  )
128  {
129  return img.width_step();
130  }
131 }
132 
long width_step() const
rs_frame_image(rs2::video_frame const &f)
const void * image_data(const rs_frame_image< T, RS > &img)
GLenum GLenum GLsizei void * row
typedef void(APIENTRY *GLDEBUGPROC)(GLenum source
rs_frame_image & operator=(const rs_frame_image &)=default
stream_profile get_profile() const
Definition: rs_frame.hpp:557
GLdouble f
long num_rows(const rs_frame_image< T, RS > &img)
long num_columns(const rs_frame_image< T, RS > &img)
size_t size() const
void const * data() const
GLint void * img
pixel_type const * operator[](unsigned const row) const
rs2::video_frame _frame
rs2_format format() const
Definition: rs_frame.hpp:44
long nr() const
long nc() const


librealsense2
Author(s): Sergey Dorodnicov , Doron Hirshberg , Mark Horn , Reagan Lopez , Itay Carpis
autogenerated on Mon May 3 2021 02:47:40