OrbbecSDK 2.10.6
OrbbecSDK: Software-Development-Kit for Orbbec 3D Cameras
Loading...
Searching...
No Matches
Frame.hpp
Go to the documentation of this file.
1// Copyright (c) Orbbec Inc. All Rights Reserved.
2// Licensed under the MIT License.
3
9#pragma once
10
11#include "Types.hpp"
12#include "libobsensor/h/Frame.h"
15#include <memory>
16#include <iostream>
17#include <typeinfo>
18#include <functional>
19
36
37namespace ob {
38class Device;
39class Sensor;
40
45class Frame : public std::enable_shared_from_this<Frame> {
46protected:
50 const ob_frame *impl_ = nullptr;
51
52public:
62 explicit Frame(const ob_frame *impl) : impl_(impl) {}
63
69 const ob_frame *getImpl() const {
70 return impl_;
71 }
72
76 virtual ~Frame() noexcept {
77 if(impl_) {
78 ob_error *error = nullptr;
79 ob_delete_frame(impl_, &error);
80 Error::handle(&error, false);
81 impl_ = nullptr;
82 }
83 }
84
90 virtual OBFrameType getType() const {
91 ob_error *error = nullptr;
92 auto type = ob_frame_get_type(impl_, &error);
93 Error::handle(&error);
94
95 return type;
96 }
97
103 virtual OBFormat getFormat() const {
104 ob_error *error = nullptr;
105 auto format = ob_frame_get_format(impl_, &error);
106 Error::handle(&error);
107
108 return format;
109 }
110
118 virtual uint64_t getIndex() const {
119 ob_error *error = nullptr;
120 auto index = ob_frame_get_index(impl_, &error);
121 Error::handle(&error);
122
123 return index;
124 }
125
131 uint64_t getToken() const {
132 ob_error *error = nullptr;
133 auto token = ob_frame_get_token(impl_, &error);
134 Error::handle(&error);
135
136 return token;
137 }
138
144 void setToken(uint64_t token) {
145 ob_error *error = nullptr;
146 auto unConstImpl = const_cast<ob_frame *>(impl_);
147
148 ob_frame_set_token(unConstImpl, token, &error);
149 Error::handle(&error);
150 }
151
157 virtual uint8_t *getData() const {
158 ob_error *error = nullptr;
159 auto data = ob_frame_get_data(impl_, &error);
160 Error::handle(&error);
161
162 return data;
163 }
164
172 virtual uint32_t getDataSize() const {
173 ob_error *error = nullptr;
174 auto dataSize = ob_frame_get_data_size(impl_, &error);
175 Error::handle(&error);
176
177 return dataSize;
178 }
179
186 uint64_t getTimeStampUs() const {
187 ob_error *error = nullptr;
189 Error::handle(&error);
190
191 return timeStampUs;
192 }
193
200 uint64_t getSystemTimeStampUs() const {
201 ob_error *error = nullptr;
203 Error::handle(&error);
204
205 return systemTimeStampUs;
206 }
207
219 uint64_t getGlobalTimeStampUs() const {
220 ob_error *error = nullptr;
222 Error::handle(&error);
223
224 return globalTimeStampUs;
225 }
226
232 uint8_t *getMetadata() const {
233 ob_error *error = nullptr;
234 auto metadata = ob_frame_get_metadata(impl_, &error);
235 Error::handle(&error);
236
237 return metadata;
238 }
239
245 uint32_t getMetadataSize() const {
246 ob_error *error = nullptr;
248 Error::handle(&error);
249
250 return metadataSize;
251 }
252
261 ob_error *error = nullptr;
262 auto result = ob_frame_has_metadata(impl_, type, &error);
263 Error::handle(&error);
264
265 return result;
266 }
267
276 ob_error *error = nullptr;
277 auto value = ob_frame_get_metadata_value(impl_, type, &error);
278 Error::handle(&error);
279
280 return value;
281 }
282
288 std::shared_ptr<StreamProfile> getStreamProfile() const {
289 ob_error *error = nullptr;
290 auto profile = ob_frame_get_stream_profile(impl_, &error);
291 Error::handle(&error);
292 return StreamProfileFactory::create(profile);
293 }
294
300 std::shared_ptr<Sensor> getSensor() const {
301 ob_error *error = nullptr;
302 auto sensor = ob_frame_get_sensor(impl_, &error);
303 Error::handle(&error);
304
305 return std::make_shared<Sensor>(sensor);
306 }
307
313 std::shared_ptr<Device> getDevice() const {
314 ob_error *error = nullptr;
315 auto device = ob_frame_get_device(impl_, &error);
316 Error::handle(&error);
317
318 return std::make_shared<Device>(device);
319 }
320
328 template <typename T> bool is() const;
329
337 template <typename T> std::shared_ptr<T> as() {
338 if(!is<T>()) {
339 throw std::runtime_error("unsupported operation, object's type is not require type");
340 }
341
342 ob_error *error = nullptr;
343 ob_frame_add_ref(impl_, &error);
344 Error::handle(&error);
345
346 return std::make_shared<T>(impl_);
347 }
348
356 template <typename T> std::shared_ptr<const T> as() const {
357 if(!is<const T>()) {
358 throw std::runtime_error("unsupported operation, object's type is not require type");
359 }
360
361 ob_error *error = nullptr;
362 ob_frame_add_ref(impl_, &error);
363 Error::handle(&error);
364
365 return std::make_shared<const T>(impl_);
366 }
367
374 void copyFrameInfo(std::shared_ptr<const Frame> srcFrame) {
375 ob_error *error = nullptr;
376 auto unConstImpl = const_cast<ob_frame *>(impl_);
377
378 ob_frame_copy_info(srcFrame->getImpl(), unConstImpl, &error);
379 Error::handle(&error);
380 }
381
387 void setSystemTimestampUs(uint64_t systemTimestampUs) {
388 ob_error *error = nullptr;
389 auto unConstImpl = const_cast<ob_frame *>(impl_);
390
391 ob_frame_set_system_timestamp_us(unConstImpl, systemTimestampUs, &error);
392 Error::handle(&error);
393 }
394
408 void updateData(const uint8_t *data, uint32_t dataSize) {
409 ob_error *error = nullptr;
410 auto unConstImpl = const_cast<ob_frame *>(impl_);
411
412 ob_frame_update_data(unConstImpl, data, dataSize, &error);
413 Error::handle(&error);
414 }
415
428 void updateMetadata(const uint8_t *metadata, uint32_t metadataSize) {
429 ob_error *error = nullptr;
430 auto unConstImpl = const_cast<ob_frame *>(impl_);
431
432 ob_frame_update_metadata(unConstImpl, metadata, metadataSize, &error);
433 Error::handle(&error);
434 }
435
441 void setStreamProfile(std::shared_ptr<const StreamProfile> profile) {
442 ob_error *error = nullptr;
443 auto unConstImpl = const_cast<ob_frame *>(impl_);
444
445 ob_frame_set_stream_profile(unConstImpl, profile->getImpl(), &error);
446 Error::handle(&error);
447 }
448
449public:
450 // The following interfaces are deprecated and are retained here for compatibility purposes.
452 return getType();
453 }
454
455 virtual OBFormat format() const {
456 return getFormat();
457 }
458
459 virtual uint64_t index() const {
460 return getIndex();
461 }
462
463 virtual void *data() const {
464 auto data = getData();
465 return reinterpret_cast<void *>(data);
466 }
467
468 virtual uint32_t dataSize() const {
469 return getDataSize();
470 }
471
472 uint64_t timeStamp() const {
473 return getTimeStampUs() / 1000;
474 }
475
476 uint64_t timeStampUs() const {
477 return getTimeStampUs();
478 }
479
480 uint64_t systemTimeStamp() const {
481 return getSystemTimeStampUs() / 1000;
482 }
483
484 uint64_t systemTimeStampUs() const {
485 return getSystemTimeStampUs();
486 }
487
488 uint64_t globalTimeStampUs() const {
489 return getGlobalTimeStampUs();
490 }
491
492 uint8_t *metadata() const {
493 return getMetadata();
494 }
495
496 uint32_t metadataSize() const {
497 return getMetadataSize();
498 }
499};
500
504class VideoFrame : public Frame {
505public:
515 explicit VideoFrame(const ob_frame *impl) : Frame(impl) {};
516
517 ~VideoFrame() noexcept override = default;
518
524 uint32_t getWidth() const {
525 ob_error *error = nullptr;
526 auto width = ob_video_frame_get_width(impl_, &error);
527 Error::handle(&error);
528
529 return width;
530 }
531
537 uint32_t getHeight() const {
538 ob_error *error = nullptr;
539 auto height = ob_video_frame_get_height(impl_, &error);
540 Error::handle(&error);
541
542 return height;
543 }
544
554 ob_error *error = nullptr;
555 auto pixelType = ob_video_frame_get_pixel_type(impl_, &error);
556 Error::handle(&error);
557
558 return pixelType;
559 }
560
567 uint8_t getPixelAvailableBitSize() const {
568 ob_error *error = nullptr;
570 Error::handle(&error);
571
572 return bitSize;
573 }
574
580 void setPixelType(OBPixelType pixelType) {
581 ob_error *error = nullptr;
582 auto unConstImpl = const_cast<ob_frame *>(impl_);
583
584 ob_video_frame_set_pixel_type(unConstImpl, pixelType, &error);
585 Error::handle(&error);
586 }
587
595 void setPixelAvailableBitSize(uint8_t bitSize) {
596 ob_error *error = nullptr;
597 auto unConstImpl = const_cast<ob_frame *>(impl_);
598
599 ob_video_frame_set_pixel_available_bit_size(unConstImpl, bitSize, &error);
600 Error::handle(&error);
601 }
602
603public:
604 // The following interfaces are deprecated and are retained here for compatibility purposes.
605 uint32_t width() const {
606 return getWidth();
607 }
608
609 uint32_t height() const {
610 return getHeight();
611 }
612
613 uint8_t pixelAvailableBitSize() const {
615 }
616};
617
621class ColorFrame : public VideoFrame {
622public:
633 explicit ColorFrame(const ob_frame *impl) : VideoFrame(impl) {};
634
635 ~ColorFrame() noexcept override = default;
636};
637
641class DepthFrame : public VideoFrame {
642
643public:
654 explicit DepthFrame(const ob_frame *impl) : VideoFrame(impl) {};
655
656 ~DepthFrame() noexcept override = default;
657
665 float getValueScale() const {
666 ob_error *error = nullptr;
667 auto scale = ob_depth_frame_get_value_scale(impl_, &error);
668 Error::handle(&error);
669
670 return scale;
671 }
672
679 void setValueScale(float valueScale) {
680 ob_error *error = nullptr;
681 auto unConstImpl = const_cast<ob_frame *>(impl_);
682
683 ob_depth_frame_set_value_scale(unConstImpl, valueScale, &error);
684 Error::handle(&error);
685 }
686};
687
692class IRFrame : public VideoFrame {
693
694public:
705 explicit IRFrame(const ob_frame *impl) : VideoFrame(impl) {};
706
707 ~IRFrame() noexcept override = default;
708};
709
715
716public:
727 explicit ConfidenceFrame(const ob_frame *impl) : VideoFrame(impl) {};
728
729 ~ConfidenceFrame() noexcept override = default;
730};
731
740class PointsFrame : public Frame {
741
742public:
753 explicit PointsFrame(const ob_frame *impl) : Frame(impl) {};
754
755 ~PointsFrame() noexcept override = default;
756
765 ob_error *error = nullptr;
767 Error::handle(&error);
768
769 return scale;
770 }
771
777 uint32_t getWidth() const {
778 ob_error *error = nullptr;
779 // TODO
780 auto width = ob_point_cloud_frame_get_width(impl_, &error);
781 Error::handle(&error);
782
783 return width;
784 }
785
791 uint32_t getHeight() const {
792 ob_error *error = nullptr;
793 auto height = ob_point_cloud_frame_get_height(impl_, &error);
794 Error::handle(&error);
795
796 return height;
797 }
798
799public:
800 // The following interfaces are deprecated and are retained here for compatibility purposes.
801#define getPositionValueScale getCoordinateValueScale
802};
803
808class AccelFrame : public Frame {
809
810public:
811 explicit AccelFrame(const ob_frame *impl) : Frame(impl) {};
812
813 ~AccelFrame() noexcept override = default;
814
821 ob_error *error = nullptr;
822 auto value = ob_accel_frame_get_value(impl_, &error);
823 Error::handle(&error);
824
825 return value;
826 }
827
833 float getTemperature() const {
834 ob_error *error = nullptr;
835 auto temp = ob_accel_frame_get_temperature(impl_, &error);
836 Error::handle(&error);
837
838 return temp;
839 }
840
841public:
842 // The following interfaces are deprecated and are retained here for compatibility purposes.
844 return getValue();
845 }
846
847 float temperature() {
848 return getTemperature();
849 }
850};
851
855class GyroFrame : public Frame {
856
857public:
858 explicit GyroFrame(const ob_frame *impl) : Frame(impl) {};
859
860 ~GyroFrame() noexcept override = default;
861
868 ob_error *error = nullptr;
869 auto value = ob_gyro_frame_get_value(impl_, &error);
870 Error::handle(&error);
871
872 return value;
873 }
874
880 float getTemperature() const {
881 ob_error *error = nullptr;
883 Error::handle(&error);
884
885 return temperature;
886 }
887
888public:
889 // The following interfaces are deprecated and are retained here for compatibility purposes.
891 return getValue();
892 }
893
894 float temperature() {
895 return getTemperature();
896 }
897};
898
911class LiDARPointsFrame : public Frame {
912public:
923 explicit LiDARPointsFrame(const ob_frame *impl) : Frame(impl){};
924 ~LiDARPointsFrame() noexcept override = default;
925};
926
931class FrameSet : public Frame {
932
933public:
934 explicit FrameSet(const ob_frame *impl) : Frame(impl) {};
935
936 ~FrameSet() noexcept override = default;
937
943 uint32_t getCount() const {
944 ob_error *error = nullptr;
945 auto count = ob_frameset_get_count(impl_, &error);
946 Error::handle(&error);
947 return count;
948 }
949
957 std::shared_ptr<Frame> getFrame(OBFrameType frameType) const {
958 ob_error *error = nullptr;
959 auto frame = ob_frameset_get_frame(impl_, frameType, &error);
960 if(!frame) {
961 return nullptr;
962 }
963 Error::handle(&error);
964 return std::make_shared<Frame>(frame);
965 }
966
974 std::shared_ptr<Frame> getFrameByIndex(uint32_t index) const {
975 ob_error *error = nullptr;
976 auto frame = ob_frameset_get_frame_by_index(impl_, index, &error);
977 if(!frame) {
978 return nullptr;
979 }
980 Error::handle(&error);
981 return std::make_shared<Frame>(frame);
982 }
983
991 void pushFrame(std::shared_ptr<const Frame> frame) const {
992 ob_error *error = nullptr;
993
994 // unsafe operation, need to cast const to non-const
995 auto unConstImpl = const_cast<ob_frame *>(impl_);
996
997 auto otherImpl = frame->getImpl();
998 ob_frameset_push_frame(unConstImpl, otherImpl, &error);
999
1000 Error::handle(&error);
1001 }
1002
1008 std::shared_ptr<DepthFrame> getDepthFrame() const {
1009 ob_error *error = nullptr;
1010 auto frame = ob_frameset_get_depth_frame(impl_, &error);
1011 if(!frame) {
1012 return nullptr;
1013 }
1014 Error::handle(&error);
1015 return std::make_shared<DepthFrame>(frame);
1016 }
1017
1023 std::shared_ptr<ColorFrame> getColorFrame() const {
1024 ob_error *error = nullptr;
1025 auto frame = ob_frameset_get_color_frame(impl_, &error);
1026 if(!frame) {
1027 return nullptr;
1028 }
1029 Error::handle(&error);
1030 return std::make_shared<ColorFrame>(frame);
1031 }
1032
1038 std::shared_ptr<IRFrame> getIrFrame() const {
1039 ob_error *error = nullptr;
1040 auto frame = ob_frameset_get_ir_frame(impl_, &error);
1041 if(!frame) {
1042 return nullptr;
1043 }
1044 Error::handle(&error);
1045 return std::make_shared<IRFrame>(frame);
1046 }
1047
1053 std::shared_ptr<PointsFrame> getPointsFrame() const {
1054 ob_error *error = nullptr;
1055 auto frame = ob_frameset_get_points_frame(impl_, &error);
1056 if(!frame) {
1057 return nullptr;
1058 }
1059 Error::handle(&error);
1060 return std::make_shared<PointsFrame>(frame);
1061 }
1062
1063public:
1064 // The following interfaces are deprecated and are retained here for compatibility purposes.
1065 uint32_t frameCount() const {
1066 return getCount();
1067 }
1068
1069 std::shared_ptr<DepthFrame> depthFrame() const {
1070 auto frame = getFrame(OB_FRAME_DEPTH);
1071 if(frame == nullptr) {
1072 return nullptr;
1073 }
1074 auto depthFrame = frame->as<ob::DepthFrame>();
1075 return depthFrame;
1076 }
1077
1078 std::shared_ptr<ColorFrame> colorFrame() const {
1079 auto frame = getFrame(OB_FRAME_COLOR);
1080 if(frame == nullptr) {
1081 return nullptr;
1082 }
1083 auto colorFrame = frame->as<ob::ColorFrame>();
1084 return colorFrame;
1085 }
1086
1087 std::shared_ptr<IRFrame> irFrame() const {
1088 auto frame = getFrame(OB_FRAME_IR);
1089 if(frame == nullptr) {
1090 return nullptr;
1091 }
1092 auto irFrame = frame->as<ob::IRFrame>();
1093 return irFrame;
1094 }
1095
1096public:
1097 // The following interfaces are deprecated and are retained here for compatibility purposes.
1098 std::shared_ptr<PointsFrame> pointsFrame() const {
1099 auto frame = getFrame(OB_FRAME_POINTS);
1100 if(frame == nullptr) {
1101 return nullptr;
1102 }
1103 auto pointsFrame = frame->as<ob::PointsFrame>();
1104 return pointsFrame;
1105 }
1106
1107 std::shared_ptr<Frame> getFrame(int index) const {
1108 return getFrameByIndex(index);
1109 }
1110};
1111
1116public:
1126 static std::shared_ptr<Frame> createFrame(OBFrameType frameType, OBFormat format, uint32_t dataSize) {
1127 ob_error *error = nullptr;
1128 auto impl = ob_create_frame(frameType, format, dataSize, &error);
1129 Error::handle(&error);
1130
1131 return std::make_shared<Frame>(impl);
1132 }
1133
1146 static std::shared_ptr<VideoFrame> createVideoFrame(OBFrameType frameType, OBFormat format, uint32_t width, uint32_t height, uint32_t stride = 0) {
1147 ob_error *error = nullptr;
1148 auto impl = ob_create_video_frame(frameType, format, width, height, stride, &error);
1149 Error::handle(&error);
1150
1151 auto frame = std::make_shared<Frame>(impl);
1152 return frame->as<VideoFrame>();
1153 }
1154
1165 static std::shared_ptr<Frame> createFrameFromOtherFrame(std::shared_ptr<const Frame> otherFrame, bool shouldCopyData = true) {
1166 ob_error *error = nullptr;
1167 auto otherImpl = otherFrame->getImpl();
1168 auto impl = ob_create_frame_from_other_frame(otherImpl, shouldCopyData, &error);
1169 Error::handle(&error);
1170
1171 return std::make_shared<Frame>(impl);
1172 }
1173
1181 static std::shared_ptr<Frame> createFrameFromStreamProfile(std::shared_ptr<const StreamProfile> profile) {
1182 ob_error *error = nullptr;
1183 auto impl = ob_create_frame_from_stream_profile(profile->getImpl(), &error);
1184 Error::handle(&error);
1185
1186 return std::make_shared<Frame>(impl);
1187 }
1188
1192 typedef std::function<void(uint8_t *)> BufferDestroyCallback;
1193
1208 static std::shared_ptr<Frame> createFrameFromBuffer(OBFrameType frameType, OBFormat format, uint8_t *buffer, BufferDestroyCallback destroyCallback,
1209 uint32_t bufferSize) {
1210 ob_error *error = nullptr;
1211 auto ctx = new BufferDestroyContext{ destroyCallback };
1212 auto impl = ob_create_frame_from_buffer(frameType, format, buffer, bufferSize, &FrameFactory::BufferDestroy, ctx, &error);
1213 Error::handle(&error);
1214
1215 return std::make_shared<Frame>(impl);
1216 }
1217
1237 static std::shared_ptr<VideoFrame> createVideoFrameFromBuffer(OBFrameType frameType, OBFormat format, uint32_t width, uint32_t height, uint8_t *buffer,
1238 BufferDestroyCallback destroyCallback, uint32_t bufferSize, uint32_t stride = 0) {
1239 ob_error *error = nullptr;
1240 auto ctx = new BufferDestroyContext{ destroyCallback };
1241 auto impl = ob_create_video_frame_from_buffer(frameType, format, width, height, stride, buffer, bufferSize, &FrameFactory::BufferDestroy, ctx, &error);
1242 Error::handle(&error);
1243
1244 auto frame = std::make_shared<Frame>(impl);
1245 return frame->as<VideoFrame>();
1246 }
1247
1257 static std::shared_ptr<FrameSet> createFrameSet() {
1258 ob_error *error = nullptr;
1259 auto impl = ob_create_frameset(&error);
1260 Error::handle(&error);
1261 return std::make_shared<FrameSet>(impl);
1262 }
1263
1264private:
1265 struct BufferDestroyContext {
1266 BufferDestroyCallback callback;
1267 };
1268
1269 static void BufferDestroy(uint8_t *buffer, void *context) {
1270 auto *ctx = static_cast<BufferDestroyContext *>(context);
1271 if(ctx->callback) {
1272 ctx->callback(buffer);
1273 }
1274 delete ctx;
1275 }
1276};
1277
1283public:
1290 static void setFrameDeviceTimestampUs(std::shared_ptr<Frame> frame, uint64_t deviceTimestampUs) {
1291 ob_error *error = nullptr;
1292 auto impl = const_cast<ob_frame *>(frame->getImpl());
1293 ob_frame_set_timestamp_us(impl, deviceTimestampUs, &error);
1294 Error::handle(&error);
1295 }
1296
1297public:
1298 // The following interfaces are deprecated and are retained here for compatibility purposes.
1299 static void setFrameSystemTimestamp(std::shared_ptr<Frame> frame, uint64_t systemTimestamp) {
1300 // In order to compile, some high-version compilers will warn that the function parameters are not used.
1301 (void)frame;
1302 (void)systemTimestamp;
1303 }
1304
1305 static void setFrameDeviceTimestamp(std::shared_ptr<Frame> frame, uint64_t deviceTimestamp) {
1306 // In order to compile, some high-version compilers will warn that the function parameters are not used.
1307 (void)frame;
1308 (void)deviceTimestamp;
1309 }
1310};
1311
1312// Define the is() template function for the Frame class
1313template <typename T> bool Frame::is() const {
1314 switch(this->getType()) {
1315 case OB_FRAME_IR_LEFT: // Follow
1316 case OB_FRAME_IR_RIGHT: // Follow
1317 case OB_FRAME_IR:
1318 return (typeid(T) == typeid(IRFrame) || typeid(T) == typeid(VideoFrame));
1319 case OB_FRAME_DEPTH:
1320 return (typeid(T) == typeid(DepthFrame) || typeid(T) == typeid(VideoFrame));
1321 case OB_FRAME_COLOR:
1324 return (typeid(T) == typeid(ColorFrame) || typeid(T) == typeid(VideoFrame));
1326 return (typeid(T) == typeid(ConfidenceFrame) || typeid(T) == typeid(VideoFrame));
1327 case OB_FRAME_GYRO:
1328 return (typeid(T) == typeid(GyroFrame));
1329 case OB_FRAME_ACCEL:
1330 return (typeid(T) == typeid(AccelFrame));
1331 case OB_FRAME_POINTS:
1332 return (typeid(T) == typeid(PointsFrame));
1334 return (typeid(T) == typeid(LiDARPointsFrame));
1335 case OB_FRAME_SET:
1336 return (typeid(T) == typeid(FrameSet));
1337 default:
1338 std::cout << "ob::Frame::is() did not catch frame type: " << (int)this->getType() << std::endl;
1339 break;
1340 }
1341 return false;
1342}
1343
1344} // namespace ob
This file defines the Error class, which describes abnormal errors within the SDK....
Frame related function is mainly used to obtain frame data and frame information.
OB_EXPORT void ob_frameset_push_frame(ob_frame *frameset, const ob_frame *frame, ob_error **error)
Push a frame to the frameset.
OB_EXPORT ob_frame * ob_frameset_get_color_frame(const ob_frame *frameset, ob_error **error)
Get the color frame from the frameset.
OB_EXPORT ob_frame * ob_frameset_get_ir_frame(const ob_frame *frameset, ob_error **error)
Get the infrared frame from the frameset.
OB_EXPORT ob_frame * ob_create_video_frame_from_buffer(ob_frame_type frame_type, ob_format format, uint32_t width, uint32_t height, uint32_t stride_bytes, uint8_t *buffer, uint32_t buffer_size, ob_frame_destroy_callback *buffer_destroy_cb, void *buffer_destroy_context, ob_error **error)
Create a video frame object based on an externally created buffer.
OB_EXPORT void ob_frame_copy_info(const ob_frame *src_frame, ob_frame *dst_frame, ob_error **error)
Copy the information of the source frame object to the destination frame object.
OB_EXPORT void ob_frame_update_data(ob_frame *frame, const uint8_t *data, uint32_t data_size, ob_error **error)
Update the data of a frame.
OB_EXPORT void ob_video_frame_set_pixel_type(ob_frame *frame, ob_pixel_type pixel_type, ob_error **error)
Set video frame pixel format.
OB_EXPORT uint8_t * ob_frame_get_data(const ob_frame *frame, ob_error **error)
Get the data buffer of a frame.
OB_EXPORT ob_frame * ob_create_frame_from_buffer(ob_frame_type frame_type, ob_format format, uint8_t *buffer, uint32_t buffer_size, ob_frame_destroy_callback *buffer_destroy_cb, void *buffer_destroy_context, ob_error **error)
Create a frame object based on an externally created buffer.
OB_EXPORT ob_frame * ob_create_frame_from_stream_profile(const ob_stream_profile *stream_profile, ob_error **error)
Create a frame object according to the specified stream profile.
OB_EXPORT void ob_frame_set_system_timestamp_us(ob_frame *frame, uint64_t system_timestamp_us, ob_error **error)
Set the system timestamp of the frame in microseconds.
OB_EXPORT ob_frame * ob_create_frame_from_other_frame(const ob_frame *other_frame, bool should_copy_data, ob_error **error)
Create (clone) a frame object based on the specified other frame object.
OB_EXPORT uint64_t ob_frame_get_timestamp_us(const ob_frame *frame, ob_error **error)
Get the frame timestamp (also known as device timestamp, hardware timestamp) of the frame in microsec...
OB_EXPORT ob_frame * ob_create_video_frame(ob_frame_type frame_type, ob_format format, uint32_t width, uint32_t height, uint32_t stride_bytes, ob_error **error)
Create an video frame object based on the specified parameters.
OB_EXPORT ob_frame_type ob_frame_get_type(const ob_frame *frame, ob_error **error)
Get the frame type.
OB_EXPORT ob_frame * ob_frameset_get_frame(const ob_frame *frameset, ob_frame_type frame_type, ob_error **error)
Get a frame of a specific type from the frameset.
OB_EXPORT ob_frame * ob_create_frameset(ob_error **error)
Create an empty frameset object.
OB_EXPORT ob_format ob_frame_get_format(const ob_frame *frame, ob_error **error)
Get the frame format.
OB_EXPORT ob_accel_value ob_accel_frame_get_value(const ob_frame *frame, ob_error **error)
Get accelerometer frame data.
OB_EXPORT uint32_t ob_video_frame_get_width(const ob_frame *frame, ob_error **error)
Get video frame width.
OB_EXPORT uint8_t ob_video_frame_get_pixel_available_bit_size(const ob_frame *frame, ob_error **error)
Get the effective number of pixels (such as Y16 format frame, but only the lower 10 bits are effectiv...
OB_EXPORT ob_frame * ob_frameset_get_points_frame(const ob_frame *frameset, ob_error **error)
Get point cloud frame from the frameset.
OB_EXPORT float ob_depth_frame_get_value_scale(const ob_frame *frame, ob_error **error)
Get the value scale of the depth frame. The pixel value of the depth frame is multiplied by the scale...
OB_EXPORT ob_stream_profile * ob_frame_get_stream_profile(const ob_frame *frame, ob_error **error)
Get the stream profile of the frame.
OB_EXPORT float ob_points_frame_get_coordinate_value_scale(const ob_frame *frame, ob_error **error)
Get the point coordinate value scale of the points frame. The point position value of the points fram...
OB_EXPORT float ob_accel_frame_get_temperature(const ob_frame *frame, ob_error **error)
Get the temperature when acquiring the accelerometer frame.
OB_EXPORT ob_frame * ob_frameset_get_frame_by_index(const ob_frame *frameset, uint32_t index, ob_error **error)
Get a frame at a specific index from the FrameSet.
OB_EXPORT bool ob_frame_has_metadata(const ob_frame *frame, ob_frame_metadata_type type, ob_error **error)
check if the frame contains the specified metadata
OB_EXPORT void ob_depth_frame_set_value_scale(ob_frame *frame, float value_scale, ob_error **error)
Set the value scale of the depth frame. The pixel value of the depth frame is multiplied by the scale...
OB_EXPORT int64_t ob_frame_get_metadata_value(const ob_frame *frame, ob_frame_metadata_type type, ob_error **error)
Get the metadata value of the frame.
OB_EXPORT uint32_t ob_point_cloud_frame_get_width(const ob_frame *frame, ob_error **error)
Get point cloud frame width.
OB_EXPORT ob_gyro_value ob_gyro_frame_get_value(const ob_frame *frame, ob_error **error)
Get gyroscope frame data.
OB_EXPORT uint64_t ob_frame_get_global_timestamp_us(const ob_frame *frame, ob_error **error)
Get the global timestamp of the frame in microseconds.
OB_EXPORT uint64_t ob_frame_get_token(const ob_frame *frame, ob_error **error)
Get the auth token carried by the frame.
OB_EXPORT uint32_t ob_frame_get_metadata_size(const ob_frame *frame, ob_error **error)
Get the metadata size of the frame.
OB_EXPORT void ob_frame_set_timestamp_us(ob_frame *frame, uint64_t timestamp_us, ob_error **error)
Set the frame timestamp (also known as the device timestamp, hardware timestamp) of a frame object.
OB_EXPORT uint32_t ob_frame_get_data_size(const ob_frame *frame, ob_error **error)
Get the frame data size.
OB_EXPORT void ob_frame_set_token(ob_frame *frame, uint64_t token, ob_error **error)
Set the auth token carried by the frame.
OB_EXPORT ob_device * ob_frame_get_device(const ob_frame *frame, ob_error **error)
Get the device of the frame.
OB_EXPORT uint64_t ob_frame_get_system_timestamp_us(const ob_frame *frame, ob_error **error)
Get the system timestamp of the frame in microseconds.
OB_EXPORT void ob_frame_update_metadata(ob_frame *frame, const uint8_t *metadata, uint32_t metadata_size, ob_error **error)
Update the metadata of the frame.
OB_EXPORT float ob_gyro_frame_get_temperature(const ob_frame *frame, ob_error **error)
Get the temperature when acquiring the gyroscope frame.
OB_EXPORT uint64_t ob_frame_get_index(const ob_frame *frame, ob_error **error)
Get the frame index.
OB_EXPORT void ob_frame_add_ref(const ob_frame *frame, ob_error **error)
Increase the reference count of a frame object.
OB_EXPORT ob_frame * ob_frameset_get_depth_frame(const ob_frame *frameset, ob_error **error)
Get the depth frame from the frameset.
OB_EXPORT void ob_video_frame_set_pixel_available_bit_size(ob_frame *frame, uint8_t bit_size, ob_error **error)
Set the effective number of pixels (such as Y16 format frame, but only the lower 10 bits are effectiv...
OB_EXPORT uint32_t ob_point_cloud_frame_get_height(const ob_frame *frame, ob_error **error)
Get point cloud frame height.
OB_EXPORT ob_pixel_type ob_video_frame_get_pixel_type(const ob_frame *frame, ob_error **error)
Get video frame pixel format.
OB_EXPORT void ob_delete_frame(const ob_frame *frame, ob_error **error)
Delete a frame object.
OB_EXPORT ob_sensor * ob_frame_get_sensor(const ob_frame *frame, ob_error **error)
Get the sensor of the frame.
OB_EXPORT ob_frame * ob_create_frame(ob_frame_type frame_type, ob_format format, uint32_t data_size, ob_error **error)
Crate a frame object based on the specified parameters.
OB_EXPORT uint8_t * ob_frame_get_metadata(const ob_frame *frame, ob_error **error)
Get the metadata of the frame.
OB_EXPORT void ob_frame_set_stream_profile(ob_frame *frame, const ob_stream_profile *stream_profile, ob_error **error)
Set (override) the stream profile of the frame.
OB_EXPORT uint32_t ob_frameset_get_count(const ob_frame *frameset, ob_error **error)
Get the number of frames contained in the frameset.
OB_EXPORT uint32_t ob_video_frame_get_height(const ob_frame *frame, ob_error **error)
Get video frame height.
struct ob_frame_t ob_frame
Definition ObTypes.h:33
struct OBAccelValue OBGyroValue
OBFormat
Enumeration value describing the pixel format.
Definition ObTypes.h:262
enum ob_frame_metadata_type OBFrameMetadataType
OBFrameType
Enumeration value describing the type of frame.
Definition ObTypes.h:225
@ OB_FRAME_IR_RIGHT
Definition ObTypes.h:236
@ OB_FRAME_ACCEL
Definition ObTypes.h:231
@ OB_FRAME_COLOR_RIGHT
Definition ObTypes.h:241
@ OB_FRAME_GYRO
Definition ObTypes.h:234
@ OB_FRAME_IR_LEFT
Definition ObTypes.h:235
@ OB_FRAME_LIDAR_POINTS
Definition ObTypes.h:239
@ OB_FRAME_COLOR_LEFT
Definition ObTypes.h:240
@ OB_FRAME_COLOR
Definition ObTypes.h:229
@ OB_FRAME_SET
Definition ObTypes.h:232
@ OB_FRAME_CONFIDENCE
Definition ObTypes.h:238
@ OB_FRAME_POINTS
Definition ObTypes.h:233
@ OB_FRAME_IR
Definition ObTypes.h:228
@ OB_FRAME_DEPTH
Definition ObTypes.h:230
OBPixelType
Enumeration value describing the pixel type of frame (usually used for depth frame).
Definition ObTypes.h:250
The stream profile related type is used to get information such as the width, height,...
Define the AccelFrame class, which inherits from the Frame class.
Definition Frame.hpp:808
OBAccelValue value()
Definition Frame.hpp:843
OBAccelValue getValue() const
Get the accelerometer frame data.
Definition Frame.hpp:820
float getTemperature() const
Get the temperature when the frame was sampled.
Definition Frame.hpp:833
float temperature()
Definition Frame.hpp:847
~AccelFrame() noexcept override=default
AccelFrame(const ob_frame *impl)
Definition Frame.hpp:811
Define the ColorFrame class, which inherits from the VideoFrame classd.
Definition Frame.hpp:621
~ColorFrame() noexcept override=default
ColorFrame(const ob_frame *impl)
Construct a new ColorFrame object with a given pointer to the internal frame object.
Definition Frame.hpp:633
Define the ConfidenceFrame class, which inherits from the VideoFrame class.
Definition Frame.hpp:714
~ConfidenceFrame() noexcept override=default
ConfidenceFrame(const ob_frame *impl)
Construct a new ConfidenceFrame object with a given pointer to the internal frame object.
Definition Frame.hpp:727
Define the DepthFrame class, which inherits from the VideoFrame class.
Definition Frame.hpp:641
float getValueScale() const
Get the value scale of the depth frame. The pixel value of depth frame is multiplied by the scale to ...
Definition Frame.hpp:665
~DepthFrame() noexcept override=default
DepthFrame(const ob_frame *impl)
Construct a new DepthFrame object with a given pointer to the internal frame object.
Definition Frame.hpp:654
void setValueScale(float valueScale)
Set the value scale of the depth frame. The pixel value of the depth frame is multiplied by the scale...
Definition Frame.hpp:679
static void handle(ob_error **error, bool throw_exception=true)
A static function to handle the ob_error and throw an exception if needed.
Definition Error.hpp:38
FrameFactory class, which provides some static functions to create frame objects.
Definition Frame.hpp:1115
static std::shared_ptr< VideoFrame > createVideoFrameFromBuffer(OBFrameType frameType, OBFormat format, uint32_t width, uint32_t height, uint8_t *buffer, BufferDestroyCallback destroyCallback, uint32_t bufferSize, uint32_t stride=0)
Create a video frame object based on an externally created buffer.
Definition Frame.hpp:1237
static std::shared_ptr< Frame > createFrame(OBFrameType frameType, OBFormat format, uint32_t dataSize)
Create a Frame object of a specific type with a given format and data size.
Definition Frame.hpp:1126
static std::shared_ptr< Frame > createFrameFromOtherFrame(std::shared_ptr< const Frame > otherFrame, bool shouldCopyData=true)
Create (clone) a frame object based on the specified other frame object.
Definition Frame.hpp:1165
static std::shared_ptr< Frame > createFrameFromStreamProfile(std::shared_ptr< const StreamProfile > profile)
Create a Frame From (according to)Stream Profile object.
Definition Frame.hpp:1181
std::function< void(uint8_t *)> BufferDestroyCallback
The callback function to destroy the buffer when the frame is destroyed.
Definition Frame.hpp:1192
static std::shared_ptr< Frame > createFrameFromBuffer(OBFrameType frameType, OBFormat format, uint8_t *buffer, BufferDestroyCallback destroyCallback, uint32_t bufferSize)
Create a frame object based on an externally created buffer.
Definition Frame.hpp:1208
static std::shared_ptr< VideoFrame > createVideoFrame(OBFrameType frameType, OBFormat format, uint32_t width, uint32_t height, uint32_t stride=0)
Create a VideoFrame object of a specific type with a given format, width, height, and stride.
Definition Frame.hpp:1146
static std::shared_ptr< FrameSet > createFrameSet()
Create a new FrameSet object.
Definition Frame.hpp:1257
FrameHepler class, which provides some static functions to set timestamp for frame objects FrameHeple...
Definition Frame.hpp:1282
static void setFrameDeviceTimestamp(std::shared_ptr< Frame > frame, uint64_t deviceTimestamp)
Definition Frame.hpp:1305
static void setFrameDeviceTimestampUs(std::shared_ptr< Frame > frame, uint64_t deviceTimestampUs)
Set the device timestamp of the frame.
Definition Frame.hpp:1290
static void setFrameSystemTimestamp(std::shared_ptr< Frame > frame, uint64_t systemTimestamp)
Definition Frame.hpp:1299
Define the FrameSet class, which inherits from the Frame class.
Definition Frame.hpp:931
std::shared_ptr< ColorFrame > colorFrame() const
Definition Frame.hpp:1078
uint32_t getCount() const
Get the number of frames in the FrameSet.
Definition Frame.hpp:943
std::shared_ptr< IRFrame > getIrFrame() const
Get the infrared frame from the frameset.
Definition Frame.hpp:1038
std::shared_ptr< PointsFrame > pointsFrame() const
Definition Frame.hpp:1098
std::shared_ptr< DepthFrame > depthFrame() const
Definition Frame.hpp:1069
FrameSet(const ob_frame *impl)
Definition Frame.hpp:934
~FrameSet() noexcept override=default
std::shared_ptr< Frame > getFrameByIndex(uint32_t index) const
Get a frame at a specific index from the FrameSet.
Definition Frame.hpp:974
std::shared_ptr< Frame > getFrame(int index) const
Definition Frame.hpp:1107
std::shared_ptr< IRFrame > irFrame() const
Definition Frame.hpp:1087
std::shared_ptr< Frame > getFrame(OBFrameType frameType) const
Get a frame of a specific type from the FrameSet.
Definition Frame.hpp:957
void pushFrame(std::shared_ptr< const Frame > frame) const
Push a frame to the FrameSet.
Definition Frame.hpp:991
uint32_t frameCount() const
Definition Frame.hpp:1065
std::shared_ptr< ColorFrame > getColorFrame() const
Get the color frame from the frameset.
Definition Frame.hpp:1023
std::shared_ptr< PointsFrame > getPointsFrame() const
Get the point cloud frame from the frameset.
Definition Frame.hpp:1053
std::shared_ptr< DepthFrame > getDepthFrame() const
Get the depth frame from the frameset.
Definition Frame.hpp:1008
std::shared_ptr< StreamProfile > getStreamProfile() const
get StreamProfile of the frame
Definition Frame.hpp:288
uint64_t systemTimeStampUs() const
Definition Frame.hpp:484
virtual ~Frame() noexcept
Destroy the Frame object.
Definition Frame.hpp:76
void setToken(uint64_t token)
Set the auth token carried by the frame.
Definition Frame.hpp:144
int64_t getMetadataValue(OBFrameMetadataType type) const
Get the metadata value.
Definition Frame.hpp:275
uint64_t timeStamp() const
Definition Frame.hpp:472
void updateMetadata(const uint8_t *metadata, uint32_t metadataSize)
Update the metadata of the frame.
Definition Frame.hpp:428
virtual OBFrameType getType() const
Get the type of frame.
Definition Frame.hpp:90
Frame(const ob_frame *impl)
Construct a new Frame object with a given pointer to the internal frame object.
Definition Frame.hpp:62
virtual uint8_t * getData() const
Get frame data.
Definition Frame.hpp:157
std::shared_ptr< Sensor > getSensor() const
get owner sensor of the frame
Definition Frame.hpp:300
std::shared_ptr< T > as()
Convert the frame object to a target type.
Definition Frame.hpp:337
void setSystemTimestampUs(uint64_t systemTimestampUs)
Set the system timestamp of the frame in microseconds.
Definition Frame.hpp:387
bool hasMetadata(OBFrameMetadataType type) const
Check if the frame object has metadata of a given type.
Definition Frame.hpp:260
void copyFrameInfo(std::shared_ptr< const Frame > srcFrame)
Copy the information of the source frame object to the destination frame object.
Definition Frame.hpp:374
uint32_t getMetadataSize() const
Get the size of the metadata of the frame.
Definition Frame.hpp:245
uint32_t metadataSize() const
Definition Frame.hpp:496
virtual OBFormat getFormat() const
Get the format of the frame.
Definition Frame.hpp:103
const ob_frame * impl_
The pointer to the internal (c api level) frame object.
Definition Frame.hpp:50
OBFrameType type() const
Definition Frame.hpp:451
bool is() const
Check if the runtime type of the frame object is compatible with a given type.
Definition Frame.hpp:1313
uint64_t getTimeStampUs() const
Get the hardware timestamp of the frame in microseconds.
Definition Frame.hpp:186
std::shared_ptr< Device > getDevice() const
get owner device of the frame
Definition Frame.hpp:313
uint64_t globalTimeStampUs() const
Definition Frame.hpp:488
uint8_t * getMetadata() const
Get the metadata pointer of the frame.
Definition Frame.hpp:232
virtual uint64_t getIndex() const
Get the sequence number of the frame.
Definition Frame.hpp:118
virtual uint64_t index() const
Definition Frame.hpp:459
uint64_t timeStampUs() const
Definition Frame.hpp:476
uint8_t * metadata() const
Definition Frame.hpp:492
virtual void * data() const
Definition Frame.hpp:463
std::shared_ptr< const T > as() const
Convert the frame object to a target type.
Definition Frame.hpp:356
virtual uint32_t dataSize() const
Definition Frame.hpp:468
virtual uint32_t getDataSize() const
Get the size of the frame data.
Definition Frame.hpp:172
virtual OBFormat format() const
Definition Frame.hpp:455
uint64_t getSystemTimeStampUs() const
Get the system timestamp of the frame in microseconds.
Definition Frame.hpp:200
uint64_t getGlobalTimeStampUs() const
Get the global timestamp of the frame in microseconds.
Definition Frame.hpp:219
void updateData(const uint8_t *data, uint32_t dataSize)
Update the data of a frame.
Definition Frame.hpp:408
const ob_frame * getImpl() const
Get the internal (impl) frame object.
Definition Frame.hpp:69
uint64_t getToken() const
Get the auth token carried by the frame.
Definition Frame.hpp:131
uint64_t systemTimeStamp() const
Definition Frame.hpp:480
void setStreamProfile(std::shared_ptr< const StreamProfile > profile)
Set (override) the stream profile of the frame.
Definition Frame.hpp:441
Define the GyroFrame class, which inherits from the Frame class.
Definition Frame.hpp:855
~GyroFrame() noexcept override=default
OBGyroValue getValue() const
Get the gyro frame data.
Definition Frame.hpp:867
GyroFrame(const ob_frame *impl)
Definition Frame.hpp:858
OBGyroValue value()
Definition Frame.hpp:890
float temperature()
Definition Frame.hpp:894
float getTemperature() const
Get the temperature when the frame was sampled.
Definition Frame.hpp:880
Define the IRFrame class, which inherits from the VideoFrame class.
Definition Frame.hpp:692
IRFrame(const ob_frame *impl)
Construct a new IRFrame object with a given pointer to the internal frame object.
Definition Frame.hpp:705
~IRFrame() noexcept override=default
Define the LiDARPointsFrame class, which inherits from the Frame class.
Definition Frame.hpp:911
~LiDARPointsFrame() noexcept override=default
LiDARPointsFrame(const ob_frame *impl)
Construct a new LiDARPointsFrame object with a given pointer to the internal frame object.
Definition Frame.hpp:923
Define the PointsFrame class, which inherits from the Frame class.
Definition Frame.hpp:740
uint32_t getHeight() const
Get the height of the frame.
Definition Frame.hpp:791
PointsFrame(const ob_frame *impl)
Construct a new PointsFrame object with a given pointer to the internal frame object.
Definition Frame.hpp:753
~PointsFrame() noexcept override=default
uint32_t getWidth() const
Get the width of the frame.
Definition Frame.hpp:777
float getCoordinateValueScale() const
Get the point coordinate value scale of the points frame. The point position value of the points fram...
Definition Frame.hpp:764
static std::shared_ptr< StreamProfile > create(const ob_stream_profile_t *impl)
Define the VideoFrame class, which inherits from the Frame class.
Definition Frame.hpp:504
uint32_t width() const
Definition Frame.hpp:605
uint32_t getWidth() const
Get the width of the frame.
Definition Frame.hpp:524
void setPixelAvailableBitSize(uint8_t bitSize)
Set the effective number of pixels (such as Y16 format frame, but only the lower 10 bits are effectiv...
Definition Frame.hpp:595
uint8_t pixelAvailableBitSize() const
Definition Frame.hpp:613
OBPixelType getPixelType() const
Get the Pixel Type object.
Definition Frame.hpp:553
uint32_t getHeight() const
Get the height of the frame.
Definition Frame.hpp:537
uint8_t getPixelAvailableBitSize() const
Get the effective number of pixels in the frame.
Definition Frame.hpp:567
void setPixelType(OBPixelType pixelType)
Set video frame pixel format.
Definition Frame.hpp:580
uint32_t height() const
Definition Frame.hpp:609
~VideoFrame() noexcept override=default
VideoFrame(const ob_frame *impl)
Construct a new VideoFrame object with a given pointer to the internal frame object.
Definition Frame.hpp:515
Data structures for accelerometers and gyroscopes.
Definition ObTypes.h:717
The error class exposed by the SDK, users can get detailed error information according to the error.
Definition ObTypes.h:162