RealSense Cross Platform API
RealSense Cross-platform API
Loading...
Searching...
No Matches
rs_frame.hpp
Go to the documentation of this file.
1// License: Apache 2.0. See LICENSE file in root directory.
2// Copyright(c) 2017 RealSense, Inc. All Rights Reserved.
3
4#ifndef LIBREALSENSE_RS2_FRAME_HPP
5#define LIBREALSENSE_RS2_FRAME_HPP
6
7#include "rs_types.hpp"
8
9namespace rs2
10{
11 class frame_source;
12 class frame_queue;
13 class syncer;
14 class processing_block;
15 class pointcloud;
16 class sensor;
17 class frame;
18 class pipeline_profile;
19 class points;
21
23 {
24 public:
28 stream_profile() : _profile(nullptr) {}
29
34 int stream_index() const { return _index; }
39 rs2_stream stream_type() const { return _type; }
44 rs2_format format() const { return _format; }
49 int fps() const { return _framerate; }
54 int unique_id() const { return _uid; }
55
64 {
65 rs2_error* e = nullptr;
66 auto ref = rs2_clone_stream_profile(_profile, type, index, format, &e);
68 stream_profile res(ref);
69 res._clone = std::shared_ptr<rs2_stream_profile>(ref, [](rs2_stream_profile* r) { rs2_delete_stream_profile(r); });
70
71 return res;
72 }
73
79 bool operator==(const stream_profile& rhs)
80 {
81 return stream_index() == rhs.stream_index() &&
82 stream_type() == rhs.stream_type() &&
83 format() == rhs.format() &&
84 fps() == rhs.fps();
85 }
86
91 template<class T>
92 bool is() const
93 {
94 T extension(*this);
95 return extension;
96 }
97
102 template<class T>
103 T as() const
104 {
105 T extension(*this);
106 return extension;
107 }
108
113 std::string stream_name() const
114 {
115 rs2_error * e = nullptr;
116 std::string name = rs2_get_stream_profile_name( _profile, &e );
117
118 if( name.empty() )
119 {
120 std::stringstream ss;
122 if( stream_index() != 0 )
123 ss << " " << stream_index();
124 name = ss.str();
125 }
126
127 return name;
128 }
129
134 bool is_default() const { return _default; }
135
140 operator bool() const { return _profile != nullptr; }
141
146 const rs2_stream_profile* get() const { return _profile; }
147
158 {
159 rs2_error* e = nullptr;
160 rs2_extrinsics res;
161 rs2_get_extrinsics(get(), to.get(), &res, &e);
162 error::handle(e);
163 return res;
164 }
165
172 {
173 rs2_error* e = nullptr;
174 rs2_register_extrinsics(get(), to.get(), extrinsics, &e);
175 error::handle(e);
176 }
177
178 bool is_cloned() { return bool(_clone); }
179 explicit stream_profile(const rs2_stream_profile* profile) : _profile(profile)
180 {
181 rs2_error* e = nullptr;
183 error::handle(e);
184
186 error::handle(e);
187
188 }
189 operator const rs2_stream_profile*() { return _profile; }
190 explicit operator std::shared_ptr<rs2_stream_profile>() { return _clone; }
191
192 protected:
193 friend class rs2::sensor;
194 friend class rs2::frame;
197
199 std::shared_ptr<rs2_stream_profile> _clone;
200
201 int _index = 0;
202 int _uid = 0;
203 int _framerate = 0;
206
207 bool _default = false;
208 };
209
211 {
212 public:
214
220 : stream_profile(sp)
221 {
222 rs2_error* e = nullptr;
223 if (!sp || (rs2_stream_profile_is(sp.get(), RS2_EXTENSION_VIDEO_PROFILE, &e) == 0 && !e))
224 {
225 _profile = nullptr;
226 }
227 error::handle(e);
228
229 if (_profile)
230 {
231 rs2_get_video_stream_resolution(_profile, &_width, &_height, &e);
232 error::handle(e);
233 }
234 }
235
236 int width() const
237 {
238 return _width;
239 }
240
241 int height() const
242 {
243 return _height;
244 }
245
250 {
251 rs2_error* e = nullptr;
252 rs2_intrinsics intr;
254 error::handle(e);
255 return intr;
256 }
257
258 bool operator==(const video_stream_profile& other) const
259 {
260 return (((stream_profile&)*this)==other &&
261 width() == other.width() &&
262 height() == other.height());
263 }
264
266
277 stream_profile clone(rs2_stream type, int index, rs2_format format, int width, int height, const rs2_intrinsics& intr) const
278 {
279 rs2_error* e = nullptr;
280 auto ref = rs2_clone_video_stream_profile(_profile, type, index, format, width, height, &intr, &e);
281 error::handle(e);
282 stream_profile res(ref);
283 res._clone = std::shared_ptr<rs2_stream_profile>(ref, [](rs2_stream_profile* r) { rs2_delete_stream_profile(r); });
284
285 return res;
286 }
287 private:
288 int _width = 0;
289 int _height = 0;
290 };
291
292
294 {
295 public:
301 : stream_profile(sp)
302 {
303 rs2_error* e = nullptr;
304 if (!sp || (rs2_stream_profile_is(sp.get(), RS2_EXTENSION_MOTION_PROFILE, &e) == 0 && !e))
305 {
306 _profile = nullptr;
307 }
308 error::handle(e);
309 }
310
316 {
317 rs2_error* e = nullptr;
320 error::handle(e);
321 return intrin;
322 }
323 };
324
326 {
327 public:
333 : stream_profile(sp)
334 {
335 rs2_error* e = nullptr;
336 if (!sp || (rs2_stream_profile_is(sp.get(), RS2_EXTENSION_POSE_PROFILE, &e) == 0 && !e))
337 {
338 _profile = nullptr;
339 }
340 error::handle(e);
341 }
342 };
343
345 {
346 public:
348 : stream_profile(sp)
349 {
350 rs2_error* e = nullptr;
351 if (!sp || (rs2_stream_profile_is(sp.get(), RS2_EXTENSION_PERCEPTION_PROFILE, &e) == 0 && !e))
352 {
353 _profile = nullptr;
354 }
355 error::handle(e);
356 }
357 };
358
363 {
364 public:
365 virtual rs2::frame process(rs2::frame frame) const = 0;
366 virtual ~filter_interface() = default;
367 };
368
369 class frame
370 {
371 public:
375 frame() : frame_ref(nullptr) {}
380 frame(rs2_frame* ref) : frame_ref(ref)
381 {
382#ifdef _DEBUG
383 if (ref)
384 {
385 rs2_error* e = nullptr;
386 auto r = rs2_get_frame_number(ref, &e);
387 if (!e)
388 frame_number = r;
389 auto s = rs2_get_frame_stream_profile(ref, &e);
390 if (!e)
391 profile = stream_profile(s);
392 }
393 else
394 {
395 frame_number = 0;
396 profile = stream_profile();
397 }
398#endif
399 }
400
404 frame(frame&& other) noexcept : frame_ref(other.frame_ref)
405 {
406 other.frame_ref = nullptr;
407#ifdef _DEBUG
408 frame_number = other.frame_number;
409 profile = other.profile;
410#endif
411 }
412
417 {
418 swap(other);
419 return *this;
420 }
421
426 frame(const frame& other)
427 : frame_ref(other.frame_ref)
428 {
429 if (frame_ref) add_ref();
430#ifdef _DEBUG
431 frame_number = other.frame_number;
432 profile = other.profile;
433#endif
434 }
435
439 void swap(frame& other)
440 {
441 std::swap(frame_ref, other.frame_ref);
442
443#ifdef _DEBUG
444 std::swap(frame_number, other.frame_number);
445 std::swap(profile, other.profile);
446#endif
447 }
448
453 {
454 if (frame_ref)
455 {
456 rs2_release_frame(frame_ref);
457 }
458 }
459
463 void keep() { rs2_keep_frame(frame_ref); }
464
469 operator bool() const { return frame_ref != nullptr; }
470
472 {
473 rs2_error* e = nullptr;
474 auto r = rs2_get_frame_sensor(frame_ref, &e);
475 error::handle(e);
476 return r;
477 }
478
500 double get_timestamp() const
501 {
502 rs2_error* e = nullptr;
503 auto r = rs2_get_frame_timestamp(frame_ref, &e);
504 error::handle(e);
505 return r;
506 }
507
512 {
513 rs2_error* e = nullptr;
514 auto r = rs2_get_frame_timestamp_domain(frame_ref, &e);
515 error::handle(e);
516 return r;
517 }
518
524 {
525 rs2_error* e = nullptr;
526 auto r = rs2_get_frame_metadata(frame_ref, frame_metadata, &e);
527 error::handle(e);
528 return r;
529 }
530
536 {
537 rs2_error* e = nullptr;
538 auto r = rs2_supports_frame_metadata(frame_ref, frame_metadata, &e);
539 error::handle(e);
540 return r != 0;
541 }
542
547 unsigned long long get_frame_number() const
548 {
549 rs2_error* e = nullptr;
550 auto r = rs2_get_frame_number(frame_ref, &e);
551 error::handle(e);
552 return r;
553 }
554
559 const int get_data_size() const
560 {
561 rs2_error* e = nullptr;
562 auto r = rs2_get_frame_data_size(frame_ref, &e);
563 error::handle(e);
564 return r;
565 }
566
571 const void* get_data() const
572 {
573 rs2_error* e = nullptr;
574 auto r = rs2_get_frame_data(frame_ref, &e);
575 error::handle(e);
576 return r;
577 }
578
588 const void* get_gpu_data_or_upload( bool* copied = nullptr ) const
589 {
590 rs2_error* e = nullptr;
591 int c = 0;
592 auto r = rs2_get_frame_gpu_data_or_upload(frame_ref, &c, &e);
593 error::handle(e);
594 if( copied ) *copied = ( c != 0 );
595 return r;
596 }
597
603 {
604 rs2_error* e = nullptr;
605 auto s = rs2_get_frame_stream_profile(frame_ref, &e);
606 error::handle(e);
607 return stream_profile(s);
608 }
609
614 template<class T>
615 bool is() const
616 {
617 T extension(*this);
618 return extension;
619 }
620
624 template<class T>
625 T as() const
626 {
627 T extension(*this);
628 return extension;
629 }
630
635 rs2_frame* get() const { return frame_ref; }
636 explicit operator rs2_frame*() { return frame_ref; }
637
639 {
640 return filter.process(*this);
641 }
642
643 protected:
649 void add_ref() const
650 {
651 rs2_error* e = nullptr;
652 rs2_frame_add_ref(frame_ref, &e);
653 error::handle(e);
654 }
655
656 void reset()
657 {
658 if (frame_ref)
659 {
660 rs2_release_frame(frame_ref);
661 }
662 frame_ref = nullptr;
663 }
664
665 private:
666 friend class rs2::frame_source;
667 friend class rs2::frame_queue;
668 friend class rs2::syncer;
670 friend class rs2::pointcloud;
671 friend class rs2::points;
672
673 rs2_frame* frame_ref;
674
675#ifdef _DEBUG
676 stream_profile profile;
677 unsigned long long frame_number = 0;
678#endif
679 };
680
681 class video_frame : public frame
682 {
683 public:
689 : frame(f)
690 {
691 rs2_error* e = nullptr;
692 if (!f || (rs2_is_frame_extendable_to(f.get(), RS2_EXTENSION_VIDEO_FRAME, &e) == 0 && !e))
693 {
694 reset();
695 }
696 error::handle(e);
697 }
698
699
704 int get_width() const
705 {
706 rs2_error* e = nullptr;
707 auto r = rs2_get_frame_width(get(), &e);
708 error::handle(e);
709 return r;
710 }
711
716 int get_height() const
717 {
718 rs2_error* e = nullptr;
719 auto r = rs2_get_frame_height(get(), &e);
720 error::handle(e);
721 return r;
722 }
723
729 {
730 rs2_error* e = nullptr;
731 auto r = rs2_get_frame_stride_in_bytes(get(), &e);
732 error::handle(e);
733 return r;
734 }
735
741 {
742 rs2_error* e = nullptr;
743 auto r = rs2_get_frame_bits_per_pixel(get(), &e);
744 error::handle(e);
745 return r;
746 }
747
752 int get_bytes_per_pixel() const { return get_bits_per_pixel() / 8; }
753
764 bool extract_target_dimensions(rs2_calib_target_type calib_type, float* target_dims, unsigned int target_dims_size) const
765 {
766 rs2_error* e = nullptr;
767 rs2_extract_target_dimensions(get(), calib_type, target_dims, target_dims_size, &e);
768 error::handle(e);
769 return (e == nullptr);
770 }
771 };
772
773 struct vertex {
774 float x, y, z;
775 operator const float*() const { return &x; }
776 };
778 float u, v;
779 operator const float*() const { return &u; }
780 };
781
782 class points : public frame
783 {
784 public:
788 points() : frame(), _size(0) {}
789
794 points(const frame& f)
795 : frame(f), _size(0)
796 {
797 rs2_error* e = nullptr;
798 if (!f || (rs2_is_frame_extendable_to(f.get(), RS2_EXTENSION_POINTS, &e) == 0 && !e))
799 {
800 reset();
801 }
802 error::handle(e);
803
804 if (get())
805 {
806 _size = rs2_get_frame_points_count(get(), &e);
807 error::handle(e);
808 }
809 }
810
814 const vertex* get_vertices() const
815 {
816 rs2_error* e = nullptr;
817 auto res = rs2_get_frame_vertices(get(), &e);
818 error::handle(e);
819 return (const vertex*)res;
820 }
821
827 void export_to_ply(const std::string& fname, video_frame texture)
828 {
829 rs2_frame* ptr = nullptr;
830 std::swap(texture.frame_ref, ptr);
831 rs2_error* e = nullptr;
832 rs2_export_to_ply(get(), fname.c_str(), ptr, &e);
833 error::handle(e);
834 }
835
840 {
841 rs2_error* e = nullptr;
842 auto res = rs2_get_frame_texture_coordinates(get(), &e);
843 error::handle(e);
844 return (const texture_coordinate*)res;
845 }
846
847 size_t size() const
848 {
849 return _size;
850 }
851
852 private:
853 size_t _size;
854 };
855
856
857 class labeled_points : public frame
858 {
859 public:
863 labeled_points() : frame(), _size(0) {}
864
870 : frame(f), _size(0)
871 {
872 rs2_error* e = nullptr;
873 if (!f || (rs2_is_frame_extendable_to(f.get(), RS2_EXTENSION_LABELED_POINTS, &e) == 0 && !e))
874 {
875 reset();
876 }
877 error::handle(e);
878
879 if (get())
880 {
882 error::handle(e);
883 }
884 }
885
890 const vertex* get_vertices() const
891 {
892 rs2_error* e = nullptr;
893 auto res = rs2_get_frame_labeled_vertices(get(), &e);
894 error::handle(e);
895 return (const vertex*)res;
896 }
897
902 const uint8_t* get_labels() const
903 {
904 rs2_error* e = nullptr;
905 auto res = rs2_get_frame_labels(get(), &e);
906 error::handle(e);
907 return (uint8_t * )res;
908 }
909
910 // Returns the vertices counts
911 size_t size() const
912 {
913 return _size;
914 }
915
920 unsigned int get_width() const
921 {
922 rs2_error* e = nullptr;
924 error::handle(e);
925 return r;
926 }
927
932 unsigned int get_height() const
933 {
934 rs2_error* e = nullptr;
936 error::handle(e);
937 return r;
938 }
939
944 unsigned int get_bits_per_pixel() const
945 {
946 rs2_error* e = nullptr;
948 error::handle(e);
949 return r;
950 }
951
952 private:
953 size_t _size;
954 };
955
957 {
958 public:
964 : video_frame(f)
965 {
966 rs2_error* e = nullptr;
967 if (!f || (rs2_is_frame_extendable_to(f.get(), RS2_EXTENSION_DEPTH_FRAME, &e) == 0 && !e))
968 {
969 reset();
970 }
971 error::handle(e);
972 }
973
980 float get_distance(int x, int y) const
981 {
982 rs2_error * e = nullptr;
983 auto r = rs2_depth_frame_get_distance(get(), x, y, &e);
984 error::handle(e);
985 return r;
986 }
987
992 float get_units() const
993 {
994 rs2_error * e = nullptr;
995 auto r = rs2_depth_frame_get_units( get(), &e );
996 error::handle( e );
997 return r;
998 }
999 };
1000
1002 {
1003 public:
1009 : depth_frame(f)
1010 {
1011 rs2_error* e = nullptr;
1012 if (!f || (rs2_is_frame_extendable_to(f.get(), RS2_EXTENSION_DISPARITY_FRAME, &e) == 0 && !e))
1013 {
1014 reset();
1015 }
1016 error::handle(e);
1017 }
1018
1022 float get_baseline(void) const
1023 {
1024 rs2_error * e = nullptr;
1026 error::handle(e);
1027 return r;
1028 }
1029 };
1030
1046 class gpu_frame : public frame
1047 {
1048 public:
1050 : frame(f)
1051 {
1052 rs2_error* e = nullptr;
1053 if (!f || (rs2_is_frame_extendable_to(f.get(), RS2_EXTENSION_GPU_FRAME, &e) == 0 && !e))
1054 {
1055 reset();
1056 }
1057 error::handle(e);
1058 }
1059
1066 const void* get_gpu_data() const
1067 {
1068 rs2_error* e = nullptr;
1069 auto r = rs2_get_frame_gpu_data(get(), &e);
1070 error::handle(e);
1071 return r;
1072 }
1073 };
1074
1075 class motion_frame : public frame
1076 {
1077 public:
1083 : frame(f)
1084 {
1085 rs2_error* e = nullptr;
1086 if (!f || (rs2_is_frame_extendable_to(f.get(), RS2_EXTENSION_MOTION_FRAME, &e) == 0 && !e))
1087 {
1088 reset();
1089 }
1090 error::handle(e);
1091 }
1092
1098 {
1099 auto data = reinterpret_cast<const float*>(get_data());
1100 return rs2_vector{ data[0], data[1], data[2] };
1101 }
1102
1108 {
1109 return *reinterpret_cast< rs2_combined_motion const * >( get_data() );
1110 }
1111 };
1112
1113 class pose_frame : public frame
1114 {
1115 public:
1121 : frame(f)
1122 {
1123 rs2_error* e = nullptr;
1124 if (!f || (rs2_is_frame_extendable_to(f.get(), RS2_EXTENSION_POSE_FRAME, &e) == 0 && !e))
1125 {
1126 reset();
1127 }
1128 error::handle(e);
1129 }
1130
1135 {
1136 rs2_pose pose_data;
1137 rs2_error* e = nullptr;
1138 rs2_pose_frame_get_pose_data(get(), &pose_data, &e);
1139 error::handle(e);
1140 return pose_data;
1141 }
1142 };
1143
1145 {
1146 public:
1151 {
1152 }
1153
1158 perception_frame( const frame & f ) : frame( f )
1159 {
1160 rs2_error * e = nullptr;
1161 if( ! f || ( rs2_is_frame_extendable_to( f.get(), RS2_EXTENSION_PERCEPTION_FRAME, &e ) == 0 && ! e ) )
1162 {
1163 reset();
1164 }
1165 error::handle( e );
1166 }
1167 };
1168
1170 {
1171 public:
1176
1182 : perception_frame(f)
1183 {
1184 rs2_error* e = nullptr;
1186 {
1187 reset();
1188 }
1189 error::handle(e);
1190 }
1191
1196 unsigned int get_detection_count() const
1197 {
1198 rs2_error* e = nullptr;
1200 error::handle(e);
1201 return r;
1202 }
1203
1210 rs2_object_detection get_detection(unsigned int index) const
1211 {
1212 rs2_object_detection detection;
1213 rs2_error* e = nullptr;
1214 rs2_get_frame_object_detection(get(), index, &detection, &e);
1215 error::handle(e);
1216 return detection;
1217 }
1218 };
1219
1220 class frameset : public frame
1221 {
1222 public:
1226 frameset() :_size(0) {};
1231 frameset(const frame& f)
1232 : frame(f), _size(0)
1233 {
1234 rs2_error* e = nullptr;
1235 if (!f || (rs2_is_frame_extendable_to(f.get(), RS2_EXTENSION_COMPOSITE_FRAME, &e) == 0 && !e))
1236 {
1237 reset();
1238 // TODO - consider explicit constructor to move resultion to compile time
1239 }
1240 error::handle(e);
1241
1242 if (get())
1243 {
1244 _size = rs2_embedded_frames_count(get(), &e);
1245 error::handle(e);
1246 }
1247 }
1248
1256 {
1257 frame result;
1258 foreach_rs([&result, s, f](frame frm) {
1259 if (!result && frm.get_profile().stream_type() == s && (f == RS2_FORMAT_ANY || f == frm.get_profile().format()))
1260 {
1261 result = std::move(frm);
1262 }
1263 });
1264 return result;
1265 }
1266
1273 {
1274 auto frm = first_or_default(s, f);
1275 if (!frm) throw error("Frame of requested stream type was not found!");
1276 return frm;
1277 }
1278
1284 {
1286 return f.as<depth_frame>();
1287 }
1288
1292 video_frame get_color_frame( const size_t index = 0 ) const
1293 {
1294 frame f;
1295
1296 foreach_rs( [&f, index]( const frame & frm ) {
1297 if( !f && frm.get_profile().stream_type() == RS2_STREAM_COLOR &&
1298 frm.get_profile().stream_index() == index )
1299 f = frm;
1300 } );
1301
1302 if( ! f )
1303 {
1304 // Color frame can also come from infrared sensor
1305 foreach_rs( [&f, index]( const frame & frm ) {
1306 if( !f && frm.get_profile().stream_type() == RS2_STREAM_INFRARED &&
1307 frm.get_profile().stream_index() == index &&
1309 f = frm;
1310 } );
1311 }
1312
1313 return f;
1314 }
1315
1322
1327 video_frame get_infrared_frame(const size_t index = 0) const
1328 {
1329 frame f;
1330 if (!index)
1331 {
1333 }
1334 else
1335 {
1336 foreach_rs([&f, index](const frame& frm) {
1337 if( !f && frm.get_profile().stream_type() == RS2_STREAM_INFRARED &&
1338 frm.get_profile().stream_index() == index )
1339 f = frm;
1340 });
1341 }
1342 return f;
1343 }
1344
1350 video_frame get_fisheye_frame(const size_t index = 0) const
1351 {
1352 frame f;
1353 if (!index)
1354 {
1356 }
1357 else
1358 {
1359 foreach_rs([&f, index](const frame& frm) {
1361 frm.get_profile().stream_index() == index) f = frm;
1362 });
1363 }
1364 return f;
1365 }
1366
1372 pose_frame get_pose_frame(const size_t index = 0) const
1373 {
1374 frame f;
1375 if (!index)
1376 {
1378 }
1379 else
1380 {
1381 foreach_rs([&f, index](const frame& frm) {
1382 if (frm.get_profile().stream_type() == RS2_STREAM_POSE &&
1383 frm.get_profile().stream_index() == index) f = frm;
1384 });
1385 }
1386 return f.as<pose_frame>();
1387 }
1388
1395 {
1396 frame f;
1397 if (!index)
1398 {
1400 }
1401 else
1402 {
1403 foreach_rs([&f, index](const frame& frm) {
1405 frm.get_profile().stream_index() == index) f = frm;
1406 });
1407 }
1408 return f.as<object_detection_frame>();
1409 }
1410
1415 size_t size() const
1416 {
1417 return _size;
1418 }
1419
1424 template<class T>
1425 void foreach_rs(T action) const
1426 {
1427 rs2_error* e = nullptr;
1428 auto count = size();
1429 for (size_t i = 0; i < count; i++)
1430 {
1431 auto fref = rs2_extract_frame(get(), (int)i, &e);
1432 error::handle(e);
1433
1434 action(frame(fref));
1435 }
1436 }
1437
1442 frame operator[](size_t index) const
1443 {
1444 rs2_error* e = nullptr;
1445 if (index < size())
1446 {
1447 auto fref = rs2_extract_frame(get(), (int)index, &e);
1448 error::handle(e);
1449 return frame(fref);
1450 }
1451
1452 throw error("Requested index is out of range!");
1453 }
1454
1456 {
1457 public:
1458 // inheriting from std::iterator template is deprecated in C++17, this is the new way to define an iterator
1459 // go to https://www.fluentcpp.com/2018/05/08/std-iterator-deprecated/ for more info
1460 using iterator_category = std::forward_iterator_tag;
1462 using difference_type = std::ptrdiff_t;
1463 using pointer = frame*;
1465
1466 iterator(const frameset* owner, size_t index = 0) : _index(index), _owner(owner) {}
1467 iterator& operator++() { ++_index; return *this; }
1468 bool operator==(const iterator& other) const { return _index == other._index; }
1469 bool operator!=(const iterator& other) const { return !(*this == other); }
1470
1471 frame operator*() { return (*_owner)[_index]; }
1472 private:
1473 size_t _index = 0;
1474 const frameset* _owner;
1475 };
1476
1477 iterator begin() const { return iterator(this); }
1478 iterator end() const { return iterator(this, size()); }
1479 private:
1480 size_t _size;
1481 };
1482
1483 template<class T>
1485 {
1486 T on_frame_function;
1487 public:
1488 explicit frame_callback(T on_frame) : on_frame_function(on_frame) {}
1489
1490 void on_frame(rs2_frame* fref) override
1491 {
1492 on_frame_function(frame{ fref });
1493 }
1494
1495 void release() override { delete this; }
1496 };
1497}
1498#endif // LIBREALSENSE_RS2_FRAME_HPP
Definition rs_frame.hpp:957
float get_units() const
Definition rs_frame.hpp:992
float get_distance(int x, int y) const
Definition rs_frame.hpp:980
depth_frame(const frame &f)
Definition rs_frame.hpp:963
disparity_frame(const frame &f)
Definition rs_frame.hpp:1008
float get_baseline(void) const
Definition rs_frame.hpp:1022
error(rs2_error *err)
Definition rs_types.hpp:115
static void handle(rs2_error *e)
Definition rs_types.hpp:162
Definition rs_frame.hpp:363
virtual rs2::frame process(rs2::frame frame) const =0
virtual ~filter_interface()=default
Definition rs_processing.hpp:361
rs2::frame process(rs2::frame frame) const override
Definition rs_processing.hpp:369
void release() override
Definition rs_frame.hpp:1495
void on_frame(rs2_frame *fref) override
Definition rs_frame.hpp:1490
frame_callback(T on_frame)
Definition rs_frame.hpp:1488
Definition rs_processing.hpp:134
Definition rs_processing.hpp:18
Definition rs_frame.hpp:370
void reset()
Definition rs_frame.hpp:656
frame(rs2_frame *ref)
Definition rs_frame.hpp:380
const void * get_gpu_data_or_upload(bool *copied=nullptr) const
Definition rs_frame.hpp:588
rs2_timestamp_domain get_frame_timestamp_domain() const
Definition rs_frame.hpp:511
frame & operator=(frame other)
Definition rs_frame.hpp:416
double get_timestamp() const
Definition rs_frame.hpp:500
frame(frame &&other) noexcept
Definition rs_frame.hpp:404
frame()
Definition rs_frame.hpp:375
frame(const frame &other)
Definition rs_frame.hpp:426
void keep()
Definition rs_frame.hpp:463
void swap(frame &other)
Definition rs_frame.hpp:439
frame apply_filter(filter_interface &filter)
Definition rs_frame.hpp:638
~frame()
Definition rs_frame.hpp:452
rs2_metadata_type get_frame_metadata(rs2_frame_metadata_value frame_metadata) const
Definition rs_frame.hpp:523
bool is() const
Definition rs_frame.hpp:615
stream_profile get_profile() const
Definition rs_frame.hpp:602
bool supports_frame_metadata(rs2_frame_metadata_value frame_metadata) const
Definition rs_frame.hpp:535
const int get_data_size() const
Definition rs_frame.hpp:559
T as() const
Definition rs_frame.hpp:625
const void * get_data() const
Definition rs_frame.hpp:571
unsigned long long get_frame_number() const
Definition rs_frame.hpp:547
rs2_sensor * get_sensor()
Definition rs_frame.hpp:471
rs2_frame * get() const
Definition rs_frame.hpp:635
void add_ref() const
Definition rs_frame.hpp:649
Definition rs_frame.hpp:1456
bool operator!=(const iterator &other) const
Definition rs_frame.hpp:1469
frame * pointer
Definition rs_frame.hpp:1463
iterator & operator++()
Definition rs_frame.hpp:1467
bool operator==(const iterator &other) const
Definition rs_frame.hpp:1468
iterator(const frameset *owner, size_t index=0)
Definition rs_frame.hpp:1466
std::ptrdiff_t difference_type
Definition rs_frame.hpp:1462
frame operator*()
Definition rs_frame.hpp:1471
frame value_type
Definition rs_frame.hpp:1461
frame & reference
Definition rs_frame.hpp:1464
std::forward_iterator_tag iterator_category
Definition rs_frame.hpp:1460
frame first_or_default(rs2_stream s, rs2_format f=RS2_FORMAT_ANY) const
Definition rs_frame.hpp:1255
labeled_points get_labeled_point_cloud_frame() const
Definition rs_frame.hpp:1316
pose_frame get_pose_frame(const size_t index=0) const
Definition rs_frame.hpp:1372
video_frame get_fisheye_frame(const size_t index=0) const
Definition rs_frame.hpp:1350
video_frame get_infrared_frame(const size_t index=0) const
Definition rs_frame.hpp:1327
void foreach_rs(T action) const
Definition rs_frame.hpp:1425
iterator end() const
Definition rs_frame.hpp:1478
object_detection_frame get_object_detection_frame(const size_t index=0) const
Definition rs_frame.hpp:1394
frame operator[](size_t index) const
Definition rs_frame.hpp:1442
depth_frame get_depth_frame() const
Definition rs_frame.hpp:1283
frameset()
Definition rs_frame.hpp:1226
iterator begin() const
Definition rs_frame.hpp:1477
frameset(const frame &f)
Definition rs_frame.hpp:1231
frame first(rs2_stream s, rs2_format f=RS2_FORMAT_ANY) const
Definition rs_frame.hpp:1272
video_frame get_color_frame(const size_t index=0) const
Definition rs_frame.hpp:1292
size_t size() const
Definition rs_frame.hpp:1415
gpu_frame(const frame &f)
Definition rs_frame.hpp:1049
const void * get_gpu_data() const
Definition rs_frame.hpp:1066
Definition rs_frame.hpp:858
const uint8_t * get_labels() const
Definition rs_frame.hpp:902
unsigned int get_bits_per_pixel() const
Definition rs_frame.hpp:944
size_t size() const
Definition rs_frame.hpp:911
unsigned int get_width() const
Definition rs_frame.hpp:920
unsigned int get_height() const
Definition rs_frame.hpp:932
labeled_points(const frame &f)
Definition rs_frame.hpp:869
const vertex * get_vertices() const
Definition rs_frame.hpp:890
labeled_points()
Definition rs_frame.hpp:863
motion_frame(const frame &f)
Definition rs_frame.hpp:1082
rs2_combined_motion get_combined_motion_data() const
Definition rs_frame.hpp:1107
rs2_vector get_motion_data() const
Definition rs_frame.hpp:1097
motion_stream_profile(const stream_profile &sp)
Definition rs_frame.hpp:300
rs2_motion_device_intrinsic get_motion_intrinsics() const
Definition rs_frame.hpp:315
Definition rs_frame.hpp:1170
object_detection_frame()
Definition rs_frame.hpp:1175
object_detection_frame(const frame &f)
Definition rs_frame.hpp:1181
unsigned int get_detection_count() const
Definition rs_frame.hpp:1196
rs2_object_detection get_detection(unsigned int index) const
Definition rs_frame.hpp:1210
perception_frame(const frame &f)
Definition rs_frame.hpp:1158
perception_frame()
Definition rs_frame.hpp:1150
perception_stream_profile(const stream_profile &sp)
Definition rs_frame.hpp:347
Definition rs_pipeline.hpp:19
Definition rs_processing.hpp:430
Definition rs_frame.hpp:783
points()
Definition rs_frame.hpp:788
const texture_coordinate * get_texture_coordinates() const
Definition rs_frame.hpp:839
size_t size() const
Definition rs_frame.hpp:847
void export_to_ply(const std::string &fname, video_frame texture)
Definition rs_frame.hpp:827
const vertex * get_vertices() const
Definition rs_frame.hpp:814
points(const frame &f)
Definition rs_frame.hpp:794
Definition rs_frame.hpp:1114
pose_frame(const frame &f)
Definition rs_frame.hpp:1120
rs2_pose get_pose_data() const
Definition rs_frame.hpp:1134
pose_stream_profile(const stream_profile &sp)
Definition rs_frame.hpp:332
Definition rs_processing.hpp:251
Definition rs_sensor.hpp:104
Definition rs_frame.hpp:23
rs2_extrinsics get_extrinsics_to(const stream_profile &to) const
Definition rs_frame.hpp:157
rs2_format format() const
Definition rs_frame.hpp:44
stream_profile(const rs2_stream_profile *profile)
Definition rs_frame.hpp:179
rs2_format _format
Definition rs_frame.hpp:204
int _uid
Definition rs_frame.hpp:202
stream_profile()
Definition rs_frame.hpp:28
int _framerate
Definition rs_frame.hpp:203
int stream_index() const
Definition rs_frame.hpp:34
int unique_id() const
Definition rs_frame.hpp:54
bool is_default() const
Definition rs_frame.hpp:134
std::shared_ptr< rs2_stream_profile > _clone
Definition rs_frame.hpp:199
std::string stream_name() const
Definition rs_frame.hpp:113
rs2_stream _type
Definition rs_frame.hpp:205
const rs2_stream_profile * _profile
Definition rs_frame.hpp:198
bool is() const
Definition rs_frame.hpp:92
int fps() const
Definition rs_frame.hpp:49
T as() const
Definition rs_frame.hpp:103
void register_extrinsics_to(const stream_profile &to, rs2_extrinsics extrinsics)
Definition rs_frame.hpp:171
bool _default
Definition rs_frame.hpp:207
rs2_stream stream_type() const
Definition rs_frame.hpp:39
const rs2_stream_profile * get() const
Definition rs_frame.hpp:146
int _index
Definition rs_frame.hpp:201
stream_profile clone(rs2_stream type, int index, rs2_format format) const
Definition rs_frame.hpp:63
bool operator==(const stream_profile &rhs)
Definition rs_frame.hpp:79
bool is_cloned()
Definition rs_frame.hpp:178
Definition rs_processing.hpp:700
Definition rs_frame.hpp:682
int get_bits_per_pixel() const
Definition rs_frame.hpp:740
int get_height() const
Definition rs_frame.hpp:716
video_frame(const frame &f)
Definition rs_frame.hpp:688
int get_stride_in_bytes() const
Definition rs_frame.hpp:728
int get_width() const
Definition rs_frame.hpp:704
int get_bytes_per_pixel() const
Definition rs_frame.hpp:752
bool extract_target_dimensions(rs2_calib_target_type calib_type, float *target_dims, unsigned int target_dims_size) const
Definition rs_frame.hpp:764
Definition rs_frame.hpp:211
stream_profile clone(rs2_stream type, int index, rs2_format format, int width, int height, const rs2_intrinsics &intr) const
Definition rs_frame.hpp:277
int height() const
Definition rs_frame.hpp:241
video_stream_profile()
Definition rs_frame.hpp:213
video_stream_profile(const stream_profile &sp)
Definition rs_frame.hpp:219
int width() const
Definition rs_frame.hpp:236
rs2_intrinsics get_intrinsics() const
Definition rs_frame.hpp:249
bool operator==(const video_stream_profile &other) const
Definition rs_frame.hpp:258
Definition rs_processing_gl.hpp:13
float rs2_depth_frame_get_distance(const rs2_frame *frame_ref, int x, int y, rs2_error **error)
rs2_vertex * rs2_get_frame_labeled_vertices(const rs2_frame *frame, rs2_error **error)
rs2_frame * rs2_extract_frame(rs2_frame *composite, int index, rs2_error **error)
void rs2_extract_target_dimensions(const rs2_frame *frame, rs2_calib_target_type calib_type, float *target_dims, unsigned int target_dims_size, rs2_error **error)
const void * rs2_get_frame_gpu_data_or_upload(const rs2_frame *frame, int *copied, rs2_error **error)
rs2_timestamp_domain rs2_get_frame_timestamp_domain(const rs2_frame *frameset, rs2_error **error)
rs2_time_t rs2_get_frame_timestamp(const rs2_frame *frame, rs2_error **error)
int rs2_get_frame_data_size(const rs2_frame *frame, rs2_error **error)
rs2_vertex * rs2_get_frame_vertices(const rs2_frame *frame, rs2_error **error)
int rs2_get_frame_points_count(const rs2_frame *frame, rs2_error **error)
void rs2_release_frame(rs2_frame *frame)
unsigned long long rs2_get_frame_number(const rs2_frame *frame, rs2_error **error)
unsigned int rs2_get_frame_labeled_points_height(const rs2_frame *frame, rs2_error **error)
unsigned int rs2_get_frame_labeled_points_width(const rs2_frame *frame, rs2_error **error)
int rs2_get_frame_bits_per_pixel(const rs2_frame *frame, rs2_error **error)
int rs2_is_frame_extendable_to(const rs2_frame *frame, rs2_extension extension_type, rs2_error **error)
const rs2_stream_profile * rs2_get_frame_stream_profile(const rs2_frame *frame, rs2_error **error)
unsigned int rs2_get_frame_labeled_points_bits_per_pixel(const rs2_frame *frame, rs2_error **error)
rs2_metadata_type rs2_get_frame_metadata(const rs2_frame *frame, rs2_frame_metadata_value frame_metadata, rs2_error **error)
int rs2_get_frame_height(const rs2_frame *frame, rs2_error **error)
void rs2_frame_add_ref(rs2_frame *frame, rs2_error **error)
int rs2_get_frame_labeled_points_count(const rs2_frame *frame, rs2_error **error)
rs2_timestamp_domain
Specifies the clock in relation to which the frame timestamp was measured.
Definition rs_frame.h:20
int rs2_supports_frame_metadata(const rs2_frame *frame, rs2_frame_metadata_value frame_metadata, rs2_error **error)
rs2_pixel * rs2_get_frame_texture_coordinates(const rs2_frame *frame, rs2_error **error)
void rs2_export_to_ply(const rs2_frame *frame, const char *fname, rs2_frame *texture, rs2_error **error)
rs2_frame_metadata_value
Per-Frame-Metadata is the set of read-only properties that might be exposed for each individual frame...
Definition rs_frame.h:30
void rs2_keep_frame(rs2_frame *frame)
const void * rs2_get_frame_gpu_data(const rs2_frame *frame, rs2_error **error)
int rs2_get_frame_stride_in_bytes(const rs2_frame *frame, rs2_error **error)
void rs2_pose_frame_get_pose_data(const rs2_frame *frame, rs2_pose *pose, rs2_error **error)
const void * rs2_get_frame_data(const rs2_frame *frame, rs2_error **error)
int rs2_embedded_frames_count(rs2_frame *composite, rs2_error **error)
rs2_sensor * rs2_get_frame_sensor(const rs2_frame *frame, rs2_error **error)
int rs2_get_frame_width(const rs2_frame *frame, rs2_error **error)
unsigned int rs2_get_frame_object_detection_count(const rs2_frame *frame, rs2_error **error)
void rs2_get_frame_object_detection(const rs2_frame *frame, unsigned int index, rs2_object_detection *detection, rs2_error **error)
float rs2_depth_frame_get_units(const rs2_frame *frame, rs2_error **error)
const char * rs2_get_stream_profile_name(const rs2_stream_profile *profile, rs2_error **error)
void * rs2_get_frame_labels(const rs2_frame *frame, rs2_error **error)
rs2_calib_target_type
Calibration target type.
Definition rs_frame.h:170
rs2_stream
Streams are different types of data provided by RealSense devices.
Definition rs_sensor.h:48
@ RS2_STREAM_DEPTH
Definition rs_sensor.h:50
@ RS2_STREAM_ANY
Definition rs_sensor.h:49
@ RS2_STREAM_INFRARED
Definition rs_sensor.h:52
@ RS2_STREAM_LABELED_POINT_CLOUD
Definition rs_sensor.h:62
@ RS2_STREAM_OBJECT_DETECTION
Definition rs_sensor.h:63
@ RS2_STREAM_COLOR
Definition rs_sensor.h:51
@ RS2_STREAM_POSE
Definition rs_sensor.h:57
@ RS2_STREAM_FISHEYE
Definition rs_sensor.h:53
void rs2_get_motion_intrinsics(const rs2_stream_profile *mode, rs2_motion_device_intrinsic *intrinsics, rs2_error **error)
float rs2_depth_stereo_frame_get_baseline(const rs2_frame *frame_ref, rs2_error **error)
void rs2_delete_stream_profile(rs2_stream_profile *mode)
const char * rs2_stream_to_string(rs2_stream stream)
int rs2_stream_profile_is(const rs2_stream_profile *mode, rs2_extension type, rs2_error **error)
void rs2_get_video_stream_resolution(const rs2_stream_profile *mode, int *width, int *height, rs2_error **error)
rs2_stream_profile * rs2_clone_video_stream_profile(const rs2_stream_profile *mode, rs2_stream stream, int index, rs2_format format, int width, int height, const rs2_intrinsics *intr, rs2_error **error)
int rs2_is_stream_profile_default(const rs2_stream_profile *mode, rs2_error **error)
void rs2_get_stream_profile_data(const rs2_stream_profile *mode, rs2_stream *stream, rs2_format *format, int *index, int *unique_id, int *framerate, rs2_error **error)
void rs2_get_extrinsics(const rs2_stream_profile *from, const rs2_stream_profile *to, rs2_extrinsics *extrin, rs2_error **error)
void rs2_get_video_stream_intrinsics(const rs2_stream_profile *mode, rs2_intrinsics *intrinsics, rs2_error **error)
rs2_format
A stream's format identifies how binary data is encoded within a frame.
Definition rs_sensor.h:70
@ RS2_FORMAT_RGB8
Definition rs_sensor.h:76
@ RS2_FORMAT_Z16
Definition rs_sensor.h:72
@ RS2_FORMAT_ANY
Definition rs_sensor.h:71
void rs2_register_extrinsics(const rs2_stream_profile *from, const rs2_stream_profile *to, rs2_extrinsics extrin, rs2_error **error)
rs2_stream_profile * rs2_clone_stream_profile(const rs2_stream_profile *mode, rs2_stream stream, int index, rs2_format format, rs2_error **error)
struct rs2_sensor rs2_sensor
Definition rs_types.h:320
struct rs2_stream_profile rs2_stream_profile
Definition rs_types.h:307
@ RS2_EXTENSION_MOTION_FRAME
Definition rs_types.h:164
@ RS2_EXTENSION_MOTION_PROFILE
Definition rs_types.h:174
@ RS2_EXTENSION_DISPARITY_FRAME
Definition rs_types.h:173
@ RS2_EXTENSION_POSE_PROFILE
Definition rs_types.h:176
@ RS2_EXTENSION_VIDEO_PROFILE
Definition rs_types.h:170
@ RS2_EXTENSION_PERCEPTION_FRAME
Definition rs_types.h:220
@ RS2_EXTENSION_VIDEO_FRAME
Definition rs_types.h:163
@ RS2_EXTENSION_PERCEPTION_PROFILE
Definition rs_types.h:223
@ RS2_EXTENSION_GPU_FRAME
Definition rs_types.h:224
@ RS2_EXTENSION_COMPOSITE_FRAME
Definition rs_types.h:165
@ RS2_EXTENSION_OBJECT_DETECTION_FRAME
Definition rs_types.h:221
@ RS2_EXTENSION_DEPTH_FRAME
Definition rs_types.h:167
@ RS2_EXTENSION_LABELED_POINTS
Definition rs_types.h:214
@ RS2_EXTENSION_POINTS
Definition rs_types.h:166
@ RS2_EXTENSION_POSE_FRAME
Definition rs_types.h:175
struct rs2_error rs2_error
Definition rs_types.h:296
long long rs2_metadata_type
Definition rs_types.h:344
struct rs2_frame rs2_frame
Definition rs_types.h:299
Definition rs_frame.hpp:777
float v
Definition rs_frame.hpp:778
float u
Definition rs_frame.hpp:778
Definition rs_frame.hpp:773
float y
Definition rs_frame.hpp:774
float x
Definition rs_frame.hpp:774
float z
Definition rs_frame.hpp:774
RS2_STREAM_MOTION / RS2_FORMAT_COMBINED_MOTION content is similar to ROS2's Imu message.
Definition rs_sensor.h:120
Cross-stream extrinsics: encodes the topology describing how the different devices are oriented.
Definition rs_sensor.h:113
Definition rs_types.hpp:27
Video stream intrinsics.
Definition rs_types.h:61
Motion device intrinsics: scale, bias, and variances.
Definition rs_types.h:74
Object detection result from algorithm.
Definition rs_types.h:124
Definition rs_types.h:111
3D vector in Euclidean coordinate space
Definition rs_types.h:100