From e267f7ef7e2f1e9d4fa4e759e36b634a739f379c Mon Sep 17 00:00:00 2001 From: Camden Dixie O'Brien Date: Tue, 27 Oct 2026 19:17:47 +0000 Subject: [PATCH] Create example binary for Canny --- examples/canny.rs | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 examples/canny.rs diff --git a/examples/canny.rs b/examples/canny.rs new file mode 100644 index 0000000..1413980 --- /dev/null +++ b/examples/canny.rs @@ -0,0 +1,38 @@ +use ccvl::filter; +use ccvl::image::*; + +fn main() -> std::process::ExitCode { + let args = std::env::args().collect::>(); + if args.len() != 3 { + println!("Usage: {} IN OUT", args[0].as_str()); + return std::process::ExitCode::FAILURE; + } + + let input_path = args[1].as_str(); + let output_path = args[2].as_str(); + + match Image::load::(input_path) { + Err(Error::Invalid) => { + println!("{} is not a valid image", input_path); + std::process::ExitCode::FAILURE + } + Err(Error::Io(err)) => { + println!("I/O error loading image {}: {}", input_path, err); + std::process::ExitCode::FAILURE + } + Ok(img) => { + let result = filter::canny(img.map(|p| Luminance::from(p))) + .map(|p| p.into()); + match result.save::(output_path) { + Err(err) => { + println!( + "I/O error saving image {}: {}", + output_path, err + ); + std::process::ExitCode::FAILURE + } + Ok(()) => std::process::ExitCode::SUCCESS, + } + } + } +}