pub struct GeometrySimplifier;Expand description
几何简化器
Implementations§
Source§impl GeometrySimplifier
impl GeometrySimplifier
Sourcepub fn simplify_to_quad(contour: Vec<Coord<f32>>) -> Option<LineString<f32>>
pub fn simplify_to_quad(contour: Vec<Coord<f32>>) -> Option<LineString<f32>>
使用凸包 + Douglas-Peucker 算法简化轮廓,筛选出四边形候选。
§算法说明
- 将输入坐标点集构造为 LineString 并主动闭合。
- 新增:对轮廓求凸包,消除锯齿噪声,使 D-P 更易收敛到 4 顶点。
- 以多档容差对凸包执行 Douglas-Peucker 简化,寻找恰好为 5 点的结果。
- 若多档容差均未能得到 5 点,则使用极值点法强制提取 4 个角点作为后备。
§凸包预处理的必要性
真实照片中文档边缘因透视变形、光照不均、纸张弯曲,Canny 产生带噪声的曲线段。 直接对锯齿轮廓执行 D-P,容差小时点数过多,容差大时直接跳过 5 点跌至 3 点, 无法在任何容差档位精确停在 5 点。凸包将轮廓预处理为凸多边形后, D-P 的简化路径更平滑,能稳定收敛到 4 顶点(5 点闭合 LineString)。
§闭合保证
输入轮廓若首尾不同,此处主动闭合,确保 geo::Simplify 对闭合轮廓的正确处理。
Auto Trait Implementations§
impl Freeze for GeometrySimplifier
impl RefUnwindSafe for GeometrySimplifier
impl Send for GeometrySimplifier
impl Sync for GeometrySimplifier
impl Unpin for GeometrySimplifier
impl UnsafeUnpin for GeometrySimplifier
impl UnwindSafe for GeometrySimplifier
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more