1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
//! Frame module
use crate::{Format, error::OrbbecError, sys::frame::OBFrame};
/// Frame trait
pub trait Frame: From<OBFrame> + AsRef<OBFrame> {}
/// Single video frame
pub struct VideoFrame {
inner: OBFrame,
}
impl VideoFrame {
/// Get the raw data of the video frame
pub fn raw_data(&self) -> &[u8] {
// Unwrap is safe here because internal pointer is guaranteed to be valid
// SDK only returns error for this function if pointer is NULL
// Ref: https://github.com/orbbec/OrbbecSDK_v2/blob/815ae047cc977a1f7edd2b97b69ff6cd29f510b3/src/impl/Frame.cpp#L219
self.inner.get_data().unwrap()
}
/// Get the width of the video frame
pub fn width(&self) -> u16 {
// Unwrap is safe here because internal pointer is guaranteed to be valid and a video frame
// SDK only returns error for this function if pointer is NULL or not a video frame
// Ref: https://github.com/orbbec/OrbbecSDK_v2/blob/815ae047cc977a1f7edd2b97b69ff6cd29f510b3/src/impl/Frame.cpp#L129
self.inner.get_video_width().map(|w| w as u16).unwrap()
}
/// Get the height of the video frame
pub fn height(&self) -> u16 {
// Unwrap is safe here because internal pointer is guaranteed to be valid and a video frame
// SDK only returns error for this function if pointer is NULL or not a video frame
// Ref: https://github.com/orbbec/OrbbecSDK_v2/blob/815ae047cc977a1f7edd2b97b69ff6cd29f510b3/src/impl/Frame.cpp#L138
self.inner.get_video_height().map(|h| h as u16).unwrap()
}
/// Get the format of the video frame data
pub fn format(&self) -> Format {
// Unwrap is safe here because internal pointer is guaranteed to be valid and a video frame
// SDK only returns error for this function if pointer is NULL or not a video frame
// Ref: https://github.com/orbbec/OrbbecSDK_v2/blob/815ae047cc977a1f7edd2b97b69ff6cd29f510b3/src/impl/Frame.cpp#L147
self.inner.get_format().unwrap()
}
}
impl From<OBFrame> for VideoFrame {
fn from(frame: OBFrame) -> Self {
VideoFrame { inner: frame }
}
}
impl AsRef<OBFrame> for VideoFrame {
fn as_ref(&self) -> &OBFrame {
&self.inner
}
}
impl Frame for VideoFrame {}
/// A container of multiple frames.
pub struct FrameSet {
inner: OBFrame,
}
impl FrameSet {
/// Get the depth frame from the frameset
pub fn get_depth_frame(&self) -> Result<Option<VideoFrame>, OrbbecError> {
self.inner
.get_depth_frame()
.map_err(OrbbecError::from)
.map(|frame| frame.map(VideoFrame::from))
}
/// Get the color frame from the frameset
pub fn get_color_frame(&self) -> Result<Option<VideoFrame>, OrbbecError> {
self.inner
.get_color_frame()
.map_err(OrbbecError::from)
.map(|frame| frame.map(VideoFrame::from))
}
}
impl From<OBFrame> for FrameSet {
fn from(frame: OBFrame) -> Self {
FrameSet { inner: frame }
}
}
impl AsRef<OBFrame> for FrameSet {
fn as_ref(&self) -> &OBFrame {
&self.inner
}
}
impl Frame for FrameSet {}