@@ -3,6 +3,25 @@ use super::generic_model::*;
3
3
use nalgebra as na;
4
4
use rayon:: prelude:: * ;
5
5
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
+ /// ```
6
25
pub fn init_undistort_map (
7
26
camera_model : & dyn CameraModel < f64 > ,
8
27
projection_mat : & na:: Matrix3 < f64 > ,
@@ -48,6 +67,23 @@ pub fn init_undistort_map(
48
67
( xmap, ymap)
49
68
}
50
69
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
+ /// ```
51
87
pub fn estimate_new_camera_matrix_for_undistort (
52
88
camera_model : & dyn CameraModel < f64 > ,
53
89
balance : f64 ,
@@ -102,6 +138,41 @@ pub fn estimate_new_camera_matrix_for_undistort(
102
138
out
103
139
}
104
140
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
+ /// ```
105
176
pub fn stereo_rectify (
106
177
camera_model0 : & GenericModel < f64 > ,
107
178
camera_model1 : & GenericModel < f64 > ,
0 commit comments