|
1 | | -//! Geometric models of OpenCV/ROS cameras for photogrammetry |
2 | | -//! |
3 | | -//! # About |
4 | | -//! |
5 | | -//! This crate provides a geometric model of a camera compatible with OpenCV as |
6 | | -//! used by ROS (the Robot Operating System). The crate is in pure Rust, can be |
7 | | -//! compiled in `no_std` mode, implements the |
8 | | -//! [`IntrinsicParameters`](https://docs.rs/cam-geom/latest/cam_geom/trait.IntrinsicParameters.html) |
9 | | -//! trait from the [`cam-geom`](https://crates.io/crates/cam-geom) and provides |
10 | | -//! support to read and write camera models in various formats. |
11 | | -//! |
12 | | -//! In greater detail: |
13 | | -//! |
14 | | -//! - Compatible with camera calibrations made by the ROS |
15 | | -//! [`camera_calibration`](http://wiki.ros.org/camera_calibration) package, |
16 | | -//! including |
17 | | -//! [monocular](http://wiki.ros.org/camera_calibration/Tutorials/MonocularCalibration) |
18 | | -//! and |
19 | | -//! [stereo](http://wiki.ros.org/camera_calibration/Tutorials/StereoCalibration) |
20 | | -//! calibrations. Despite this compatibility, does not depend on ROS or |
21 | | -//! OpenCV. (Furthermore, there is also no dependency on the excellent |
22 | | -//! [rosrust](https://crates.io/crates/rosrust) crate). |
23 | | -//! - Can be compiled without the Rust standard library or allocator to support |
24 | | -//! embedded applications. |
25 | | -//! - The [`RosOpenCvIntrinsics`](struct.RosOpenCvIntrinsics.html) type |
26 | | -//! implements [the `IntrinsicParameters` trait from the `cam-geom` |
27 | | -//! crate](https://docs.rs/cam-geom/latest/cam_geom/trait.IntrinsicParameters.html). |
28 | | -//! Thus, a |
29 | | -//! [`cam_geom::Camera`](https://docs.rs/cam-geom/latest/cam_geom/struct.Camera.html) |
30 | | -//! can be created to handle intrinsic parameters using `RosOpenCvIntrinsics` |
31 | | -//! and camera pose handled by [the `ExtrinsicParameters` struct from |
32 | | -//! `cam-geom`](https://docs.rs/cam-geom/latest/cam_geom/struct.ExtrinsicParameters.html). |
33 | | -//! (See the example below.) |
34 | | -//! - When compiled with the `serde-serialize` feature, read camera calibrations |
35 | | -//! saved by the ROS `camera_calibration/cameracalibrator.py` node in |
36 | | -//! `~/.ros/camera_info/camera_name.yaml` with |
37 | | -//! [`from_ros_yaml`](fn.from_ros_yaml.html). |
38 | | -//! - When compiled with the `serde-serialize` feature, read and write the |
39 | | -//! [`RosOpenCvIntrinsics`](struct.RosOpenCvIntrinsics.html) struct using |
40 | | -//! serde. |
41 | | -//! |
42 | | -//! # Example - read a ROS YAML file and create a `cam_geom::Camera` from it. |
43 | | -//! |
44 | | -//! Let's say we have YAML file saved by the ROS |
45 | | -//! `camera_calibration/cameracalibrator.py` node. How can we create a |
46 | | -//! [`cam_geom::Camera`](https://docs.rs/cam-geom/latest/cam_geom/struct.Camera.html) |
47 | | -//! from this? |
48 | | -//! |
49 | | -//! ``` |
50 | | -//! use nalgebra::{Matrix2x3, Unit, Vector3}; |
51 | | -//! |
52 | | -//! // Here we have the YAML file contents hardcoded in a string. Ordinarily, you |
53 | | -//! // would read this from a file such as `~/.ros/camera_info/camera_name.yaml`, but |
54 | | -//! // for this example, it is hardcoded here. |
55 | | -//! let yaml_buf = b"image_width: 659 |
56 | | -//! image_height: 494 |
57 | | -//! camera_name: Basler_21029382 |
58 | | -//! camera_matrix: |
59 | | -//! rows: 3 |
60 | | -//! cols: 3 |
61 | | -//! data: [516.385667640757, 0, 339.167079537312, 0, 516.125799367807, 227.37993524141, 0, 0, 1] |
62 | | -//! distortion_model: plumb_bob |
63 | | -//! distortion_coefficients: |
64 | | -//! rows: 1 |
65 | | -//! cols: 5 |
66 | | -//! data: [-0.331416226762003, 0.143584747015566, 0.00314558656668844, -0.00393597842852019, 0] |
67 | | -//! rectification_matrix: |
68 | | -//! rows: 3 |
69 | | -//! cols: 3 |
70 | | -//! data: [1, 0, 0, 0, 1, 0, 0, 0, 1] |
71 | | -//! projection_matrix: |
72 | | -//! rows: 3 |
73 | | -//! cols: 4 |
74 | | -//! data: [444.369750976562, 0, 337.107817516087, 0, 0, 474.186859130859, 225.062742824321, 0, 0, 0, 1, 0]"; |
75 | | -//! |
76 | | -//! // The ROS YAML file does not contain the pose (no extrinsic parameters). Here we |
77 | | -//! // specify them directly. The camera is at (10,0,0), looking at (0,0,0), with up (0,0,1). |
78 | | -//! let camcenter = Vector3::new(10.0, 0.0, 0.0); |
79 | | -//! let lookat = Vector3::new(0.0, 0.0, 0.0); |
80 | | -//! let up = Unit::new_normalize(Vector3::new(0.0, 0.0, 1.0)); |
81 | | -//! let pose = cam_geom::ExtrinsicParameters::from_view(&camcenter, &lookat, &up); |
82 | | -//! |
83 | | -//! // We need the `serde-serialize` feature for the `from_ros_yaml` function. |
84 | | -//! #[cfg(feature = "serde-serialize")] |
85 | | -//! { |
86 | | -//! let from_ros = opencv_ros_camera::from_ros_yaml(&yaml_buf[..]).unwrap(); |
87 | | -//! |
88 | | -//! // Finally, create camera from intrinsic and extrinsic parameters. |
89 | | -//! let camera = cam_geom::Camera::new(from_ros.intrinsics, pose); |
90 | | -//! } |
91 | | -//! ``` |
92 | | -//! |
93 | | -//! # testing |
94 | | -//! |
95 | | -//! Test `no_std` compilation with: |
96 | | -//! |
97 | | -//! ```text |
98 | | -//! # install target with: "rustup target add thumbv7em-none-eabihf" |
99 | | -//! cargo check --no-default-features --target thumbv7em-none-eabihf |
100 | | -//! ``` |
101 | | -//! |
102 | | -//! Run unit tests with: |
103 | | -//! |
104 | | -//! ```text |
105 | | -//! cargo test |
106 | | -//! cargo test --features serde-serialize |
107 | | -//! ``` |
108 | | -//! |
109 | | -//! serde support requires std. |
110 | | -//! |
111 | | -//! # re-render README.md |
112 | | -//! |
113 | | -//! ```text |
114 | | -//! cargo install cargo-readme |
115 | | -//! cargo readme > README.md |
116 | | -//! ``` |
117 | | -
|
| 1 | +#![doc = include_str!("../README.md")] |
118 | 2 | #![deny(rust_2018_idioms, unsafe_code, missing_docs)] |
119 | 3 | #![cfg_attr(not(feature = "std"), no_std)] |
120 | 4 |
|
|
0 commit comments