Crate cam_geom
for the Rust language
📷 📐 Geometric models of cameras for photogrammetry
About
The crate implements geometric models of cameras which may be useful for photogrammetry.
The crate provides a couple camera models, the pinhole perspective
camera and the
orthographic
camera. Adding
another camera model entails implementing the
IntrinsicParameters
trait.
Also provided is the function
best_intersection_of_rays()
which
determines the best 3D point corresponding to the intersection of multiple
rays. Thus, this crate is also useful for multiple view geometry.
Characteristics:
- Extensive use of static typing to ensure no unpleasant runtime surprises with coordinate system, matrix dimensions, and so on.
- Serialization and deserialization using
serde
. Enable with theserde-serialize
cargo feature. - Linear algebra and types from the
nalgebra
crate. - Possible to create new camera models by implementing the
IntrinsicParameters
trait. While the camera models implemented in this crate are linear, there is no requirement that implementations are linear. For example, it is anticipated that other implementations may exhibit distortion. ExtrinsicParameters
based on thenalgebra::Isometry3
type to handle the camera pose.- No standard library is required (disable the default features to disable
use of
std
) and no heap allocations. In other words, this can run on a bare-metal microcontroller with no OS. - Extensive documentation and tests.
- Requires rust version 1.40 or greater.
Testing
Unit tests
To run all unit tests:
cargo test
Test for no_std
Since the thumbv7em-none-eabihf
target does not have std
available, we
can build for it to check that our crate does not inadvertently pull in std.
The following will fail if a std dependency is present:
# install target with: "rustup target add thumbv7em-none-eabihf"
cargo build --no-default-features --target thumbv7em-none-eabihf
Examples
Example - projecting 3D world coordinates to 2D pixel coordinates.
use *;
use ;
// Create two points in the world coordinate frame.
let world_coords = new;
// perepective parameters - focal length of 100, no skew, pixel center at (640,480)
let intrinsics = from;
// Set extrinsic parameters - camera at (10,0,0), looing at (0,0,0), up (0,0,1)
let camcenter = new;
let lookat = new;
let up = new_normalize;
let pose = from_view;
// Create a `Camera` with both intrinsic and extrinsic parameters.
let camera = new;
// Project the original 3D coordinates to 2D pixel coordinates.
let pixel_coords = camera.world_to_pixel;
// Print the results.
for i in 0..world_coords.data.nrows
This will print:
┌ ┐
│ 1 0 0 │
└ ┘
->
┌ ┐
│ 640 480 │
└ ┘
┌ ┐
│ 0 1 0 │
└ ┘
->
┌ ┐
│ 650 480 │
└ ┘
Example - intersection of rays
use *;
use RowVector3;
// Create the first ray.
let ray1 = new;
// Create the second ray.
let ray2 = new;
// Compute the best intersection.
let result = best_intersection_of_rays.unwrap;
// Print the result.
println!;
This will print:
result:
┌ ┐
│ 1 1 0 │
└ ┘
Regenerate README.md
The README.md
file can be regenerated with:
cargo readme > README.md
Code of conduct
Anyone who interacts with this software in any space, including but not limited to this GitHub repository, must follow our code of conduct.
License
Licensed under either of these:
- Apache License, Version 2.0, (LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or https://opensource.org/licenses/MIT)