From 1157b7320d0953544a6833f1da98a2d72879f24d Mon Sep 17 00:00:00 2001 From: edgar Date: Tue, 2 Apr 2024 22:20:47 +0200 Subject: [PATCH] add rotate example --- examples/rotate.rs | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 examples/rotate.rs diff --git a/examples/rotate.rs b/examples/rotate.rs new file mode 100644 index 00000000..3c8fc32d --- /dev/null +++ b/examples/rotate.rs @@ -0,0 +1,38 @@ +use kornia_rs::image::Image; +use kornia_rs::io::functional as F; + +fn main() -> Result<(), Box> { + // read the image + let image_path = std::path::Path::new("tests/data/dog.jpeg"); + + let image: Image = F::read_image_jpeg(image_path)?; + let image = image.cast::()?; + + let rec = rerun::RecordingStreamBuilder::new("Kornia App").spawn()?; + + // rotate the image + + let center = ( + image.size().width as f32 / 2.0, + image.size().height as f32 / 2.0, + ); + + for i in 0..360 { + let angle = i as f32; + let scale = i as f32 / 360.0; + let rotation_matrix = kornia_rs::warp::get_rotation_matrix2d(center, angle, scale); + + let output = kornia_rs::warp::warp_affine( + &image, + rotation_matrix, + image.size(), + kornia_rs::resize::InterpolationMode::Bilinear, + )?; + + let output = kornia_rs::normalize::normalize_min_max(&output, 0.0, 255.0)?; + + rec.log("image", &rerun::Image::try_from(output.data)?)?; + } + + Ok(()) +}