kornia/kornia-rs

[Feature]: Kornia-rs still largely slower than OpenCV in 2026

Open

#667 opened on Jan 26, 2026

View on GitHub
 (10 comments) (0 reactions) (1 assignee)Rust (188 forks)auto 404
enhancementhelp wantedtriage

Repository metrics

Stars
 (675 stars)
PR merge metrics
 (PR metrics pending)

Description

🚀 Feature Description

tested simple

import time
import cv2
import numpy as np
import kornia_rs as K

cv2.setNumThreads(1)

sizes = [
    (256, 256),
    (512, 512),
    (1024, 1024),
    (2048, 2048),
]

img = cv2.imread("data/images/test_ocr_page2.png", cv2.IMREAD_COLOR)
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)

iters = 200
warmup = 20


def bench_opencv(img, size):
    h, w = size
    for _ in range(warmup):
        cv2.resize(img, (w, h), interpolation=cv2.INTER_LINEAR)

    t0 = time.perf_counter()
    for _ in range(iters):
        cv2.resize(img, (w, h), interpolation=cv2.INTER_LINEAR)
    return (time.perf_counter() - t0) / iters


def bench_kornia(img, size):
    h, w = size
    for _ in range(warmup):
        K.resize(img, (h, w), interpolation="bilinear")

    t0 = time.perf_counter()
    for _ in range(iters):
        K.resize(img, (h, w), interpolation="bilinear")
    return (time.perf_counter() - t0) / iters


print(f"Iterations: {iters}, Warmup: {warmup}")
print("-" * 60)

for size in sizes:
    t_cv = bench_opencv(img, size)
    t_kr = bench_kornia(img, size)

    print(
        f"{size[0]:4d}x{size[1]:4d} | "
        f"OpenCV: {t_cv*1000:6.2f} ms | "
        f"kornia-rs: {t_kr*1000:6.2f} ms | "
        f"ratio: {t_kr / t_cv:5.2f}x"
    )

📂 Feature Category

Rust Core Library

💡 Motivation

I found the result is surprisely badly lay behind OpenCV tooo much:

Iterations: 200, Warmup: 20
------------------------------------------------------------
 256x 256 | OpenCV:   0.16 ms | kornia-rs:   0.80 ms | ratio:  4.93x
 512x 512 | OpenCV:   0.62 ms | kornia-rs:   1.26 ms | ratio:  2.04x
1024x1024 | OpenCV:   1.78 ms | kornia-rs:   3.03 ms | ratio:  1.71x
2048x2048 | OpenCV:   4.47 ms | kornia-rs:   8.34 ms | ratio:  1.87x

💭 Proposed Solution

Wondering if kornia-rs pay some time on improve simple operation such as resize rather than spent too much converting kornia to 3D libary.

📚 Library Reference

opencv

🔄 Alternatives Considered

No response

🎯 Use Cases

No response

📝 Additional Context

No response

🤝 Contribution Intent

  • I plan to submit a PR to implement this feature
  • I'm requesting this feature but not planning to implement it

Contributor guide