Skip to main content

Low level implementations for computer vision in Rust

Project description

kornia-rs: Low level implementations for Computer Vision in Rust.

Continuous integration PyPI version License Slack

This project provides low level functionality for Computer Vision written in Rust to be consumed by machine learning and data-science frameworks, specially those working with images. We mainly aim to provide I/O functionality for images (future: video, cameras), and visualisation in future.

  • The library is written in Rust.
  • 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

Basic Usage

Load an image, that is converted to cv::Tensor wich is a centric structure to the DLPack protocol to share tensor data across frameworks with a zero-copy cost.

    import kornia_rs as K
    from kornia_rs import Tensor as cvTensor

    # load an image with Rust `image-rs` as backend library
    cv_tensor: cvTensor = K.read_image_rs("dog.jpeg")
    assert cv_tensor.shape == [195, 258, 3]

    # convert to dlpack to import to torch
    th_tensor = torch.utils.dlpack.from_dlpack(cv_tensor)
    assert th_tensor.shape == (195, 258, 3)
    assert np_tensor.shape == (195, 258, 3)

    # or to numpy with same interface
    np_tensor = np.from_dlpack(cv_tensor)

Advanced usage

Encode or decoda image streams using the turbojpeg backend

# load image using turbojpeg
cv_tensor = K.read_image_jpeg("dog.jpeg")
image: np.ndarray = np.from_dlpack(cv_tensor)  # HxWx3

# encode the image with jpeg
image_encoder = K.ImageEncoder()
image_encoder.set_quality(95)  # set the encoding quality

# get the encoded stream
image_encoded: List[int] = image_encoder.encode(image.tobytes(), image.shape)

# write to disk the encoded stream
K.write_image_jpeg("dog_encoded.jpeg", image_encoded)

# decode back the image
image_decoder = K.ImageDecoder()

decoded_tensor = image_decoder.decode(bytes(image_encoded))
decoded_image: np.ndarray = np.from_dlpack(decoded_tensor)  # HxWx3

TODO: short/mid-terrm

  • [infra] Automate packaging for manywheels.
  • [kornia] integrate with the new Image API
  • [dlpack] move dlpack implementation to dlpack-rs.
  • [dlpack] implement test for torch and numpy.
  • [dlpack] update dlpack version >=0.8
  • [dlpack] implement DLPack to cv::Tensor.

TODO: not priority for now

  • [io] Implement image encoding and explore video.
  • [viz] Fix minor issues and implement a full VizManager to work on the browser.
  • [tensor] implement basic functionality to test: add, sub, mul, etc.
  • [tensor] explore xnnpack and openvino integration.

Development

To test the project in lyour local machine use the following instructions:

  1. Clone the repository in your local directory
git clone https://github.com/kornia/kornia-rs.git

2.1 (optional) Build the devel.Dockerfile

Let's prepare the development environment with Docker. Make sure you have docker in your system: https://docs.docker.com/engine/install/ubuntu/

cd ./docker && ./build_devel.sh
KORNIA_RS_DEVEL_IMAGE="kornia_rs/devel:local" ./devel.sh

2.2 Enter to the devel docker container.

./devel.sh
  1. Build the project

(you should now be inside the docker container)

# maturin needs you to be a `venv`
python3 -m venv .venv
source .venv/bin/activate

# build and generate linked wheels
maturin develop --extras dev
  1. Run the tests
pytest test/

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

kornia_rs-0.0.8-cp311-none-win_amd64.whl (981.6 kB view hashes)

Uploaded CPython 3.11 Windows x86-64

kornia_rs-0.0.8-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.2 MB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

kornia_rs-0.0.8-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (2.1 MB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ ARM64

kornia_rs-0.0.8-cp311-cp311-macosx_10_7_x86_64.whl (1.3 MB view hashes)

Uploaded CPython 3.11 macOS 10.7+ x86-64

kornia_rs-0.0.8-cp310-none-win_amd64.whl (981.6 kB view hashes)

Uploaded CPython 3.10 Windows x86-64

kornia_rs-0.0.8-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.2 MB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

kornia_rs-0.0.8-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (2.1 MB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ ARM64

kornia_rs-0.0.8-cp310-cp310-macosx_10_7_x86_64.whl (1.3 MB view hashes)

Uploaded CPython 3.10 macOS 10.7+ x86-64

kornia_rs-0.0.8-cp39-none-win_amd64.whl (981.8 kB view hashes)

Uploaded CPython 3.9 Windows x86-64

kornia_rs-0.0.8-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.2 MB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

kornia_rs-0.0.8-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (2.1 MB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ ARM64

kornia_rs-0.0.8-cp39-cp39-macosx_11_0_arm64.whl (1.2 MB view hashes)

Uploaded CPython 3.9 macOS 11.0+ ARM64

kornia_rs-0.0.8-cp39-cp39-macosx_10_7_x86_64.whl (1.3 MB view hashes)

Uploaded CPython 3.9 macOS 10.7+ x86-64

kornia_rs-0.0.8-cp38-none-win_amd64.whl (981.9 kB view hashes)

Uploaded CPython 3.8 Windows x86-64

kornia_rs-0.0.8-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.2 MB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

kornia_rs-0.0.8-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (2.1 MB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ ARM64

kornia_rs-0.0.8-cp38-cp38-macosx_11_0_arm64.whl (1.2 MB view hashes)

Uploaded CPython 3.8 macOS 11.0+ ARM64

kornia_rs-0.0.8-cp38-cp38-macosx_10_7_x86_64.whl (1.3 MB view hashes)

Uploaded CPython 3.8 macOS 10.7+ x86-64

kornia_rs-0.0.8-cp37-none-win_amd64.whl (982.0 kB view hashes)

Uploaded CPython 3.7 Windows x86-64

kornia_rs-0.0.8-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.2 MB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.17+ x86-64

kornia_rs-0.0.8-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (2.1 MB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.17+ ARM64

kornia_rs-0.0.8-cp37-cp37m-macosx_10_7_x86_64.whl (1.3 MB view hashes)

Uploaded CPython 3.7m macOS 10.7+ x86-64

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page