Created
November 11, 2020 20:10
-
-
Save framp/8d51d9354e5a893abcd1c5f7d2627419 to your computer and use it in GitHub Desktop.
rust opencv test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[package] | |
name = "rust-ela" | |
version = "0.1.0" | |
edition = "2018" | |
[dependencies] | |
opencv = {version = "0.46", features = ["contrib"]} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::convert::TryInto; | |
use std::char; | |
use std::env; | |
use opencv::prelude::*; | |
use opencv::core::Mat; | |
use opencv::highgui; | |
use opencv::imgcodecs; | |
use opencv::imgproc; | |
fn main() { | |
let args: Vec<String> = env::args().collect(); | |
if args.len() <= 1 { | |
panic!("Call with an image plz"); | |
} | |
load(&args[1]); | |
} | |
fn load(path: &str) { | |
let src: Mat = imgcodecs::imread(path, 1).unwrap(); | |
if src.empty().unwrap() { | |
panic!("Image is empty"); | |
} | |
let mut hsv : Mat = Mat::default().unwrap(); | |
imgproc::cvt_color(&src, &mut hsv, imgproc::COLOR_BGR2HSV, 3).unwrap(); | |
highgui::named_window("Source", highgui::WindowFlags::WINDOW_FREERATIO as i32).unwrap(); | |
highgui::imshow("Source", &src).unwrap(); | |
highgui::named_window("HSV", highgui::WindowFlags::WINDOW_FREERATIO as i32).unwrap(); | |
highgui::imshow("HSV", &hsv).unwrap(); | |
loop { | |
let key_raw : u32 = highgui::wait_key(0).unwrap().try_into().unwrap(); | |
if let Some(key) = char::from_u32(key_raw) { | |
if key == 'q' || key == '\u{1b}' { break; } // press q or esc | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
with import <nixpkgs> {}; | |
stdenv.mkDerivation { | |
name = "env"; | |
nativeBuildInputs = [ pkg-config ]; | |
buildInputs = [ | |
opencv | |
]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment