Skip to content

Commit 5bd71fa

Browse files
committed
add doc
1 parent 5d53ae1 commit 5bd71fa

File tree

3 files changed

+98
-1
lines changed

3 files changed

+98
-1
lines changed

.github/workflows/rust.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: Basic check
2+
3+
on:
4+
push:
5+
branches: [ "main" ]
6+
pull_request:
7+
branches: [ "main" ]
8+
9+
env:
10+
CARGO_TERM_COLOR: always
11+
12+
jobs:
13+
build:
14+
15+
runs-on: ubuntu-latest
16+
17+
steps:
18+
- uses: actions/checkout@v4
19+
- name: Format
20+
run: cargo fmt --check --verbose
21+
- name: Linting
22+
run: cargo clippy
23+
- name: Doc
24+
run: cargo test --doc
25+
- name: Build
26+
run: cargo build --verbose

examples/remap.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ fn main() {
2020
model_to_json("eucm.json", &GenericModel::EUCM(model0));
2121
let model1 = model_from_json("data/eucm0.json");
2222
let new_w_h = 1024;
23-
let p = model1.estimate_new_camera_matrix_for_undistort(1.0, Some((new_w_h, new_w_h)));
23+
let p = model1.estimate_new_camera_matrix_for_undistort(0.0, Some((new_w_h, new_w_h)));
2424
let (xmap, ymap) = model1.init_undistort_map(&p, (new_w_h, new_w_h), None);
2525
let remaped = remap(&img, &xmap, &ymap);
2626
remaped.save("remaped.png").unwrap()

src/generic_functions.rs

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,25 @@ use super::generic_model::*;
33
use nalgebra as na;
44
use rayon::prelude::*;
55

6+
/// Returns xmap and ymap for remaping
7+
///
8+
/// # Arguments
9+
///
10+
/// * `camera_model` - any camera model
11+
/// * `projection_mat` - new camera matrix for the undistorted image
12+
/// * `new_w_h` - new image width and height for the undistorted image
13+
/// * `rotation` - Optional rotation, normally for stereo rectify
14+
///
15+
/// # Examples
16+
///
17+
/// ```
18+
/// use camera_intrinsic_model::*;
19+
/// let model = model_from_json("eucm.json");
20+
/// let new_w_h = 1024;
21+
/// let p = model.estimate_new_camera_matrix_for_undistort(0.0, Some((new_w_h, new_w_h)));
22+
/// let (xmap, ymap) = model.init_undistort_map(&p, (new_w_h, new_w_h), None);
23+
/// // let remaped = remap(&img, &xmap, &ymap);
24+
/// ```
625
pub fn init_undistort_map(
726
camera_model: &dyn CameraModel<f64>,
827
projection_mat: &na::Matrix3<f64>,
@@ -48,6 +67,23 @@ pub fn init_undistort_map(
4867
(xmap, ymap)
4968
}
5069

70+
/// Returns xmap and ymap for remaping
71+
///
72+
/// # Arguments
73+
///
74+
/// * `camera_model` - any camera model
75+
/// * `balance` - [0-1] zero means no black margin
76+
/// * `new_image_w_h` - optional new image width and height, default using the original w, h
77+
///
78+
/// # Examples
79+
///
80+
/// ```
81+
/// use camera_intrinsic_model::*;
82+
/// let model = model_from_json("eucm.json");
83+
/// let new_w_h = 1024;
84+
/// let p = model.estimate_new_camera_matrix_for_undistort(0.0, Some((new_w_h, new_w_h)));
85+
/// let (xmap, ymap) = model.init_undistort_map(&p, (new_w_h, new_w_h), None);
86+
/// ```
5187
pub fn estimate_new_camera_matrix_for_undistort(
5288
camera_model: &dyn CameraModel<f64>,
5389
balance: f64,
@@ -102,6 +138,41 @@ pub fn estimate_new_camera_matrix_for_undistort(
102138
out
103139
}
104140

141+
/// Returns xmap and ymap for remaping
142+
///
143+
/// # Arguments
144+
///
145+
/// * `camera_model` - any camera model
146+
/// * `balance` - [0-1] zero means no black margin
147+
/// * `new_image_w_h` - optional new image width and height, default using the original w, h
148+
///
149+
/// # Examples
150+
///
151+
/// ```
152+
/// use camera_intrinsic_model::*;
153+
/// use nalgebra as na;
154+
/// let model0 = model_from_json("data/eucm0.json");
155+
/// let model1 = model_from_json("data/eucm1.json");
156+
/// let tvec = na::Vector3::new(
157+
/// -0.10098947190325333,
158+
/// -0.0020811599784744455,
159+
/// -0.0012888359197775197,
160+
/// );
161+
/// let quat = na::Quaternion::new(
162+
/// 0.9997158799903332,
163+
/// 0.02382966001551074,
164+
/// -0.00032454324393309654,
165+
/// 0.00044863167728445325,
166+
/// );
167+
/// let rvec = na::UnitQuaternion::from_quaternion(quat).scaled_axis();
168+
/// let (r0, r1, p) = stereo_rectify(&model0, &model1, &rvec, &tvec, None);
169+
/// let image_w_h = (
170+
/// model0.width().round() as u32,
171+
/// model0.height().round() as u32,
172+
/// );
173+
/// let (xmap0, ymap0) = model0.init_undistort_map(&p, image_w_h, Some(r0));
174+
/// let (xmap1, ymap1) = model1.init_undistort_map(&p, image_w_h, Some(r1));
175+
/// ```
105176
pub fn stereo_rectify(
106177
camera_model0: &GenericModel<f64>,
107178
camera_model1: &GenericModel<f64>,

0 commit comments

Comments
 (0)