Compare commits

..

2 Commits

Author SHA1 Message Date
dee7199b09 fix: some stuf about image file name 2023-09-14 22:04:44 +02:00
f74c7caf10 fix: replace WaitSpace Sequence 2023-09-14 21:11:01 +02:00
3 changed files with 67 additions and 23 deletions

View File

@ -90,9 +90,9 @@ fn run_all() -> Result<(), Box<dyn std::error::Error>> {
//let _t = framerate_handler.handle_time()?; //let _t = framerate_handler.handle_time()?;
///////////////// /////////////////
let key = highgui::wait_key(1)?; let key = highgui::wait_key(1)?;
if key != -1 { //if key != -1 {
qualibration.key = key; qualibration.key = key;
} //}
if key == 27 { if key == 27 {
// esc in my case // esc in my case
break; break;
@ -113,7 +113,7 @@ fn run_all() -> Result<(), Box<dyn std::error::Error>> {
qualibration.run_step()?; qualibration.run_step()?;
if qualibration.capture_mode { 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); std::thread::sleep(millis);
} }
} }

View File

@ -1,6 +1,7 @@
pub mod annalyse; pub mod annalyse;
pub mod borders; pub mod borders;
use std::time::Instant;
use annalyse::{image_diff, is_same_frame}; use annalyse::{image_diff, is_same_frame};
use borders::{bord_mult, get_extermities, get_intersection, mix_borders, probabilistic_hough}; use borders::{bord_mult, get_extermities, get_intersection, mix_borders, probabilistic_hough};
use std::env::args; use std::env::args;
@ -45,6 +46,7 @@ const DEBUG: bool = true;
pub enum Sequence { pub enum Sequence {
//TODO: avoir le meme nombre d'image en mode capture ET en mode replay //TODO: avoir le meme nombre d'image en mode capture ET en mode replay
FirstState, FirstState,
WaitSpace,
BackGround, BackGround,
UpBorder, UpBorder,
LeftBorder, LeftBorder,
@ -52,10 +54,9 @@ pub enum Sequence {
RightBorder, RightBorder,
ReadDir, ReadDir,
ComputeArea, ComputeArea,
PlayLineDotted,
Finish, Finish,
WaitSpace,
WaitQ,
LinearConstSpeed, // [multiple test] LinearConstSpeed, // [multiple test]
@ -74,6 +75,7 @@ pub enum Sequence {
#[derive(Debug)] #[derive(Debug)]
pub struct Qualibration { pub struct Qualibration {
pub begin: Instant,
pub cam: VideoCapture, pub cam: VideoCapture,
pub r: i32, pub r: i32,
pub g: i32, pub g: i32,
@ -95,6 +97,7 @@ pub struct Qualibration {
pub border_pt: Vec<(f64, f64)>, pub border_pt: Vec<(f64, f64)>,
pub homography: Mat, pub homography: Mat,
pub h_size: Size_<i32>, pub h_size: Size_<i32>,
pub line_pos: Vec<i32>,
} }
impl Qualibration { impl Qualibration {
@ -113,7 +116,9 @@ impl Qualibration {
let mut frame = Mat::default(); let mut frame = Mat::default();
cam.read(&mut frame)?; cam.read(&mut frame)?;
//let now = std::time::Instant::now();
Ok(Qualibration { Ok(Qualibration {
begin: std::time::Instant::now(),
cam, cam,
r: 150, r: 150,
g: 0, g: 0,
@ -141,6 +146,7 @@ impl Qualibration {
border_pt: vec![], border_pt: vec![],
homography: Mat::default(), homography: Mat::default(),
h_size: Size::default(), h_size: Size::default(),
line_pos: vec![4095; 100],
}) })
} }
@ -151,20 +157,13 @@ impl Qualibration {
highgui::imshow("camera", &self.frame)?; 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 { if self.frame.size()?.width > 0 && self.frame_prev.size()?.width > 0 || !self.capture_mode {
//println!("plif: {}", line!());
if self.id.is_some() { if self.id.is_some() {
// println!("plif: {}", line!());
self.id = if true { self.id = if true {
//self.capture_mode || self.id == Some(Sequence::WaitSpace) || is_same_frame(&self.frame, &self.frame_prev)? { //self.capture_mode || self.id == Some(Sequence::WaitSpace) || is_same_frame(&self.frame, &self.frame_prev)? {
if self.id != Some(Sequence::WaitSpace) if self.id != Some(Sequence::WaitSpace)
&& self.id != Some(Sequence::FirstState) && self.id != Some(Sequence::FirstState)
&& self.id != Some(Sequence::PlayLineDotted)
&& self.capture_mode && self.capture_mode
{ {
self.img.push(self.frame.clone()); self.img.push(self.frame.clone());
@ -248,9 +247,29 @@ impl Qualibration {
}; };
let nb_all = self.nb_all as usize; let nb_all = self.nb_all as usize;
let nb_visible = self.nb_visible as usize; let nb_visible = self.nb_visible as usize;
let nb_wait = 20;
if seq.is_some() { if seq.is_some() {
match seq.unwrap() { 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 => { Sequence::WaitSpace => {
pl = draw::draw_line(&p0, &p1, nb_all, nb_visible)?; pl = draw::draw_line(&p0, &p1, nb_all, nb_visible)?;
pl.extend(draw::draw_line(&p1, &p2, nb_all, nb_visible)?); pl.extend(draw::draw_line(&p1, &p2, nb_all, nb_visible)?);
@ -320,11 +339,11 @@ impl Qualibration {
return None; return None;
} }
println!("Hey"); //println!("Hey");
match self.id.unwrap() { match self.id.unwrap() {
//Sequence::Finish => Some(Sequence::Finish), //Sequence::Finish => Some(Sequence::Finish),
Sequence::Finish => None, Sequence::Finish => None,
Sequence::SelectNbAll(mut n) => { Sequence::SelectNbAll(n) => {
if n == 0 { if n == 0 {
Some(Sequence::SelectNbAll(2 - 1)) Some(Sequence::SelectNbAll(2 - 1))
} else if (2 * n) > line_max as u16 { } else if (2 * n) > line_max as u16 {
@ -335,18 +354,18 @@ impl Qualibration {
} }
Sequence::WaitSpace => { Sequence::WaitSpace => {
//println!("key: {}", self.key); //println!("key: {}", self.key);
if self.key == 32 { if self.key == 32 || !self.capture_mode{
next(&Sequence::WaitSpace) next(&Sequence::WaitSpace)
} else { } else {
Some(Sequence::WaitSpace) Some(Sequence::WaitSpace)
} }
} }
Sequence::WaitQ => { Sequence::PlayLineDotted => {
//println!("key: {}", self.key); //println!("key: {}", self.key);
if self.key == 113 { if self.key == 32 {
next(&Sequence::WaitQ) next(&Sequence::PlayLineDotted)
} else { } else {
Some(Sequence::WaitQ) Some(Sequence::PlayLineDotted)
} }
} }
Sequence::Vertical(n) => { Sequence::Vertical(n) => {
@ -480,10 +499,10 @@ impl Qualibration {
// on fait le nom de dossier general au cas ou // on fait le nom de dossier general au cas ou
// on fait un nom de dossier avec le temps // on fait un nom de dossier avec le temps
// on sauvgarde toutes les image // on sauvgarde toutes les image
let now = std::time::Instant::now(); let now = self.begin;
let name = format!("image/"); let name = format!("image/");
create_dir(&name).unwrap_or(()); 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(()); create_dir(&name).unwrap_or(());
//name.push_str(format!("image/{}_{}/", now.elapsed().as_secs(), now.elapsed().as_nanos()).as_str()); //name.push_str(format!("image/{}_{}/", now.elapsed().as_secs(), now.elapsed().as_nanos()).as_str());
//let name = format!("image/{now:?}/"); //let name = format!("image/{now:?}/");
@ -510,6 +529,10 @@ impl Qualibration {
let d: Vec<_> = c[c.len()-1].chars().collect(); let d: Vec<_> = c[c.len()-1].chars().collect();
let e: String = d[4..d.len()-4].iter().collect(); let e: String = d[4..d.len()-4].iter().collect();
let img_id: i32 = e.parse()?; let img_id: i32 = e.parse()?;
//println!("c: {c:?}");
//let a: Vec<_> = path.to_str().unwrap().to_string().chars().collect();
//let b: String = a[27..(a.len() - 4)].iter().collect();
//let img_id: i32 = b.parse()?;
let path = format!("{path:?}"); let path = format!("{path:?}");
let path = path[1..(path.len() - 1)].to_owned(); let path = path[1..(path.len() - 1)].to_owned();
let img: Mat = imread(&find_file(&path, false, false)?, IMREAD_COLOR)?; let img: Mat = imread(&find_file(&path, false, false)?, IMREAD_COLOR)?;

View File

@ -411,8 +411,29 @@ pub fn trackbar_line_segment(mem: &mut Qualibration, winname: &str) -> Result<()
Ok(()) 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<f64, 4> = 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}"); //println!("winname: {winname}");
line_pos(&mut mem , "Play Line")?;
trackbar_init_param(mem, "init_param")?; trackbar_init_param(mem, "init_param")?;
//named_window(winname, WINDOW_AUTOSIZE)?; //named_window(winname, WINDOW_AUTOSIZE)?;
//associate_trackbar(winname, &mut mem.tresh)?; //associate_trackbar(winname, &mut mem.tresh)?;