diff --git a/src/main.rs b/src/main.rs index 5b36f3f..675016c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -113,7 +113,7 @@ fn run_all() -> Result<(), Box> { qualibration.run_step()?; if qualibration.capture_mode { - let millis = std::time::Duration::from_millis(1000); // TODO: find solution to know when change has been done + let millis = std::time::Duration::from_millis(300); // TODO: find solution to know when change has been done std::thread::sleep(millis); } } diff --git a/src/qualibration.rs b/src/qualibration.rs index 8ccad5c..8c48de7 100644 --- a/src/qualibration.rs +++ b/src/qualibration.rs @@ -1,6 +1,7 @@ pub mod annalyse; pub mod borders; +use std::time::Instant; use annalyse::{image_diff, is_same_frame}; use borders::{bord_mult, get_extermities, get_intersection, mix_borders, probabilistic_hough}; use std::env::args; @@ -53,9 +54,9 @@ pub enum Sequence { RightBorder, ReadDir, ComputeArea, + PlayLineDotted, Finish, - WaitQ, LinearConstSpeed, // [multiple test] @@ -74,6 +75,7 @@ pub enum Sequence { #[derive(Debug)] pub struct Qualibration { + pub begin: Instant, pub cam: VideoCapture, pub r: i32, pub g: i32, @@ -95,6 +97,7 @@ pub struct Qualibration { pub border_pt: Vec<(f64, f64)>, pub homography: Mat, pub h_size: Size_, + pub line_pos: Vec, } impl Qualibration { @@ -113,7 +116,9 @@ impl Qualibration { let mut frame = Mat::default(); cam.read(&mut frame)?; + //let now = std::time::Instant::now(); Ok(Qualibration { + begin: std::time::Instant::now(), cam, r: 150, g: 0, @@ -141,6 +146,7 @@ impl Qualibration { border_pt: vec![], homography: Mat::default(), h_size: Size::default(), + line_pos: vec![4095; 100], }) } @@ -151,20 +157,13 @@ impl Qualibration { highgui::imshow("camera", &self.frame)?; } - - //println!( - // "frame.size:{} \tframe_prev.size:{}", - // self.frame.size()?.width, - // self.frame_prev.size()?.width - //); if self.frame.size()?.width > 0 && self.frame_prev.size()?.width > 0 || !self.capture_mode { - //println!("plif: {}", line!()); if self.id.is_some() { - // println!("plif: {}", line!()); self.id = if true { //self.capture_mode || self.id == Some(Sequence::WaitSpace) || is_same_frame(&self.frame, &self.frame_prev)? { if self.id != Some(Sequence::WaitSpace) && self.id != Some(Sequence::FirstState) + && self.id != Some(Sequence::PlayLineDotted) && self.capture_mode { self.img.push(self.frame.clone()); @@ -248,9 +247,29 @@ impl Qualibration { }; let nb_all = self.nb_all as usize; let nb_visible = self.nb_visible as usize; + let nb_wait = 20; if seq.is_some() { match seq.unwrap() { + Sequence::PlayLineDotted => { + // la on va faire une ligne qu'on peut observer + pl = vec![]; + let black = Color{r: 0, g: 0, b: 0}; + for _ in 0..nb_all { + pl.push(Point{x: 0., y: 0., color: black}); + } + let len = (self.line_pos.len() + nb_wait) as f32; + for i in 0..nb_wait { + let y = i as f32 * 4095. / len; + pl.push(Point{x: 0., y, color: black}); + } + for i in 0..(self.line_pos.len()) { + let y = (i + nb_wait) as f32 * 4095. / len; + let c = if (i + nb_wait) % 2 == 0 {color} else {black}; + pl.push(Point{x: self.line_pos[i] as f32, y, color: c}); + } + + } Sequence::WaitSpace => { pl = draw::draw_line(&p0, &p1, nb_all, nb_visible)?; pl.extend(draw::draw_line(&p1, &p2, nb_all, nb_visible)?); @@ -320,7 +339,7 @@ impl Qualibration { return None; } - println!("Hey"); + //println!("Hey"); match self.id.unwrap() { //Sequence::Finish => Some(Sequence::Finish), Sequence::Finish => None, @@ -341,12 +360,12 @@ impl Qualibration { Some(Sequence::WaitSpace) } } - Sequence::WaitQ => { + Sequence::PlayLineDotted => { //println!("key: {}", self.key); - if self.key == 113 { - next(&Sequence::WaitQ) + if self.key == 32 { + next(&Sequence::PlayLineDotted) } else { - Some(Sequence::WaitQ) + Some(Sequence::PlayLineDotted) } } Sequence::Vertical(n) => { @@ -480,10 +499,10 @@ impl Qualibration { // on fait le nom de dossier general au cas ou // on fait un nom de dossier avec le temps // on sauvgarde toutes les image - let now = std::time::Instant::now(); + let now = self.begin; let name = format!("image/"); create_dir(&name).unwrap_or(()); - let name = format!("image/{:0>6?}_{:0>9?}/", now.elapsed().as_millis(), now.elapsed().as_nanos()); + let name = format!("image/{:0>6?}_{:0>9?}/", now.elapsed().as_secs(), now.elapsed().as_nanos()); create_dir(&name).unwrap_or(()); //name.push_str(format!("image/{}_{}/", now.elapsed().as_secs(), now.elapsed().as_nanos()).as_str()); //let name = format!("image/{now:?}/"); diff --git a/src/qualibration/annalyse.rs b/src/qualibration/annalyse.rs index 5871d55..9336bf0 100644 --- a/src/qualibration/annalyse.rs +++ b/src/qualibration/annalyse.rs @@ -411,8 +411,29 @@ pub fn trackbar_line_segment(mem: &mut Qualibration, winname: &str) -> Result<() Ok(()) } -pub fn adding_trackbar(mem: &mut Qualibration, winname: &str) -> Result<()> { +pub fn line_pos(mem: &mut Qualibration, winname: &str) -> Result<()> { + named_window(winname, WINDOW_AUTOSIZE)?; + highgui::move_window(winname, 20, 20)?; + let v: VecN = VecN::new(0., 0., 0., 255.); + let m = Mat::new_rows_cols_with_default(1, 1024, CV_8UC3, v)?; + highgui::imshow(winname, &m)?; + + for i in 0..mem.line_pos.len() { + create_trackbar( + format!("pt[{i}]:\t").as_str(), + winname, + Some(&mut mem.line_pos[i]), + 4095, + None, + )?; + } + + Ok(()) +} + +pub fn adding_trackbar(mut mem: &mut Qualibration, winname: &str) -> Result<()> { //println!("winname: {winname}"); + line_pos(&mut mem , "Play Line")?; trackbar_init_param(mem, "init_param")?; //named_window(winname, WINDOW_AUTOSIZE)?; //associate_trackbar(winname, &mut mem.tresh)?;