项目作者: STPR

项目描述 :
A 2D library to trace contours.
高级语言: Rust
项目地址: git://github.com/STPR/contour_tracing.git
创建时间: 2020-03-15T09:17:02Z
项目社区:https://github.com/STPR/contour_tracing

开源协议:European Union Public License 1.2

下载


Contour tracing library

A 2D library to trace contours.
How it works in a live demo: https://stpr.github.io/contour_tracing/

Features

Core features:

  • Trace contours using the Theo Pavlidis’ algorithm (connectivity: 4-connected)
  • Trace outlines in clockwise direction
  • Trace holes in counterclockwise direction
  • Input format: a 2D array of bits or an image buffer
  • Output format: a string of SVG Path commands

Manual parameters:

  • User can specify to close or not the paths (with the SVG Path Z command)

A Rust example with an array of bits

  1. Add the following line to your Cargo.toml file in the dependencies section:

    1. contour_tracing = { version = "*", features = ["array"] }
  2. Then use the library:
    ```rust
    use contour_tracing::array::bits_to_paths;

fn main() {
let bits = vec![vec![ 1,0,0 ],
vec![ 0,1,0 ],
vec![ 0,0,1 ]];

  1. println!("{}", bits_to_paths(bits, true));

}

  1. ## A Rust example with an image buffer
  2. 1. Add the following line to your **Cargo.toml** file in the **dependencies** section:

contour_tracing = { version = “*”, features = [“image”] }

  1. 2. Then use the library:
  2. ```rust
  3. use image::{GrayImage, Luma};
  4. use contour_tracing::image::single_l8_to_paths;
  5. fn main() {
  6. let mut image_buffer = GrayImage::new(3, 3);
  7. let foreground_color: image::Luma<u8> = Luma([1]);
  8. image_buffer.put_pixel(0, 0, foreground_color);
  9. image_buffer.put_pixel(1, 1, foreground_color);
  10. image_buffer.put_pixel(2, 2, foreground_color);
  11. println!("{}", single_l8_to_paths(&mut image_buffer, foreground_color, true));
  12. }

Both examples should print: M0 0H1V1H0ZM1 1H2V2H1ZM2 2H3V3H2Z

For more Rust examples, have a look at the documentation: Documentation

License

Contour tracing library
https://github.com/STPR/contour_tracing

Copyright (c) 2022, STPR - https://github.com/STPR

SPDX-License-Identifier: EUPL-1.2

Contribution

Your contribution is highly appreciated. Do not hesitate to open an issue or a
pull request. Note that any contribution submitted for inclusion in the project
will be licensed according to the terms given in LICENSE.txt.