4个版本 (2个重大变更)
0.5.0 | 2021年11月30日 |
---|---|
0.4.0 | 2021年11月30日 |
0.3.1 | 2021年11月30日 |
0.3.0 | 2021年11月30日 |
#404 在 图像
53KB
1K SLoC
image-moments
此crate提供高效的图像轮廓矩编译时检查计算。它力求尽可能与相应的OpenCV函数兼容,同时保持“rusty”工作流程。矩的计算顺序可调整:您只需为所需的矩付费。
使用
use image_moments::{Moments, Spatial};
use approx::assert_abs_diff_eq;
fn main() {
// Points defining the contour
let points = [
(53, 19),
(52, 20),
(49, 20),
// [...]
(60, 25),
(54, 19),
];
// Calculate all spatial (aka "raw") contour moments up to the third order
let moments: Spatial<f64, 3> = points.iter().collect();
// Compare with those values generated by OpenCV
assert_abs_diff_eq!(moments.get::<0, 0>(), 703.0);
assert_abs_diff_eq!(moments.get::<1, 0>(), 52175.166666666664);
assert_abs_diff_eq!(moments.get::<0, 1>(), 25661.5);
assert_abs_diff_eq!(moments.get::<2, 0>(), 4084450.6666666665);
assert_abs_diff_eq!(moments.get::<1, 1>(), 2024477.75);
assert_abs_diff_eq!(moments.get::<0, 2>(), 1071256.0);
assert_abs_diff_eq!(moments.get::<3, 0>(), 332589780.65000004);
assert_abs_diff_eq!(moments.get::<2, 1>(), 166738807.83333334);
assert_abs_diff_eq!(moments.get::<1, 2>(), 89124447.63333333);
assert_abs_diff_eq!(moments.get::<0, 3>(), 50269189.75);
// This will fail at compile time because it is not covered by the third order:
// assert_abs_diff_eq!(moments.get::<0, 4>(), 50269189.75);
}
许可
许可方式如下
- Apache License,版本2.0 (LICENSE-APACHE 或 https://apache.ac.cn/licenses/LICENSE-2.0)
- MIT许可 (LICENSE-MIT 或 http://opensource.org/licenses/MIT)
任选其一。
贡献
除非您明确表示,否则根据Apache-2.0许可中定义的,您有意提交的任何贡献,包括但不限于他uristic和手动编目数据,都应按照上述方式双许可,不附加任何额外条款或条件。