Skip to content

Commit 8bcfa02

Browse files
committed
Add ability to fetch camera calibration params
Topic: vendor-submodule
1 parent 14a9e28 commit 8bcfa02

4 files changed

Lines changed: 30 additions & 88 deletions

File tree

src/pipeline.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ use crate::{
66
device::Device,
77
frame::FrameSet,
88
stream::{StreamProfile, StreamProfileList, VideoStreamProfile},
9-
sys::pipeline::{OBConfig, OBPipeline, frameset_trampoline},
9+
sys::{
10+
orb::OBCameraParam,
11+
pipeline::{OBConfig, OBPipeline, frameset_trampoline},
12+
},
1013
};
1114

1215
/// Pipeline Configuration
@@ -133,6 +136,13 @@ impl Pipeline {
133136
Ok(profile_list)
134137
}
135138

139+
/// Get the camera parameters for the pipeline
140+
pub fn get_camera_param(&mut self) -> Result<OBCameraParam, crate::error::OrbbecError> {
141+
self.inner
142+
.get_camera_param()
143+
.map_err(crate::error::OrbbecError::from)
144+
}
145+
136146
/// Start the pipeline with the given configuration
137147
/// ### Arguments
138148
/// * `config` - Configuration to use for the pipeline

src/stream.rs

Lines changed: 6 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -2,42 +2,14 @@
22
use crate::{
33
Format,
44
error::OrbbecError,
5-
sys::stream::{OBCameraIntrinsic, OBStreamProfile, OBStreamProfileList},
5+
sys::{
6+
orb::OBCameraIntrinsic,
7+
stream::{OBStreamProfile, OBStreamProfileList},
8+
},
69
};
710

811
/// Stream profile trait
912
pub trait StreamProfile: AsRef<OBStreamProfile> {}
10-
11-
/// Camera intrinsic for a stream
12-
#[derive(Debug, Clone, Copy, PartialEq)]
13-
pub struct CameraIntrinsic {
14-
/// Focal length in pixels along X axis
15-
pub fx: f32,
16-
/// Focal length in pixels along Y axis
17-
pub fy: f32,
18-
/// Optical center abscissa
19-
pub cx: f32,
20-
/// Optical center ordinate
21-
pub cy: f32,
22-
/// Image width in pixels
23-
pub width: u16,
24-
/// Image height in pixels
25-
pub height: u16,
26-
}
27-
28-
impl From<OBCameraIntrinsic> for CameraIntrinsic {
29-
fn from(intrinsic: OBCameraIntrinsic) -> Self {
30-
CameraIntrinsic {
31-
fx: intrinsic.fx(),
32-
fy: intrinsic.fy(),
33-
cx: intrinsic.cx(),
34-
cy: intrinsic.cy(),
35-
width: intrinsic.width() as u16,
36-
height: intrinsic.height() as u16,
37-
}
38-
}
39-
}
40-
4113
/// Video Stream profile
4214
pub struct VideoStreamProfile {
4315
inner: OBStreamProfile,
@@ -53,11 +25,8 @@ impl VideoStreamProfile {
5325
}
5426

5527
/// Get the camera intrinsic parameters for this video stream profile
56-
pub fn get_intrinsic(&self) -> Result<CameraIntrinsic, OrbbecError> {
57-
self.inner
58-
.get_video_intrinsic()
59-
.map(|intrinsic| intrinsic.into())
60-
.map_err(OrbbecError::from)
28+
pub fn get_intrinsic(&self) -> Result<OBCameraIntrinsic, OrbbecError> {
29+
self.inner.get_video_intrinsic().map_err(OrbbecError::from)
6130
}
6231

6332
/// Get the width of this video stream profile in pixels

src/sys/pipeline.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//! Pipeline configuration and management
2-
use crate::sys::orb::{OBAlignMode, OBFrameAggregateOutputMode, OBSensorType};
2+
use crate::sys::orb::{OBAlignMode, OBCameraParam, OBFrameAggregateOutputMode, OBSensorType};
33

44
use super::device::OBDevice;
55
use super::frame::OBFrame;
@@ -112,6 +112,12 @@ impl OBPipeline {
112112
orb::ob_pipeline_enable_frame_sync,
113113
);
114114

115+
impl_ob_method!(
116+
/// Get the camera parameters for the pipeline
117+
get_camera_param => OBCameraParam,
118+
orb::ob_pipeline_get_camera_param,
119+
);
120+
115121
impl_ob_method!(
116122
/// Disable frame synchronization
117123
disable_frame_sync => (),

src/sys/stream.rs

Lines changed: 6 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,6 @@
11
//! Stream profiles and related operations
22
use super::{OBError, call_ob_function, drop_ob_object, impl_ob_method, orb};
3-
use crate::sys::orb::OBFormat;
4-
5-
/// Camera intrinsic parameters
6-
pub struct OBCameraIntrinsic {
7-
inner: orb::OBCameraIntrinsic,
8-
}
9-
10-
impl OBCameraIntrinsic {
11-
/// Focal length in pixels along X axis
12-
pub fn fx(&self) -> f32 {
13-
self.inner.fx
14-
}
15-
16-
/// Focal length in pixels along Y axis
17-
pub fn fy(&self) -> f32 {
18-
self.inner.fy
19-
}
20-
21-
/// Optical center abscissa
22-
pub fn cx(&self) -> f32 {
23-
self.inner.cx
24-
}
25-
26-
/// Optical center ordinate
27-
pub fn cy(&self) -> f32 {
28-
self.inner.cy
29-
}
30-
31-
/// Image width in pixels
32-
pub fn width(&self) -> i16 {
33-
self.inner.width
34-
}
35-
36-
/// Image height in pixels
37-
pub fn height(&self) -> i16 {
38-
self.inner.height
39-
}
40-
}
41-
42-
impl From<orb::OBCameraIntrinsic> for OBCameraIntrinsic {
43-
fn from(intrinsic: orb::OBCameraIntrinsic) -> Self {
44-
OBCameraIntrinsic { inner: intrinsic }
45-
}
46-
}
3+
use crate::sys::orb::{OBCameraIntrinsic, OBFormat};
474

485
/// Stream profile
496
pub struct OBStreamProfile {
@@ -61,11 +18,11 @@ impl OBStreamProfile {
6118
self.inner
6219
}
6320

64-
/// Get video stream profile intrinsic
65-
pub fn get_video_intrinsic(&self) -> Result<OBCameraIntrinsic, OBError> {
66-
let intrinsics = call_ob_function!(orb::ob_video_stream_profile_get_intrinsic, self.inner)?;
67-
Ok(OBCameraIntrinsic::from(intrinsics))
68-
}
21+
impl_ob_method!(
22+
/// Get video stream profile intrinsic
23+
get_video_intrinsic => OBCameraIntrinsic,
24+
orb::ob_video_stream_profile_get_intrinsic,
25+
);
6926

7027
impl_ob_method!(
7128
/// Get stream profile format

0 commit comments

Comments
 (0)