Create example binary for Canny
This commit is contained in:
1 parent
c95d05f1ac
commit
e267f7ef7e
1 file changed
+38
@@ -0,0 +1,38 @@
|
||||
use ccvl::filter;
|
||||
use ccvl::image::*;
|
||||
|
||||
fn main() -> std::process::ExitCode {
|
||||
let args = std::env::args().collect::<Vec<String>>();
|
||||
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::<Farbfeld>(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::<Farbfeld>(output_path) {
|
||||
Err(err) => {
|
||||
println!(
|
||||
"I/O error saving image {}: {}",
|
||||
output_path, err
|
||||
);
|
||||
std::process::ExitCode::FAILURE
|
||||
}
|
||||
Ok(()) => std::process::ExitCode::SUCCESS,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user