Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions crates/kornia-apriltag/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ thiserror = { workspace = true }
kornia-io = { workspace = true }
criterion = { workspace = true }
apriltag = "0.4"
aprilgrid = "0.6"
image = "0.25"

[[bench]]
name = "bench_decoding"
Expand Down
22 changes: 19 additions & 3 deletions crates/kornia-apriltag/benches/bench_decoding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,17 @@ use std::path::PathBuf;
fn bench_decoding(c: &mut Criterion) {
let img_path =
PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("../../tests/data/apriltags_tag36h11.jpg");

// Kornia
let img = read_image_jpeg_rgb8(img_path).unwrap();
let mut gray_img = Image::from_size_val(img.size(), 0, CpuAllocator).unwrap();
gray_from_rgb_u8(&img, &mut gray_img).unwrap();

let kornia_detector_config = DecodeTagsConfig::new(vec![TagFamilyKind::Tag36H11]);
let mut kornia_detector =
AprilTagDecoder::new(kornia_detector_config, gray_img.size()).unwrap();

// AprilTag C
let mut apriltag_c_img =
apriltag::Image::zeros_with_stride(gray_img.width(), gray_img.height(), gray_img.width())
.unwrap();
Expand All @@ -31,9 +38,14 @@ fn bench_decoding(c: &mut Criterion) {

apriltag_c_detector.set_decimation(2.0);

let kornia_detector_config = DecodeTagsConfig::new(vec![TagFamilyKind::Tag36H11]);
let mut kornia_detector =
AprilTagDecoder::new(kornia_detector_config, gray_img.size()).unwrap();
// AprilGrid-rs
let aprilgrid_img: image::DynamicImage =
image::GrayImage::from_vec(img.width() as u32, img.height() as u32, img.to_vec())
.unwrap()
.into();

let aprilgrid_detector =
aprilgrid::detector::TagDetector::new(&aprilgrid::TagFamily::T36H11, None);

c.bench_function("kornia-apriltag", |b| {
b.iter(|| {
Expand All @@ -45,6 +57,10 @@ fn bench_decoding(c: &mut Criterion) {
c.bench_function("apriltag-c", |b| {
b.iter(|| std::hint::black_box(apriltag_c_detector.detect(&apriltag_c_img)));
});

c.bench_function("aprilgrid-rs", |b| {
b.iter(|| std::hint::black_box(aprilgrid_detector.detect(&aprilgrid_img)));
});
}

criterion_group!(benches, bench_decoding);
Expand Down
Loading