Created
February 13, 2022 23:57
-
-
Save Machine-Jonte/347b4e771370bff7c837b7eb6299987c to your computer and use it in GitHub Desktop.
opencv_rust_tutorial_medium_cam
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 anyhow::Result; // Automatically handle the error types | |
use opencv::{ | |
prelude::*, | |
videoio, | |
highgui | |
}; // Note, the namespace of OpenCV is changed (to better or worse). It is no longer one enormous. | |
fn main() -> Result<()> { // Note, this is anyhow::Result | |
// Open a GUI window | |
highgui::named_window("window", highgui::WINDOW_FULLSCREEN)?; | |
// Open the web-camera (assuming you have one) | |
let mut cam = videoio::VideoCapture::new(0, videoio::CAP_ANY)?; | |
let mut frame = Mat::default(); // This array will store the web-cam data | |
// Read the camera | |
// and display in the window | |
loop { | |
cam.read(&mut frame)?; | |
highgui::imshow("window", &frame)?; | |
let key = highgui::wait_key(1)?; | |
if key == 113 { // quit with q | |
break; | |
} | |
} | |
Ok(()) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment