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; {
|
rustSettings = with pkgs; {
|
||||||
src = ./.;
|
src = ./.;
|
||||||
nativeBuildInputs = [ pkg-config ];
|
nativeBuildInputs = [
|
||||||
|
pkg-config
|
||||||
|
llvmPackages.clang
|
||||||
|
];
|
||||||
buildInputs = [
|
buildInputs = [
|
||||||
(opencv.override {
|
(opencv.override {
|
||||||
enableGtk2 = true;
|
enableGtk2 = true;
|
||||||
|
@ -59,11 +62,6 @@ Some utility commands:
|
||||||
extensions = [ "rust-src" ];
|
extensions = [ "rust-src" ];
|
||||||
})
|
})
|
||||||
bacon
|
bacon
|
||||||
(opencv.override {
|
|
||||||
enableGtk2 = true;
|
|
||||||
enableFfmpeg = true;
|
|
||||||
})
|
|
||||||
llvmPackages.clang
|
|
||||||
];
|
];
|
||||||
inputsFrom = with self.packages.${system}; [ opencv_tracking ];
|
inputsFrom = with self.packages.${system}; [ opencv_tracking ];
|
||||||
};
|
};
|
||||||
|
|
|
@ -2,8 +2,11 @@ use anyhow::Result; // Automatically handle the error types
|
||||||
use opencv::{
|
use opencv::{
|
||||||
prelude::*,
|
prelude::*,
|
||||||
videoio,
|
videoio,
|
||||||
|
video::{TrackerMIL, TrackerMIL_Params},
|
||||||
highgui
|
highgui
|
||||||
}; // Note, the namespace of OpenCV is changed (to better or worse). It is no longer one enormous.
|
}; // 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
|
fn main() -> Result<()> { // Note, this is anyhow::Result
|
||||||
// Open a GUI window
|
// Open a GUI window
|
||||||
highgui::named_window("window", highgui::WINDOW_FULLSCREEN)?;
|
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 cam = videoio::VideoCapture::new(0, videoio::CAP_ANY)?;
|
||||||
let mut frame = Mat::default(); // This array will store the web-cam data
|
let mut frame = Mat::default(); // This array will store the web-cam data
|
||||||
// Read the camera
|
// 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
|
// and display in the window
|
||||||
loop {
|
loop {
|
||||||
cam.read(&mut frame)?;
|
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)?;
|
highgui::imshow("window", &frame)?;
|
||||||
let key = highgui::wait_key(1)?;
|
let key = highgui::wait_key(1)?;
|
||||||
if key == 113 { // quit with q
|
if key == 113 { // quit with q
|
||||||
|
|
Loading…
Reference in a new issue