| OrbbecSDK 1.10.18 OrbbecSDK: Software-Development-Kit for Orbbec 3D Cameras

Loading...
Searching...
No Matches
Frame.hpp
Go to the documentation of this file.
1
6#pragma once
7
8#include "Types.hpp"
9
10#include <memory>
11#include <iostream>
12#include <typeinfo>
13
31 struct FrameImpl;
32
33 namespace ob {
34 class Device;
35 class Sensor;
36 class StreamProfile;
37 class Filter;
38 class FrameHelper;
39
40 typedef std::function<void(void *buffer, void *context)> BufferDestroyCallback;
41
42 class OB_EXTENSION_API Frame : public std::enable_shared_from_this<Frame> {
43 protected:
44 std::unique_ptr<FrameImpl> impl_;
45
46 public:
47 explicit Frame(std::unique_ptr<FrameImpl> impl);
48 Frame(Frame &frame);
49
50 virtual ~Frame() noexcept;
51
57 virtual OBFrameType type();
58
64 virtual OBFormat format();
65
71 virtual uint64_t index();
72
78 virtual void *data();
79
87 virtual uint32_t dataSize();
88
95 uint64_t timeStamp();
96
103 uint64_t timeStampUs();
104
111 uint64_t systemTimeStamp();
112
119 uint64_t systemTimeStampUs();
120
131 uint64_t globalTimeStampUs();
132
138 void *metadata();
139
145 uint32_t metadataSize();
146
153 bool hasMetadata(OBFrameMetadataType type);
154
161 int64_t getMetadataValue(OBFrameMetadataType type);
162
168 std::shared_ptr<StreamProfile> getStreamProfile();
169
175 std::shared_ptr<Sensor> getSensor();
176
182 std::shared_ptr<Device> getDevice();
183
190 template <typename T> bool is();
191
198 template <typename T> std::shared_ptr<T> as() {
199 if(!is<T>()) {
200 throw std::runtime_error("unsupported operation, object's type is not require type");
201 }
202
203 return std::dynamic_pointer_cast<T>(shared_from_this());
204 }
205
206 private:
207 friend class Filter;
208 friend class Recorder;
209 friend class FrameHelper;
210 friend class CoordinateTransformHelper;
211};
212
213 class OB_EXTENSION_API VideoFrame : public Frame {
214 public:
215 explicit VideoFrame(Frame &frame);
216
217 explicit VideoFrame(std::unique_ptr<FrameImpl> impl);
218
219 ~VideoFrame() noexcept override = default;
220
226 uint32_t width();
227
233 uint32_t height();
234
241 uint8_t pixelAvailableBitSize();
242};
243
244class OB_EXTENSION_API ColorFrame : public VideoFrame {
245 public:
246 explicit ColorFrame(Frame &frame);
247
248 explicit ColorFrame(std::unique_ptr<FrameImpl> impl);
249
250 ~ColorFrame() noexcept override = default;
251};
252
253class OB_EXTENSION_API DepthFrame : public VideoFrame {
254 public:
255 explicit DepthFrame(Frame &frame);
256
257 explicit DepthFrame(std::unique_ptr<FrameImpl> impl);
258
259 ~DepthFrame() noexcept override = default;
260
268 float getValueScale();
269};
270
271class OB_EXTENSION_API IRFrame : public VideoFrame {
272 public:
273 explicit IRFrame(Frame &frame);
274
275 explicit IRFrame(std::unique_ptr<FrameImpl> impl);
276
277 ~IRFrame() noexcept override = default;
278
279public:
280 OBSensorType getDataSource();
281};
282
283class OB_EXTENSION_API PointsFrame : public Frame {
284 public:
285 explicit PointsFrame(Frame &frame);
286
287 explicit PointsFrame(std::unique_ptr<FrameImpl> impl);
288
289 ~PointsFrame() noexcept override = default;
290
298 float getPositionValueScale();
299};
300
305class OB_EXTENSION_API FrameSet : public Frame {
306
307 public:
308 explicit FrameSet(std::unique_ptr<FrameImpl> impl);
309
310 explicit FrameSet(Frame &frame);
311
312 ~FrameSet() noexcept override;
313
319 uint32_t frameCount();
320
326 std::shared_ptr<DepthFrame> depthFrame();
327
333 std::shared_ptr<ColorFrame> colorFrame();
334
340 std::shared_ptr<IRFrame> irFrame();
341
347 std::shared_ptr<PointsFrame> pointsFrame();
348
355 std::shared_ptr<Frame> getFrame(OBFrameType frameType);
356
363 std::shared_ptr<Frame> getFrame(int index);
364
365 // Declare Pipeline and Filter classes as friends
366 friend class Pipeline;
367 friend class Filter;
368};
369
374class OB_EXTENSION_API AccelFrame : public Frame {
375 public:
376 explicit AccelFrame(Frame &frame);
377
378 explicit AccelFrame(std::unique_ptr<FrameImpl> impl);
379
380 ~AccelFrame() noexcept override = default;
381
387 OBAccelValue value();
388
394 float temperature();
395};
396
400class OB_EXTENSION_API GyroFrame : public Frame {
401 public:
402 explicit GyroFrame(Frame &frame);
403
404 explicit GyroFrame(std::unique_ptr<FrameImpl> impl);
405
406 ~GyroFrame() noexcept override = default;
407
413 OBGyroValue value();
414
420 float temperature();
421};
422
426class OB_EXTENSION_API RawPhaseFrame : public VideoFrame {
427 public:
428 explicit RawPhaseFrame(Frame &frame);
429
430 explicit RawPhaseFrame(std::unique_ptr<FrameImpl> impl);
431
432 ~RawPhaseFrame() noexcept override = default;
433};
434
438class OB_EXTENSION_API FrameHelper {
439 public:
452 static std::shared_ptr<Frame> createFrame(OBFrameType type, OBFormat format, uint32_t width, uint32_t height, uint32_t strideBytes);
453
467 static std::shared_ptr<Frame> createFrameFromBuffer(OBFormat format, uint32_t width, uint32_t height, uint8_t *buffer, uint32_t bufferSize,
468 BufferDestroyCallback destroyCallback, void *destroyCallbackContext);
469
475 static std::shared_ptr<FrameSet> createFrameSet();
476
484 static void pushFrame(std::shared_ptr<Frame> frameSet, OBFrameType frameType, std::shared_ptr<Frame> frame);
485
492 static void setFrameSystemTimestamp(std::shared_ptr<Frame> frame, uint64_t systemTimestamp);
493
500 static void setFrameDeviceTimestamp(std::shared_ptr<Frame> frame, uint64_t deviceTimestamp);
501
508 static void setFrameDeviceTimestampUs(std::shared_ptr<Frame> frame, uint64_t deviceTimestampUs);
509};
510
511// Define the is() template function for the Frame class
512 template <typename T> bool Frame::is() {
513 switch(this->type()) {
514 case OB_FRAME_IR_LEFT: // Follow
515 case OB_FRAME_IR_RIGHT: // Follow
516 case OB_FRAME_IR:
517 return (typeid(T) == typeid(IRFrame) || typeid(T) == typeid(VideoFrame));
518 case OB_FRAME_DEPTH:
519 return (typeid(T) == typeid(DepthFrame) || typeid(T) == typeid(VideoFrame));
520 case OB_FRAME_COLOR:
521 return (typeid(T) == typeid(ColorFrame) || typeid(T) == typeid(VideoFrame));
522 case OB_FRAME_GYRO:
523 return (typeid(T) == typeid(GyroFrame));
524 case OB_FRAME_ACCEL:
525 return (typeid(T) == typeid(AccelFrame));
526 case OB_FRAME_SET:
527 return (typeid(T) == typeid(FrameSet));
528 case OB_FRAME_POINTS:
529 return (typeid(T) == typeid(PointsFrame));
530 case OB_FRAME_RAW_PHASE:
531 return (typeid(T) == typeid(RawPhaseFrame) || typeid(T) == typeid(VideoFrame));
532 default:
533 std::cout << "ob::Frame::is() did not catch frame type: " << (int)this->type() << std::endl;
534 break;
535 }
536 return false;
537}
538} // namespace ob
OBSensorType
OBSensorType
Enumeration value describing the sensor type.
Definition ObTypes.h:162
OBFormat
OBFormat
Enumeration value describing the pixel format.
Definition ObTypes.h:216
OBFrameMetadataType
enum ob_frame_metadata_type OBFrameMetadataType
OBFrameType
OBFrameType
Enumeration value describing the type of frame.
Definition ObTypes.h:196
OB_FRAME_IR_RIGHT
@ OB_FRAME_IR_RIGHT
Definition ObTypes.h:207
OB_FRAME_ACCEL
@ OB_FRAME_ACCEL
Definition ObTypes.h:202
OB_FRAME_GYRO
@ OB_FRAME_GYRO
Definition ObTypes.h:205
OB_FRAME_IR_LEFT
@ OB_FRAME_IR_LEFT
Definition ObTypes.h:206
OB_FRAME_COLOR
@ OB_FRAME_COLOR
Definition ObTypes.h:200
OB_FRAME_RAW_PHASE
@ OB_FRAME_RAW_PHASE
Definition ObTypes.h:208
OB_FRAME_SET
@ OB_FRAME_SET
Definition ObTypes.h:203
OB_FRAME_POINTS
@ OB_FRAME_POINTS
Definition ObTypes.h:204
OB_FRAME_IR
@ OB_FRAME_IR
Definition ObTypes.h:199
OB_FRAME_DEPTH
@ OB_FRAME_DEPTH
Definition ObTypes.h:201
OB_EXTENSION_API
#define OB_EXTENSION_API
Definition ObTypes.h:28
Types.hpp
Provides SDK structure and enumeration constant definitions (depending on libobsensor/h/ObTypes....
ob::AccelFrame
Define the AccelFrame class, which inherits from the Frame class.
Definition Frame.hpp:374
ob::AccelFrame::AccelFrame
AccelFrame(std::unique_ptr< FrameImpl > impl)
ob::AccelFrame::AccelFrame
AccelFrame(Frame &frame)
ob::AccelFrame::~AccelFrame
~AccelFrame() noexcept override=default
ob::ColorFrame
Definition Frame.hpp:244
ob::ColorFrame::~ColorFrame
~ColorFrame() noexcept override=default
ob::ColorFrame::ColorFrame
ColorFrame(Frame &frame)
ob::ColorFrame::ColorFrame
ColorFrame(std::unique_ptr< FrameImpl > impl)
ob::CoordinateTransformHelper
Definition Utils.hpp:13
ob::DepthFrame
Definition Frame.hpp:253
ob::DepthFrame::DepthFrame
DepthFrame(Frame &frame)
ob::DepthFrame::~DepthFrame
~DepthFrame() noexcept override=default
ob::DepthFrame::DepthFrame
DepthFrame(std::unique_ptr< FrameImpl > impl)
ob::Device
Definition Device.hpp:29
ob::Filter
The Filter class is the base class for all filters in the SDK.
Definition Filter.hpp:27
ob::FrameHelper
Define the FrameHelper class.
Definition Frame.hpp:438
ob::FrameHelper::createFrame
static std::shared_ptr< Frame > createFrame(OBFrameType type, OBFormat format, uint32_t width, uint32_t height, uint32_t strideBytes)
Create a Frame object.
ob::FrameHelper::setFrameDeviceTimestamp
static void setFrameDeviceTimestamp(std::shared_ptr< Frame > frame, uint64_t deviceTimestamp)
Set the device timestamp of the frame.
ob::FrameHelper::createFrameFromBuffer
static std::shared_ptr< Frame > createFrameFromBuffer(OBFormat format, uint32_t width, uint32_t height, uint8_t *buffer, uint32_t bufferSize, BufferDestroyCallback destroyCallback, void *destroyCallbackContext)
Create a frame object based on an externally created buffer.
ob::FrameHelper::setFrameDeviceTimestampUs
static void setFrameDeviceTimestampUs(std::shared_ptr< Frame > frame, uint64_t deviceTimestampUs)
Set the device timestamp of the frame.
ob::FrameHelper::pushFrame
static void pushFrame(std::shared_ptr< Frame > frameSet, OBFrameType frameType, std::shared_ptr< Frame > frame)
Add a frame of a specific type to the FrameSet.
ob::FrameHelper::createFrameSet
static std::shared_ptr< FrameSet > createFrameSet()
Create an empty FrameSet object.
ob::FrameHelper::setFrameSystemTimestamp
static void setFrameSystemTimestamp(std::shared_ptr< Frame > frame, uint64_t systemTimestamp)
Set the system timestamp of the frame.
ob::FrameSet
Define the FrameSet class, which inherits from the Frame class.
Definition Frame.hpp:305
ob::FrameSet::~FrameSet
~FrameSet() noexcept override
ob::FrameSet::FrameSet
FrameSet(Frame &frame)
ob::FrameSet::FrameSet
FrameSet(std::unique_ptr< FrameImpl > impl)
ob::Frame
Definition Frame.hpp:42
ob::Frame::~Frame
virtual ~Frame() noexcept
ob::Frame::Frame
Frame(Frame &frame)
ob::Frame::impl_
std::unique_ptr< FrameImpl > impl_
Definition Frame.hpp:44
ob::Frame::Frame
Frame(std::unique_ptr< FrameImpl > impl)
ob::GyroFrame
Define the GyroFrame class, which inherits from the Frame class.
Definition Frame.hpp:400
ob::GyroFrame::~GyroFrame
~GyroFrame() noexcept override=default
ob::GyroFrame::GyroFrame
GyroFrame(Frame &frame)
ob::GyroFrame::GyroFrame
GyroFrame(std::unique_ptr< FrameImpl > impl)
ob::IRFrame
Definition Frame.hpp:271
ob::IRFrame::IRFrame
IRFrame(Frame &frame)
ob::IRFrame::IRFrame
IRFrame(std::unique_ptr< FrameImpl > impl)
ob::IRFrame::~IRFrame
~IRFrame() noexcept override=default
ob::Pipeline
Definition Pipeline.hpp:28
ob::PointsFrame
Definition Frame.hpp:283
ob::PointsFrame::~PointsFrame
~PointsFrame() noexcept override=default
ob::PointsFrame::PointsFrame
PointsFrame(std::unique_ptr< FrameImpl > impl)
ob::PointsFrame::PointsFrame
PointsFrame(Frame &frame)
ob::RawPhaseFrame
Define the RawPhaseFrame class, which inherits from the VideoFrame class.
Definition Frame.hpp:426
ob::RawPhaseFrame::RawPhaseFrame
RawPhaseFrame(std::unique_ptr< FrameImpl > impl)
ob::RawPhaseFrame::RawPhaseFrame
RawPhaseFrame(Frame &frame)
ob::RawPhaseFrame::~RawPhaseFrame
~RawPhaseFrame() noexcept override=default
ob::Recorder
Definition RecordPlayback.hpp:23
ob::Sensor
Definition Sensor.hpp:31
ob::StreamProfile
Definition StreamProfile.hpp:22
ob::VideoFrame
Definition Frame.hpp:213
ob::VideoFrame::VideoFrame
VideoFrame(std::unique_ptr< FrameImpl > impl)
ob::VideoFrame::~VideoFrame
~VideoFrame() noexcept override=default
ob::VideoFrame::VideoFrame
VideoFrame(Frame &frame)
ob
Definition Context.hpp:16
ob::BufferDestroyCallback
std::function< void(void *buffer, void *context)> BufferDestroyCallback
Definition Frame.hpp:40
OBAccelValue
Data structures for accelerometers and gyroscopes.
Definition ObTypes.h:635