From 00c08e5042fe745645e8521a871b8982cb5cc81c Mon Sep 17 00:00:00 2001 From: Nickiel12 Date: Sun, 1 Oct 2023 17:42:47 -0700 Subject: [PATCH] working tracking with MIL --- flake.nix | 10 ++++------ object_tracking/src/main.rs | 19 +++++++++++++++++++ 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/flake.nix b/flake.nix index 02fbbe2..1136e53 100644 --- a/flake.nix +++ b/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 ]; }; diff --git a/object_tracking/src/main.rs b/object_tracking/src/main.rs index 9dde802..dfadaff 100644 --- a/object_tracking/src/main.rs +++ b/object_tracking/src/main.rs @@ -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