kornia-rs: low level computer vision library in Rust
The kornia-rs crate is a low level library for Computer Vision written in Rust π¦
Use the library to perform image I/O, visualisation and other low level operations in your machine learning and data-science projects in a thread-safe and efficient way.
Getting Started
cargo run --bin hello_world -- --image-path path/to/image.jpg
use Image;
use functional as F;
Features
- π¦The library is primarly written in Rust.
- π Multi-threaded and efficient image I/O, image processing and advanced computer vision operators.
- π’ The n-dimensional backend is based on the
ndarraycrate. - π Python bindings are created with PyO3/Maturin.
- π¦ We package with support for Linux [amd64/arm64], Macos and WIndows.
- Supported Python versions are 3.7/3.8/3.9/3.10/3.11
Supported image formats
- Read images from AVIF, BMP, DDS, Farbeld, GIF, HDR, ICO, JPEG (libjpeg-turbo), OpenEXR, PNG, PNM, TGA, TIFF, WebP.
Image processing
- Convert images to grayscale, resize, crop, rotate, flip, pad, normalize, denormalize, and other image processing operations.
Video processing
- Capture video frames from a camera.
π οΈ Installation
>_ System dependencies
Dependeing on the features you want to use, you might need to install the following dependencies in your system:
turbojpeg
gstreamer
** Check the gstreamr installation guide: https://docs.rs/gstreamer/latest/gstreamer/#installation
π¦ Rust
Add the following to your Cargo.toml:
[]
= { = "https://github.com/kornia/kornia-rs", = "v0.1.6-rc1" }
Alternatively, you can use each sub-crate separately:
[]
= { = "https://github.com/kornia/kornia-rs", = "v0.1.6-rc1" }
= { = "https://github.com/kornia/kornia-rs", = "v0.1.6-rc1" }
= { = "https://github.com/kornia/kornia-rs", = "v0.1.6-rc1" }
= { = "https://github.com/kornia/kornia-rs", = "v0.1.6-rc1" }
π Python
Examples: Image processing
The following example shows how to read an image, convert it to grayscale and resize it. The image is then logged to a rerun recording stream.
Checkout all the examples in the examples directory to see more use cases.
use ;
use functional as F;
Python usage
Load an image, that is converted directly to a numpy array to ease the integration with other libraries.
# load an image with using libjpeg-turbo
: =
# alternatively, load other formats
# img: np.ndarray = K.read_image_any("dog.png")
assert ==
# convert to dlpack to import to torch
=
assert ==
Write an image to disk
# load an image with using libjpeg-turbo
: =
# write the image to disk
Encode or decode image streams using the turbojpeg backend
# load image with kornia-rs
=
# encode the image with jpeg
=
# set the encoding quality
# get the encoded stream
: =
# decode back the image
=
: =
Resize an image using the kornia-rs backend with SIMD acceleration
# load image with kornia-rs
=
# resize the image
=
assert ==
π§βπ» Development
Pre-requisites: install rust and python3 in your system.
|
Clone the repository in your local directory
π¦ Rust
Compile the project and run the tests
For specific tests, you can run the following command:
π Python
To build the Python wheels, we use the maturin package. Use the following command to build the wheels:
To run the tests, use the following command:
π Contributing
This is a child project of Kornia. Join the community to get in touch with us, or just sponsor the project: https://opencollective.com/kornia