Compare commits
2 Commits
e991fffdb1
...
dee7199b09
Author | SHA1 | Date | |
---|---|---|---|
dee7199b09 | |||
f74c7caf10 |
@ -90,9 +90,9 @@ fn run_all() -> Result<(), Box<dyn std::error::Error>> {
|
||||
//let _t = framerate_handler.handle_time()?;
|
||||
/////////////////
|
||||
let key = highgui::wait_key(1)?;
|
||||
if key != -1 {
|
||||
//if key != -1 {
|
||||
qualibration.key = key;
|
||||
}
|
||||
//}
|
||||
if key == 27 {
|
||||
// esc in my case
|
||||
break;
|
||||
@ -113,7 +113,7 @@ fn run_all() -> Result<(), Box<dyn std::error::Error>> {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
@ -45,6 +46,7 @@ const DEBUG: bool = true;
|
||||
pub enum Sequence {
|
||||
//TODO: avoir le meme nombre d'image en mode capture ET en mode replay
|
||||
FirstState,
|
||||
WaitSpace,
|
||||
BackGround,
|
||||
UpBorder,
|
||||
LeftBorder,
|
||||
@ -52,10 +54,9 @@ pub enum Sequence {
|
||||
RightBorder,
|
||||
ReadDir,
|
||||
ComputeArea,
|
||||
PlayLineDotted,
|
||||
Finish,
|
||||
WaitSpace,
|
||||
|
||||
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_<i32>,
|
||||
pub line_pos: Vec<i32>,
|
||||
}
|
||||
|
||||
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,11 +339,11 @@ impl Qualibration {
|
||||
return None;
|
||||
}
|
||||
|
||||
println!("Hey");
|
||||
//println!("Hey");
|
||||
match self.id.unwrap() {
|
||||
//Sequence::Finish => Some(Sequence::Finish),
|
||||
Sequence::Finish => None,
|
||||
Sequence::SelectNbAll(mut n) => {
|
||||
Sequence::SelectNbAll(n) => {
|
||||
if n == 0 {
|
||||
Some(Sequence::SelectNbAll(2 - 1))
|
||||
} else if (2 * n) > line_max as u16 {
|
||||
@ -335,18 +354,18 @@ impl Qualibration {
|
||||
}
|
||||
Sequence::WaitSpace => {
|
||||
//println!("key: {}", self.key);
|
||||
if self.key == 32 {
|
||||
if self.key == 32 || !self.capture_mode{
|
||||
next(&Sequence::WaitSpace)
|
||||
} else {
|
||||
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:?}/");
|
||||
@ -510,6 +529,10 @@ impl Qualibration {
|
||||
let d: Vec<_> = c[c.len()-1].chars().collect();
|
||||
let e: String = d[4..d.len()-4].iter().collect();
|
||||
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 = path[1..(path.len() - 1)].to_owned();
|
||||
let img: Mat = imread(&find_file(&path, false, false)?, IMREAD_COLOR)?;
|
||||
|
@ -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<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}");
|
||||
line_pos(&mut mem , "Play Line")?;
|
||||
trackbar_init_param(mem, "init_param")?;
|
||||
//named_window(winname, WINDOW_AUTOSIZE)?;
|
||||
//associate_trackbar(winname, &mut mem.tresh)?;
|
||||
|
Loading…
Reference in New Issue
Block a user