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
31struct FrameImpl;
32
33namespace ob {
34class Device;
35class Sensor;
36class StreamProfile;
37class Filter;
38class FrameHelper;
39
40typedef std::function<void(void *buffer, void *context)> BufferDestroyCallback;
41
42class OB_EXTENSION_API Frame : public std::enable_shared_from_this<Frame> {
43protected:
44 std::unique_ptr<FrameImpl> impl_;
45
46public:
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
206private:
207 friend class Filter;
208 friend class Recorder;
209 friend class FrameHelper;
211};
212
214public:
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
245public:
246 explicit ColorFrame(Frame &frame);
247
248 explicit ColorFrame(std::unique_ptr<FrameImpl> impl);
249
250 ~ColorFrame() noexcept override = default;
251};
252
254public:
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
272public:
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
284public:
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
306
307public:
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
375public:
376 explicit AccelFrame(Frame &frame);
377
378 explicit AccelFrame(std::unique_ptr<FrameImpl> impl);
379
380 ~AccelFrame() noexcept override = default;
381
388
394 float temperature();
395};
396
401public:
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
427public:
428 explicit RawPhaseFrame(Frame &frame);
429
430 explicit RawPhaseFrame(std::unique_ptr<FrameImpl> impl);
431
432 ~RawPhaseFrame() noexcept override = default;
433};
434
439public:
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
512template <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));
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
Enumeration value describing the sensor type.
Definition ObTypes.h:162
OBFormat
Enumeration value describing the pixel format.
Definition ObTypes.h:216
enum ob_frame_metadata_type OBFrameMetadataType
OBFrameType
Enumeration value describing the type of frame.
Definition ObTypes.h:196
@ OB_FRAME_IR_RIGHT
Definition ObTypes.h:207
@ OB_FRAME_ACCEL
Definition ObTypes.h:202
@ OB_FRAME_GYRO
Definition ObTypes.h:205
@ OB_FRAME_IR_LEFT
Definition ObTypes.h:206
@ OB_FRAME_COLOR
Definition ObTypes.h:200
@ OB_FRAME_RAW_PHASE
Definition ObTypes.h:208
@ OB_FRAME_SET
Definition ObTypes.h:203
@ OB_FRAME_POINTS
Definition ObTypes.h:204
@ OB_FRAME_IR
Definition ObTypes.h:199
@ OB_FRAME_DEPTH
Definition ObTypes.h:201
#define OB_EXTENSION_API
Definition ObTypes.h:28
Provides SDK structure and enumeration constant definitions (depending on libobsensor/h/ObTypes....
Define the AccelFrame class, which inherits from the Frame class.
Definition Frame.hpp:374
AccelFrame(std::unique_ptr< FrameImpl > impl)
AccelFrame(Frame &frame)
~AccelFrame() noexcept override=default
~ColorFrame() noexcept override=default
ColorFrame(Frame &frame)
ColorFrame(std::unique_ptr< FrameImpl > impl)
DepthFrame(Frame &frame)
~DepthFrame() noexcept override=default
DepthFrame(std::unique_ptr< FrameImpl > impl)
The Filter class is the base class for all filters in the SDK.
Definition Filter.hpp:27
Define the FrameHelper class.
Definition Frame.hpp:438
static std::shared_ptr< Frame > createFrame(OBFrameType type, OBFormat format, uint32_t width, uint32_t height, uint32_t strideBytes)
Create a Frame object.
static void setFrameDeviceTimestamp(std::shared_ptr< Frame > frame, uint64_t deviceTimestamp)
Set the device timestamp of the frame.
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.
static void setFrameDeviceTimestampUs(std::shared_ptr< Frame > frame, uint64_t deviceTimestampUs)
Set the device timestamp of the frame.
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.
static std::shared_ptr< FrameSet > createFrameSet()
Create an empty FrameSet object.
static void setFrameSystemTimestamp(std::shared_ptr< Frame > frame, uint64_t systemTimestamp)
Set the system timestamp of the frame.
Define the FrameSet class, which inherits from the Frame class.
Definition Frame.hpp:305
~FrameSet() noexcept override
FrameSet(Frame &frame)
FrameSet(std::unique_ptr< FrameImpl > impl)
virtual ~Frame() noexcept
Frame(Frame &frame)
std::unique_ptr< FrameImpl > impl_
Definition Frame.hpp:44
Frame(std::unique_ptr< FrameImpl > impl)
Define the GyroFrame class, which inherits from the Frame class.
Definition Frame.hpp:400
~GyroFrame() noexcept override=default
GyroFrame(Frame &frame)
GyroFrame(std::unique_ptr< FrameImpl > impl)
IRFrame(Frame &frame)
IRFrame(std::unique_ptr< FrameImpl > impl)
~IRFrame() noexcept override=default
~PointsFrame() noexcept override=default
PointsFrame(std::unique_ptr< FrameImpl > impl)
PointsFrame(Frame &frame)
Define the RawPhaseFrame class, which inherits from the VideoFrame class.
Definition Frame.hpp:426
RawPhaseFrame(std::unique_ptr< FrameImpl > impl)
RawPhaseFrame(Frame &frame)
~RawPhaseFrame() noexcept override=default
VideoFrame(std::unique_ptr< FrameImpl > impl)
~VideoFrame() noexcept override=default
VideoFrame(Frame &frame)
Definition Context.hpp:16
std::function< void(void *buffer, void *context)> BufferDestroyCallback
Definition Frame.hpp:40
Data structures for accelerometers and gyroscopes.
Definition ObTypes.h:635