working tracking with MIL
This commit is contained in:
parent
93205ae982
commit
00c08e5042
2 changed files with 23 additions and 6 deletions
10
flake.nix
10
flake.nix
|
@ -34,7 +34,10 @@ Some utility commands:
|
|||
};
|
||||
rustSettings = with pkgs; {
|
||||
src = ./.;
|
||||
nativeBuildInputs = [ pkg-config ];
|
||||
nativeBuildInputs = [
|
||||
pkg-config
|
||||
llvmPackages.clang
|
||||
];
|
||||
buildInputs = [
|
||||
(opencv.override {
|
||||
enableGtk2 = true;
|
||||
|
@ -59,11 +62,6 @@ Some utility commands:
|
|||
extensions = [ "rust-src" ];
|
||||
})
|
||||
bacon
|
||||
(opencv.override {
|
||||
enableGtk2 = true;
|
||||
enableFfmpeg = true;
|
||||
})
|
||||
llvmPackages.clang
|
||||
];
|
||||
inputsFrom = with self.packages.${system}; [ opencv_tracking ];
|
||||
};
|
||||
|
|
|
@ -2,8 +2,11 @@ use anyhow::Result; // Automatically handle the error types
|
|||
use opencv::{
|
||||
prelude::*,
|
||||
videoio,
|
||||
video::{TrackerMIL, TrackerMIL_Params},
|
||||
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)?;
|
||||
|
@ -11,9 +14,25 @@ fn main() -> Result<()> { // Note, this is anyhow::Result
|
|||
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
|
||||
cam.read(&mut frame)?;
|
||||
cam.read(&mut frame)?;
|
||||
cam.read(&mut frame)?;
|
||||
cam.read(&mut frame)?;
|
||||
|
||||
let mut tracker = TrackerMIL::create(TrackerMIL_Params::default().unwrap()).unwrap();
|
||||
|
||||
let mut bbox = highgui::select_roi(&frame, true, true)?;
|
||||
|
||||
tracker.init(&frame, bbox)?;
|
||||
|
||||
// and display in the window
|
||||
loop {
|
||||
cam.read(&mut frame)?;
|
||||
|
||||
let success = tracker.update(&frame, &mut bbox)?;
|
||||
|
||||
opencv::imgproc::rectangle(&mut frame, bbox, opencv::core::VecN([0_f64, 255., 0., 255.]), 1_i32, 1_i32, 0_i32)?;
|
||||
|
||||
highgui::imshow("window", &frame)?;
|
||||
let key = highgui::wait_key(1)?;
|
||||
if key == 113 { // quit with q
|
||||
|
|
Loading…
Reference in a new issue