cv_core/lib.rs
1//! # Rust CV Core
2//!
3//! This library provides common abstractions and types for computer vision (CV) in Rust.
4//! All the crates in the rust-cv ecosystem that have or depend on CV types depend on this crate.
5//! This includes things like camera model traits, bearings, poses, keypoints, etc. The crate is designed to
6//! be very small so that it adds negligable build time. It pulls in some dependencies
7//! that will probably be brought in by writing computer vision code normally.
8//! The core concept is that all CV crates can work together with each other by using the
9//! abstractions and types specified in this crate.
10//!
11//! The crate is designed to work with `#![no_std]`, even without an allocator. `libm` is used
12//! (indirectly through [`num-traits`]) for all math algorithms that aren't present in `std`. Any
13//! code that doesn't need to be shared across all CV crates should not belong in this repository.
14//! If there is a good reason to put code that some crates may need into `cv-core`, it should be
15//! gated behind a feature.
16//!
17//! ## Triangulation
18//!
19//! Several of the traits with in `cv-core`, such as [`TriangulatorObservances`], must perform a process
20//! called [triangulation](https://en.wikipedia.org/wiki/Triangulation). In computer vision, this problem
21//! occurs quite often, as we often have some of the following data:
22//!
23//! * [The pose of a camera](WorldToCamera)
24//! * [The relative pose of a camera](CameraToCamera)
25//! * [A bearing direction at which lies a feature](Bearing)
26//!
27//! We have to take this data and produce a 3d point. Cameras have an optical center which all bearings protrude from.
28//! This is often refered to as the focal point in a standard camera, but in computer vision the term optical center
29//! is prefered, as it is a generalized concept. What typically happens in triangulation is that we have (at least)
30//! two optical centers and a bearing (direction) out of each of those optical centers approximately pointing towards
31//! the 3d point. In an ideal world, these bearings would point exactly at the point and triangulation would be achieved
32//! simply by solving the equation for the point of intersection. Unfortunately, the real world throws a wrench at us, as
33//! the bearings wont actually intersect since they are based on noisy data. This is what causes us to need different
34//! triangulation algorithms, which deal with the error in different ways and have different characteristics.
35//!
36//! Here is an example where we have two pinhole cameras A and B. The `@` are used to show the
37//! [virtual image plane](https://en.wikipedia.org/wiki/Pinhole_camera_model). The virtual image plane can be thought
38//! of as a surface in front of the camera through which the light passes through from the point to the optical center `O`.
39//! The points `a` and `b` are normalized image coordinates which describe the position on the virtual image plane which
40//! the light passed through from the point to the optical center on cameras `A` and `B` respectively. We know the
41//! exact pose (position and orientation) of each of these two cameras, and we also know the normalized image coordinates,
42//! which we can use to compute a bearing. We are trying to solve for the point `p` which would cause the ray of light to
43//! pass through points `a` and `b` followed by `O`.
44//!
45//! - `p` the point we are trying to triangulate
46//! - `a` the normalized keypoint on camera A
47//! - `b` the normalized keypoint on camera B
48//! - `O` the optical center of a camera
49//! - `@` the virtual image plane
50//!
51//! ```text
52//! @
53//! @
54//! p--------b--------O
55//! / @
56//! / @
57//! / @
58//! / @
59//! @@@@@@@a@@@@@
60//! /
61//! /
62//! /
63//! O
64//! ```
65
66#![no_std]
67
68mod camera;
69mod keypoint;
70mod matches;
71mod point;
72mod pose;
73mod so3;
74mod triangulation;
75
76pub use camera::*;
77pub use keypoint::*;
78pub use matches::*;
79pub use nalgebra;
80pub use point::*;
81pub use pose::*;
82pub use sample_consensus;
83pub use so3::*;
84pub use triangulation::*;