OrbbecSDK 2.6.3
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 virtual uint8_t *getData() const {
132 ob_error *error = nullptr;
133 auto data = ob_frame_get_data(impl_, &error);
134 Error::handle(&error);
135
136 return data;
137 }
138
146 virtual uint32_t getDataSize() const {
147 ob_error *error = nullptr;
148 auto dataSize = ob_frame_get_data_size(impl_, &error);
149 Error::handle(&error);
150
151 return dataSize;
152 }
153
160 uint64_t getTimeStampUs() const {
161 ob_error *error = nullptr;
163 Error::handle(&error);
164
165 return timeStampUs;
166 }
167
174 uint64_t getSystemTimeStampUs() const {
175 ob_error *error = nullptr;
177 Error::handle(&error);
178
179 return systemTimeStampUs;
180 }
181
193 uint64_t getGlobalTimeStampUs() const {
194 ob_error *error = nullptr;
196 Error::handle(&error);
197
198 return globalTimeStampUs;
199 }
200
206 uint8_t *getMetadata() const {
207 ob_error *error = nullptr;
208 auto metadata = ob_frame_get_metadata(impl_, &error);
209 Error::handle(&error);
210
211 return metadata;
212 }
213
219 uint32_t getMetadataSize() const {
220 ob_error *error = nullptr;
222 Error::handle(&error);
223
224 return metadataSize;
225 }
226
235 ob_error *error = nullptr;
236 auto result = ob_frame_has_metadata(impl_, type, &error);
237 Error::handle(&error);
238
239 return result;
240 }
241
250 ob_error *error = nullptr;
251 auto value = ob_frame_get_metadata_value(impl_, type, &error);
252 Error::handle(&error);
253
254 return value;
255 }
256
262 std::shared_ptr<StreamProfile> getStreamProfile() const {
263 ob_error *error = nullptr;
264 auto profile = ob_frame_get_stream_profile(impl_, &error);
265 Error::handle(&error);
266 return StreamProfileFactory::create(profile);
267 }
268
274 std::shared_ptr<Sensor> getSensor() const {
275 ob_error *error = nullptr;
276 auto sensor = ob_frame_get_sensor(impl_, &error);
277 Error::handle(&error);
278
279 return std::make_shared<Sensor>(sensor);
280 }
281
287 std::shared_ptr<Device> getDevice() const {
288 ob_error *error = nullptr;
289 auto device = ob_frame_get_device(impl_, &error);
290 Error::handle(&error);
291
292 return std::make_shared<Device>(device);
293 }
294
302 template <typename T> bool is() const;
303
311 template <typename T> std::shared_ptr<T> as() {
312 if(!is<T>()) {
313 throw std::runtime_error("unsupported operation, object's type is not require type");
314 }
315
316 ob_error *error = nullptr;
317 ob_frame_add_ref(impl_, &error);
318 Error::handle(&error);
319
320 return std::make_shared<T>(impl_);
321 }
322
330 template <typename T> std::shared_ptr<const T> as() const {
331 if(!is<const T>()) {
332 throw std::runtime_error("unsupported operation, object's type is not require type");
333 }
334
335 ob_error *error = nullptr;
336 ob_frame_add_ref(impl_, &error);
337 Error::handle(&error);
338
339 return std::make_shared<const T>(impl_);
340 }
341
348 void copyFrameInfo(std::shared_ptr<const Frame> srcFrame) {
349 ob_error *error = nullptr;
350 auto unConstImpl = const_cast<ob_frame *>(impl_);
351
352 ob_frame_copy_info(srcFrame->getImpl(), unConstImpl, &error);
353 Error::handle(&error);
354 }
355
361 void setSystemTimestampUs(uint64_t systemTimestampUs) {
362 ob_error *error = nullptr;
363 auto unConstImpl = const_cast<ob_frame *>(impl_);
364
365 ob_frame_set_system_timestamp_us(unConstImpl, systemTimestampUs, &error);
366 Error::handle(&error);
367 }
368
382 void updateData(const uint8_t *data, uint32_t dataSize) {
383 ob_error *error = nullptr;
384 auto unConstImpl = const_cast<ob_frame *>(impl_);
385
386 ob_frame_update_data(unConstImpl, data, dataSize, &error);
387 Error::handle(&error);
388 }
389
402 void updateMetadata(const uint8_t *metadata, uint32_t metadataSize) {
403 ob_error *error = nullptr;
404 auto unConstImpl = const_cast<ob_frame *>(impl_);
405
406 ob_frame_update_metadata(unConstImpl, metadata, metadataSize, &error);
407 Error::handle(&error);
408 }
409
415 void setStreamProfile(std::shared_ptr<const StreamProfile> profile) {
416 ob_error *error = nullptr;
417 auto unConstImpl = const_cast<ob_frame *>(impl_);
418
419 ob_frame_set_stream_profile(unConstImpl, profile->getImpl(), &error);
420 Error::handle(&error);
421 }
422
423public:
424 // The following interfaces are deprecated and are retained here for compatibility purposes.
426 return getType();
427 }
428
429 virtual OBFormat format() const {
430 return getFormat();
431 }
432
433 virtual uint64_t index() const {
434 return getIndex();
435 }
436
437 virtual void *data() const {
438 auto data = getData();
439 return reinterpret_cast<void *>(data);
440 }
441
442 virtual uint32_t dataSize() const {
443 return getDataSize();
444 }
445
446 uint64_t timeStamp() const {
447 return getTimeStampUs() / 1000;
448 }
449
450 uint64_t timeStampUs() const {
451 return getTimeStampUs();
452 }
453
454 uint64_t systemTimeStamp() const {
455 return getSystemTimeStampUs() / 1000;
456 }
457
458 uint64_t systemTimeStampUs() const {
459 return getSystemTimeStampUs();
460 }
461
462 uint64_t globalTimeStampUs() const {
463 return getGlobalTimeStampUs();
464 }
465
466 uint8_t *metadata() const {
467 return getMetadata();
468 }
469
470 uint32_t metadataSize() const {
471 return getMetadataSize();
472 }
473};
474
478class VideoFrame : public Frame {
479public:
489 explicit VideoFrame(const ob_frame *impl) : Frame(impl) {};
490
491 ~VideoFrame() noexcept override = default;
492
498 uint32_t getWidth() const {
499 ob_error *error = nullptr;
500 auto width = ob_video_frame_get_width(impl_, &error);
501 Error::handle(&error);
502
503 return width;
504 }
505
511 uint32_t getHeight() const {
512 ob_error *error = nullptr;
513 auto height = ob_video_frame_get_height(impl_, &error);
514 Error::handle(&error);
515
516 return height;
517 }
518
528 ob_error *error = nullptr;
529 auto pixelType = ob_video_frame_get_pixel_type(impl_, &error);
530 Error::handle(&error);
531
532 return pixelType;
533 }
534
541 uint8_t getPixelAvailableBitSize() const {
542 ob_error *error = nullptr;
544 Error::handle(&error);
545
546 return bitSize;
547 }
548
554 void setPixelType(OBPixelType pixelType) {
555 ob_error *error = nullptr;
556 auto unConstImpl = const_cast<ob_frame *>(impl_);
557
558 ob_video_frame_set_pixel_type(unConstImpl, pixelType, &error);
559 Error::handle(&error);
560 }
561
569 void setPixelAvailableBitSize(uint8_t bitSize) {
570 ob_error *error = nullptr;
571 auto unConstImpl = const_cast<ob_frame *>(impl_);
572
573 ob_video_frame_set_pixel_available_bit_size(unConstImpl, bitSize, &error);
574 Error::handle(&error);
575 }
576
577public:
578 // The following interfaces are deprecated and are retained here for compatibility purposes.
579 uint32_t width() const {
580 return getWidth();
581 }
582
583 uint32_t height() const {
584 return getHeight();
585 }
586
587 uint8_t pixelAvailableBitSize() const {
589 }
590};
591
595class ColorFrame : public VideoFrame {
596public:
607 explicit ColorFrame(const ob_frame *impl) : VideoFrame(impl) {};
608
609 ~ColorFrame() noexcept override = default;
610};
611
615class DepthFrame : public VideoFrame {
616
617public:
628 explicit DepthFrame(const ob_frame *impl) : VideoFrame(impl) {};
629
630 ~DepthFrame() noexcept override = default;
631
639 float getValueScale() const {
640 ob_error *error = nullptr;
641 auto scale = ob_depth_frame_get_value_scale(impl_, &error);
642 Error::handle(&error);
643
644 return scale;
645 }
646
653 void setValueScale(float valueScale) {
654 ob_error *error = nullptr;
655 auto unConstImpl = const_cast<ob_frame *>(impl_);
656
657 ob_depth_frame_set_value_scale(unConstImpl, valueScale, &error);
658 Error::handle(&error);
659 }
660};
661
666class IRFrame : public VideoFrame {
667
668public:
679 explicit IRFrame(const ob_frame *impl) : VideoFrame(impl) {};
680
681 ~IRFrame() noexcept override = default;
682};
683
689
690public:
701 explicit ConfidenceFrame(const ob_frame *impl) : VideoFrame(impl) {};
702
703 ~ConfidenceFrame() noexcept override = default;
704};
705
714class PointsFrame : public Frame {
715
716public:
727 explicit PointsFrame(const ob_frame *impl) : Frame(impl) {};
728
729 ~PointsFrame() noexcept override = default;
730
739 ob_error *error = nullptr;
741 Error::handle(&error);
742
743 return scale;
744 }
745
751 uint32_t getWidth() const {
752 ob_error *error = nullptr;
753 // TODO
754 auto width = ob_point_cloud_frame_get_width(impl_, &error);
755 Error::handle(&error);
756
757 return width;
758 }
759
765 uint32_t getHeight() const {
766 ob_error *error = nullptr;
767 auto height = ob_point_cloud_frame_get_height(impl_, &error);
768 Error::handle(&error);
769
770 return height;
771 }
772
773public:
774 // The following interfaces are deprecated and are retained here for compatibility purposes.
775#define getPositionValueScale getCoordinateValueScale
776};
777
782class AccelFrame : public Frame {
783
784public:
785 explicit AccelFrame(const ob_frame *impl) : Frame(impl) {};
786
787 ~AccelFrame() noexcept override = default;
788
795 ob_error *error = nullptr;
796 auto value = ob_accel_frame_get_value(impl_, &error);
797 Error::handle(&error);
798
799 return value;
800 }
801
807 float getTemperature() const {
808 ob_error *error = nullptr;
809 auto temp = ob_accel_frame_get_temperature(impl_, &error);
810 Error::handle(&error);
811
812 return temp;
813 }
814
815public:
816 // The following interfaces are deprecated and are retained here for compatibility purposes.
818 return getValue();
819 }
820
821 float temperature() {
822 return getTemperature();
823 }
824};
825
829class GyroFrame : public Frame {
830
831public:
832 explicit GyroFrame(const ob_frame *impl) : Frame(impl) {};
833
834 ~GyroFrame() noexcept override = default;
835
842 ob_error *error = nullptr;
843 auto value = ob_gyro_frame_get_value(impl_, &error);
844 Error::handle(&error);
845
846 return value;
847 }
848
854 float getTemperature() const {
855 ob_error *error = nullptr;
857 Error::handle(&error);
858
859 return temperature;
860 }
861
862public:
863 // The following interfaces are deprecated and are retained here for compatibility purposes.
865 return getValue();
866 }
867
868 float temperature() {
869 return getTemperature();
870 }
871};
872
885class LiDARPointsFrame : public Frame {
886public:
897 explicit LiDARPointsFrame(const ob_frame *impl) : Frame(impl){};
898 ~LiDARPointsFrame() noexcept override = default;
899};
900
905class FrameSet : public Frame {
906
907public:
908 explicit FrameSet(const ob_frame *impl) : Frame(impl) {};
909
910 ~FrameSet() noexcept override = default;
911
917 uint32_t getCount() const {
918 ob_error *error = nullptr;
919 auto count = ob_frameset_get_count(impl_, &error);
920 Error::handle(&error);
921 return count;
922 }
923
931 std::shared_ptr<Frame> getFrame(OBFrameType frameType) const {
932 ob_error *error = nullptr;
933 auto frame = ob_frameset_get_frame(impl_, frameType, &error);
934 if(!frame) {
935 return nullptr;
936 }
937 Error::handle(&error);
938 return std::make_shared<Frame>(frame);
939 }
940
948 std::shared_ptr<Frame> getFrameByIndex(uint32_t index) const {
949 ob_error *error = nullptr;
950 auto frame = ob_frameset_get_frame_by_index(impl_, index, &error);
951 if(!frame) {
952 return nullptr;
953 }
954 Error::handle(&error);
955 return std::make_shared<Frame>(frame);
956 }
957
965 void pushFrame(std::shared_ptr<const Frame> frame) const {
966 ob_error *error = nullptr;
967
968 // unsafe operation, need to cast const to non-const
969 auto unConstImpl = const_cast<ob_frame *>(impl_);
970
971 auto otherImpl = frame->getImpl();
972 ob_frameset_push_frame(unConstImpl, otherImpl, &error);
973
974 Error::handle(&error);
975 }
976
982 std::shared_ptr<DepthFrame> getDepthFrame() const {
983 ob_error *error = nullptr;
984 auto frame = ob_frameset_get_depth_frame(impl_, &error);
985 if(!frame) {
986 return nullptr;
987 }
988 Error::handle(&error);
989 return std::make_shared<DepthFrame>(frame);
990 }
991
997 std::shared_ptr<ColorFrame> getColorFrame() const {
998 ob_error *error = nullptr;
999 auto frame = ob_frameset_get_color_frame(impl_, &error);
1000 if(!frame) {
1001 return nullptr;
1002 }
1003 Error::handle(&error);
1004 return std::make_shared<ColorFrame>(frame);
1005 }
1006
1012 std::shared_ptr<IRFrame> getIrFrame() const {
1013 ob_error *error = nullptr;
1014 auto frame = ob_frameset_get_ir_frame(impl_, &error);
1015 if(!frame) {
1016 return nullptr;
1017 }
1018 Error::handle(&error);
1019 return std::make_shared<IRFrame>(frame);
1020 }
1021
1027 std::shared_ptr<PointsFrame> getPointsFrame() const {
1028 ob_error *error = nullptr;
1029 auto frame = ob_frameset_get_points_frame(impl_, &error);
1030 if(!frame) {
1031 return nullptr;
1032 }
1033 Error::handle(&error);
1034 return std::make_shared<PointsFrame>(frame);
1035 }
1036
1037public:
1038 // The following interfaces are deprecated and are retained here for compatibility purposes.
1039 uint32_t frameCount() const {
1040 return getCount();
1041 }
1042
1043 std::shared_ptr<DepthFrame> depthFrame() const {
1044 auto frame = getFrame(OB_FRAME_DEPTH);
1045 if(frame == nullptr) {
1046 return nullptr;
1047 }
1048 auto depthFrame = frame->as<ob::DepthFrame>();
1049 return depthFrame;
1050 }
1051
1052 std::shared_ptr<ColorFrame> colorFrame() const {
1053 auto frame = getFrame(OB_FRAME_COLOR);
1054 if(frame == nullptr) {
1055 return nullptr;
1056 }
1057 auto colorFrame = frame->as<ob::ColorFrame>();
1058 return colorFrame;
1059 }
1060
1061 std::shared_ptr<IRFrame> irFrame() const {
1062 auto frame = getFrame(OB_FRAME_IR);
1063 if(frame == nullptr) {
1064 return nullptr;
1065 }
1066 auto irFrame = frame->as<ob::IRFrame>();
1067 return irFrame;
1068 }
1069
1070public:
1071 // The following interfaces are deprecated and are retained here for compatibility purposes.
1072 std::shared_ptr<PointsFrame> pointsFrame() const {
1073 auto frame = getFrame(OB_FRAME_POINTS);
1074 if(frame == nullptr) {
1075 return nullptr;
1076 }
1077 auto pointsFrame = frame->as<ob::PointsFrame>();
1078 return pointsFrame;
1079 }
1080
1081 std::shared_ptr<Frame> getFrame(int index) const {
1082 return getFrameByIndex(index);
1083 }
1084};
1085
1090public:
1100 static std::shared_ptr<Frame> createFrame(OBFrameType frameType, OBFormat format, uint32_t dataSize) {
1101 ob_error *error = nullptr;
1102 auto impl = ob_create_frame(frameType, format, dataSize, &error);
1103 Error::handle(&error);
1104
1105 return std::make_shared<Frame>(impl);
1106 }
1107
1120 static std::shared_ptr<VideoFrame> createVideoFrame(OBFrameType frameType, OBFormat format, uint32_t width, uint32_t height, uint32_t stride = 0) {
1121 ob_error *error = nullptr;
1122 auto impl = ob_create_video_frame(frameType, format, width, height, stride, &error);
1123 Error::handle(&error);
1124
1125 auto frame = std::make_shared<Frame>(impl);
1126 return frame->as<VideoFrame>();
1127 }
1128
1139 static std::shared_ptr<Frame> createFrameFromOtherFrame(std::shared_ptr<const Frame> otherFrame, bool shouldCopyData = true) {
1140 ob_error *error = nullptr;
1141 auto otherImpl = otherFrame->getImpl();
1142 auto impl = ob_create_frame_from_other_frame(otherImpl, shouldCopyData, &error);
1143 Error::handle(&error);
1144
1145 return std::make_shared<Frame>(impl);
1146 }
1147
1155 static std::shared_ptr<Frame> createFrameFromStreamProfile(std::shared_ptr<const StreamProfile> profile) {
1156 ob_error *error = nullptr;
1157 auto impl = ob_create_frame_from_stream_profile(profile->getImpl(), &error);
1158 Error::handle(&error);
1159
1160 return std::make_shared<Frame>(impl);
1161 }
1162
1166 typedef std::function<void(uint8_t *)> BufferDestroyCallback;
1167
1182 static std::shared_ptr<Frame> createFrameFromBuffer(OBFrameType frameType, OBFormat format, uint8_t *buffer, BufferDestroyCallback destroyCallback,
1183 uint32_t bufferSize) {
1184 ob_error *error = nullptr;
1185 auto ctx = new BufferDestroyContext{ destroyCallback };
1186 auto impl = ob_create_frame_from_buffer(frameType, format, buffer, bufferSize, &FrameFactory::BufferDestroy, ctx, &error);
1187 Error::handle(&error);
1188
1189 return std::make_shared<Frame>(impl);
1190 }
1191
1211 static std::shared_ptr<VideoFrame> createVideoFrameFromBuffer(OBFrameType frameType, OBFormat format, uint32_t width, uint32_t height, uint8_t *buffer,
1212 BufferDestroyCallback destroyCallback, uint32_t bufferSize, uint32_t stride = 0) {
1213 ob_error *error = nullptr;
1214 auto ctx = new BufferDestroyContext{ destroyCallback };
1215 auto impl = ob_create_video_frame_from_buffer(frameType, format, width, height, stride, buffer, bufferSize, &FrameFactory::BufferDestroy, ctx, &error);
1216 Error::handle(&error);
1217
1218 auto frame = std::make_shared<Frame>(impl);
1219 return frame->as<VideoFrame>();
1220 }
1221
1231 static std::shared_ptr<FrameSet> createFrameSet() {
1232 ob_error *error = nullptr;
1233 auto impl = ob_create_frameset(&error);
1234 Error::handle(&error);
1235 return std::make_shared<FrameSet>(impl);
1236 }
1237
1238private:
1239 struct BufferDestroyContext {
1240 BufferDestroyCallback callback;
1241 };
1242
1243 static void BufferDestroy(uint8_t *buffer, void *context) {
1244 auto *ctx = static_cast<BufferDestroyContext *>(context);
1245 if(ctx->callback) {
1246 ctx->callback(buffer);
1247 }
1248 delete ctx;
1249 }
1250};
1251
1257public:
1264 static void setFrameDeviceTimestampUs(std::shared_ptr<Frame> frame, uint64_t deviceTimestampUs) {
1265 ob_error *error = nullptr;
1266 auto impl = const_cast<ob_frame *>(frame->getImpl());
1267 ob_frame_set_timestamp_us(impl, deviceTimestampUs, &error);
1268 Error::handle(&error);
1269 }
1270
1271public:
1272 // The following interfaces are deprecated and are retained here for compatibility purposes.
1273 static void setFrameSystemTimestamp(std::shared_ptr<Frame> frame, uint64_t systemTimestamp) {
1274 // In order to compile, some high-version compilers will warn that the function parameters are not used.
1275 (void)frame;
1276 (void)systemTimestamp;
1277 }
1278
1279 static void setFrameDeviceTimestamp(std::shared_ptr<Frame> frame, uint64_t deviceTimestamp) {
1280 // In order to compile, some high-version compilers will warn that the function parameters are not used.
1281 (void)frame;
1282 (void)deviceTimestamp;
1283 }
1284};
1285
1286// Define the is() template function for the Frame class
1287template <typename T> bool Frame::is() const {
1288 switch(this->getType()) {
1289 case OB_FRAME_IR_LEFT: // Follow
1290 case OB_FRAME_IR_RIGHT: // Follow
1291 case OB_FRAME_IR:
1292 return (typeid(T) == typeid(IRFrame) || typeid(T) == typeid(VideoFrame));
1293 case OB_FRAME_DEPTH:
1294 return (typeid(T) == typeid(DepthFrame) || typeid(T) == typeid(VideoFrame));
1295 case OB_FRAME_COLOR:
1296 return (typeid(T) == typeid(ColorFrame) || typeid(T) == typeid(VideoFrame));
1298 return (typeid(T) == typeid(ConfidenceFrame) || typeid(T) == typeid(VideoFrame));
1299 case OB_FRAME_GYRO:
1300 return (typeid(T) == typeid(GyroFrame));
1301 case OB_FRAME_ACCEL:
1302 return (typeid(T) == typeid(AccelFrame));
1303 case OB_FRAME_POINTS:
1304 return (typeid(T) == typeid(PointsFrame));
1306 return (typeid(T) == typeid(LiDARPointsFrame));
1307 case OB_FRAME_SET:
1308 return (typeid(T) == typeid(FrameSet));
1309 default:
1310 std::cout << "ob::Frame::is() did not catch frame type: " << (int)this->getType() << std::endl;
1311 break;
1312 }
1313 return false;
1314}
1315
1316} // 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 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 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:204
enum ob_frame_metadata_type OBFrameMetadataType
OBFrameType
Enumeration value describing the type of frame.
Definition ObTypes.h:169
@ OB_FRAME_IR_RIGHT
Definition ObTypes.h:180
@ OB_FRAME_ACCEL
Definition ObTypes.h:175
@ OB_FRAME_GYRO
Definition ObTypes.h:178
@ OB_FRAME_IR_LEFT
Definition ObTypes.h:179
@ OB_FRAME_LIDAR_POINTS
Definition ObTypes.h:183
@ OB_FRAME_COLOR
Definition ObTypes.h:173
@ OB_FRAME_SET
Definition ObTypes.h:176
@ OB_FRAME_CONFIDENCE
Definition ObTypes.h:182
@ OB_FRAME_POINTS
Definition ObTypes.h:177
@ OB_FRAME_IR
Definition ObTypes.h:172
@ OB_FRAME_DEPTH
Definition ObTypes.h:174
OBPixelType
Enumeration value describing the pixel type of frame (usually used for depth frame)
Definition ObTypes.h:192
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:782
OBAccelValue value()
Definition Frame.hpp:817
OBAccelValue getValue() const
Get the accelerometer frame data.
Definition Frame.hpp:794
float getTemperature() const
Get the temperature when the frame was sampled.
Definition Frame.hpp:807
float temperature()
Definition Frame.hpp:821
~AccelFrame() noexcept override=default
AccelFrame(const ob_frame *impl)
Definition Frame.hpp:785
Define the ColorFrame class, which inherits from the VideoFrame classd.
Definition Frame.hpp:595
~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:607
Define the ConfidenceFrame class, which inherits from the VideoFrame class.
Definition Frame.hpp:688
~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:701
Define the DepthFrame class, which inherits from the VideoFrame class.
Definition Frame.hpp:615
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:639
~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:628
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:653
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:1089
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:1211
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:1100
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:1139
static std::shared_ptr< Frame > createFrameFromStreamProfile(std::shared_ptr< const StreamProfile > profile)
Create a Frame From (according to)Stream Profile object.
Definition Frame.hpp:1155
std::function< void(uint8_t *)> BufferDestroyCallback
The callback function to destroy the buffer when the frame is destroyed.
Definition Frame.hpp:1166
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:1182
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:1120
static std::shared_ptr< FrameSet > createFrameSet()
Create a new FrameSet object.
Definition Frame.hpp:1231
FrameHepler class, which provides some static functions to set timestamp for frame objects FrameHeple...
Definition Frame.hpp:1256
static void setFrameDeviceTimestamp(std::shared_ptr< Frame > frame, uint64_t deviceTimestamp)
Definition Frame.hpp:1279
static void setFrameDeviceTimestampUs(std::shared_ptr< Frame > frame, uint64_t deviceTimestampUs)
Set the device timestamp of the frame.
Definition Frame.hpp:1264
static void setFrameSystemTimestamp(std::shared_ptr< Frame > frame, uint64_t systemTimestamp)
Definition Frame.hpp:1273
std::shared_ptr< StreamProfile > getStreamProfile() const
get StreamProfile of the frame
Definition Frame.hpp:262
uint64_t systemTimeStampUs() const
Definition Frame.hpp:458
virtual ~Frame() noexcept
Destroy the Frame object.
Definition Frame.hpp:76
int64_t getMetadataValue(OBFrameMetadataType type) const
Get the metadata value.
Definition Frame.hpp:249
uint64_t timeStamp() const
Definition Frame.hpp:446
void updateMetadata(const uint8_t *metadata, uint32_t metadataSize)
Update the metadata of the frame.
Definition Frame.hpp:402
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:131
std::shared_ptr< Sensor > getSensor() const
get owner sensor of the frame
Definition Frame.hpp:274
std::shared_ptr< T > as()
Convert the frame object to a target type.
Definition Frame.hpp:311
void setSystemTimestampUs(uint64_t systemTimestampUs)
Set the system timestamp of the frame in microseconds.
Definition Frame.hpp:361
bool hasMetadata(OBFrameMetadataType type) const
Check if the frame object has metadata of a given type.
Definition Frame.hpp:234
void copyFrameInfo(std::shared_ptr< const Frame > srcFrame)
Copy the information of the source frame object to the destination frame object.
Definition Frame.hpp:348
uint32_t getMetadataSize() const
Get the size of the metadata of the frame.
Definition Frame.hpp:219
uint32_t metadataSize() const
Definition Frame.hpp:470
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:425
bool is() const
Check if the runtime type of the frame object is compatible with a given type.
Definition Frame.hpp:1287
uint64_t getTimeStampUs() const
Get the hardware timestamp of the frame in microseconds.
Definition Frame.hpp:160
std::shared_ptr< Device > getDevice() const
get owner device of the frame
Definition Frame.hpp:287
uint64_t globalTimeStampUs() const
Definition Frame.hpp:462
uint8_t * getMetadata() const
Get the metadata pointer of the frame.
Definition Frame.hpp:206
virtual uint64_t getIndex() const
Get the sequence number of the frame.
Definition Frame.hpp:118
virtual uint64_t index() const
Definition Frame.hpp:433
uint64_t timeStampUs() const
Definition Frame.hpp:450
uint8_t * metadata() const
Definition Frame.hpp:466
virtual void * data() const
Definition Frame.hpp:437
std::shared_ptr< const T > as() const
Convert the frame object to a target type.
Definition Frame.hpp:330
virtual uint32_t dataSize() const
Definition Frame.hpp:442
virtual uint32_t getDataSize() const
Get the size of the frame data.
Definition Frame.hpp:146
virtual OBFormat format() const
Definition Frame.hpp:429
uint64_t getSystemTimeStampUs() const
Get the system timestamp of the frame in microseconds.
Definition Frame.hpp:174
uint64_t getGlobalTimeStampUs() const
Get the global timestamp of the frame in microseconds.
Definition Frame.hpp:193
void updateData(const uint8_t *data, uint32_t dataSize)
Update the data of a frame.
Definition Frame.hpp:382
const ob_frame * getImpl() const
Get the internal (impl) frame object.
Definition Frame.hpp:69
uint64_t systemTimeStamp() const
Definition Frame.hpp:454
void setStreamProfile(std::shared_ptr< const StreamProfile > profile)
Set (override) the stream profile of the frame.
Definition Frame.hpp:415
Define the FrameSet class, which inherits from the Frame class.
Definition Frame.hpp:905
std::shared_ptr< ColorFrame > colorFrame() const
Definition Frame.hpp:1052
uint32_t getCount() const
Get the number of frames in the FrameSet.
Definition Frame.hpp:917
std::shared_ptr< IRFrame > getIrFrame() const
Get the infrared frame from the frameset.
Definition Frame.hpp:1012
std::shared_ptr< PointsFrame > pointsFrame() const
Definition Frame.hpp:1072
std::shared_ptr< DepthFrame > depthFrame() const
Definition Frame.hpp:1043
FrameSet(const ob_frame *impl)
Definition Frame.hpp:908
~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:948
std::shared_ptr< Frame > getFrame(int index) const
Definition Frame.hpp:1081
std::shared_ptr< IRFrame > irFrame() const
Definition Frame.hpp:1061
std::shared_ptr< Frame > getFrame(OBFrameType frameType) const
Get a frame of a specific type from the FrameSet.
Definition Frame.hpp:931
void pushFrame(std::shared_ptr< const Frame > frame) const
Push a frame to the FrameSet.
Definition Frame.hpp:965
uint32_t frameCount() const
Definition Frame.hpp:1039
std::shared_ptr< ColorFrame > getColorFrame() const
Get the color frame from the frameset.
Definition Frame.hpp:997
std::shared_ptr< PointsFrame > getPointsFrame() const
Get the point cloud frame from the frameset.
Definition Frame.hpp:1027
std::shared_ptr< DepthFrame > getDepthFrame() const
Get the depth frame from the frameset.
Definition Frame.hpp:982
Define the GyroFrame class, which inherits from the Frame class.
Definition Frame.hpp:829
~GyroFrame() noexcept override=default
OBGyroValue getValue() const
Get the gyro frame data.
Definition Frame.hpp:841
GyroFrame(const ob_frame *impl)
Definition Frame.hpp:832
OBGyroValue value()
Definition Frame.hpp:864
float temperature()
Definition Frame.hpp:868
float getTemperature() const
Get the temperature when the frame was sampled.
Definition Frame.hpp:854
Define the IRFrame class, which inherits from the VideoFrame class.
Definition Frame.hpp:666
IRFrame(const ob_frame *impl)
Construct a new IRFrame object with a given pointer to the internal frame object.
Definition Frame.hpp:679
~IRFrame() noexcept override=default
Define the LiDARPointsFrame class, which inherits from the Frame class.
Definition Frame.hpp:885
~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:897
Define the PointsFrame class, which inherits from the Frame class.
Definition Frame.hpp:714
uint32_t getHeight() const
Get the height of the frame.
Definition Frame.hpp:765
PointsFrame(const ob_frame *impl)
Construct a new PointsFrame object with a given pointer to the internal frame object.
Definition Frame.hpp:727
~PointsFrame() noexcept override=default
uint32_t getWidth() const
Get the width of the frame.
Definition Frame.hpp:751
float getCoordinateValueScale() const
Get the point coordinate value scale of the points frame. The point position value of the points fram...
Definition Frame.hpp:738
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:478
uint32_t width() const
Definition Frame.hpp:579
uint32_t getWidth() const
Get the width of the frame.
Definition Frame.hpp:498
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:569
uint8_t pixelAvailableBitSize() const
Definition Frame.hpp:587
OBPixelType getPixelType() const
Get the Pixel Type object.
Definition Frame.hpp:527
uint32_t getHeight() const
Get the height of the frame.
Definition Frame.hpp:511
uint8_t getPixelAvailableBitSize() const
Get the effective number of pixels in the frame.
Definition Frame.hpp:541
void setPixelType(OBPixelType pixelType)
Set video frame pixel format.
Definition Frame.hpp:554
uint32_t height() const
Definition Frame.hpp:583
~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:489
Definition Context.hpp:22
Data structures for accelerometers and gyroscopes.
Definition ObTypes.h:650
The error class exposed by the SDK, users can get detailed error information according to the error.
Definition ObTypes.h:119