Skip to content

Instantly share code, notes, and snippets.

@framp
Created November 11, 2020 20:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save framp/8d51d9354e5a893abcd1c5f7d2627419 to your computer and use it in GitHub Desktop.
Save framp/8d51d9354e5a893abcd1c5f7d2627419 to your computer and use it in GitHub Desktop.
rust opencv test
[package]
name = "rust-ela"
version = "0.1.0"
edition = "2018"
[dependencies]
opencv = {version = "0.46", features = ["contrib"]}
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
}
}
}
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