From 7460b74c154ce930b4f41f2273dac0959a98dbf3 Mon Sep 17 00:00:00 2001 From: Lapin Raving Date: Wed, 20 Sep 2023 16:52:51 +0200 Subject: [PATCH] fix: unsued and draw - remove all warning about unused function and variable. - adding draw figure to wait_space sequence --- src/framerate.rs | 5 +- src/point.rs | 1 + src/qualibration.rs | 7 +- src/qualibration/annalyse.rs | 28 ++-- src/qualibration/borders.rs | 6 +- src/qualibration/compute_image.rs | 1 + src/qualibration/sequence/init_border.rs | 3 +- src/qualibration/sequence/init_idcode.rs | 2 +- src/qualibration/sequence/wait_space.rs | 159 ++++++++++++++++++++++- 9 files changed, 190 insertions(+), 22 deletions(-) diff --git a/src/framerate.rs b/src/framerate.rs index cfca9f6..5b55ebe 100644 --- a/src/framerate.rs +++ b/src/framerate.rs @@ -1,8 +1,10 @@ +#[allow(unused)] use log::{debug, warn}; use std::thread; use std::time::{Duration, Instant}; /// Converts helios Geometry to Helios +#[allow(dead_code)] #[derive(Debug, Clone, Copy)] pub struct Framerate { start: Instant, @@ -10,6 +12,7 @@ pub struct Framerate { framerate: u8, } +#[allow(dead_code)] impl Framerate { pub fn new(framerate: u8) -> Result> { Ok(Framerate { @@ -18,7 +21,7 @@ impl Framerate { framerate, }) } - pub fn handle_time(&mut self) -> Result<(f64), Box> { + pub fn handle_time(&mut self) -> Result> { let frame_time = 1000000000 / self.framerate as u128; let now = Instant::now(); // How long since last loop ? diff --git a/src/point.rs b/src/point.rs index 36f13b8..c720627 100644 --- a/src/point.rs +++ b/src/point.rs @@ -1,3 +1,4 @@ +#[allow(dead_code)] pub type Line = Vec<(f32, f32, u32)>; #[derive(Debug, Clone, Copy, Default, PartialEq)] diff --git a/src/qualibration.rs b/src/qualibration.rs index a1f8f15..1737b67 100644 --- a/src/qualibration.rs +++ b/src/qualibration.rs @@ -1,6 +1,7 @@ //use opencv::Result; //use opencv::core::{self, Mat}; +#[allow(dead_code)] static DEBUG: bool = true; pub mod annalyse; @@ -25,7 +26,7 @@ mod param; use param::Param; mod sequence; -pub use sequence::{InitBorder, LineDotted, LoadImage, SaveImage, Sequence, WaitSpace, InitIdcode}; +pub use sequence::{InitBorder, InitIdcode, LineDotted, LoadImage, SaveImage, Sequence, WaitSpace}; #[derive(Debug)] pub struct Qualibration { @@ -54,12 +55,12 @@ impl Qualibration { cam.read(&mut frame)?; // 38400 -> r:150, v:0, b:0 - let beg = Point::from((0., 0., 38400)); + let beg = Point::from((0., 0., 38400)); let beg2 = Point::from((4095., 0., 38400)); let end = Point::from((4095., 4095., 38400)); let seq: Vec> = vec![ Box::new(LoadImage::new()), - Box::new(WaitSpace::new()), + Box::new(WaitSpace::new(beg, end)), Box::new(InitBorder::new(beg, end)), Box::new(LineDotted::new(beg, end, true, false)), Box::new(InitIdcode::new(beg2, end)), diff --git a/src/qualibration/annalyse.rs b/src/qualibration/annalyse.rs index cdbeae7..05e2e37 100644 --- a/src/qualibration/annalyse.rs +++ b/src/qualibration/annalyse.rs @@ -28,6 +28,7 @@ opencv::not_opencv_branch_4! { use super::param::Treshold; const MAX_TRACKBAR: i32 = 255; +#[allow(dead_code)] pub fn draw_histograme_dbg( window_name: &str, histo: &Vec, @@ -66,6 +67,7 @@ pub fn draw_histograme_dbg( Ok(()) } +#[allow(dead_code)] pub fn draw_histograme(window_name: &str, histo: &Vec) -> Result<()> { let v: VecN = VecN::new(0., 0., 0., 255.); let color: VecN = VecN::new(255., 255., 255., 255.); @@ -104,6 +106,7 @@ pub fn draw_histograme(window_name: &str, histo: &Vec) -> Result<()> { Ok(()) } +#[allow(dead_code)] pub fn draw_histograme_bgr(window_name: &str, histo: &Vec>) -> Result<()> { let v: VecN = VecN::new(0., 0., 0., 255.); let b: VecN = VecN::new(255., 0., 0., 255.); @@ -196,6 +199,7 @@ pub fn draw_histograme_bgr_tresh( } // limit = 0.35 c'est bien +#[allow(dead_code)] pub fn is_same_frame(frame: &Mat, frame_prev: &Mat) -> Result { let nb_liss: i32 = 50; // plus on lisse la courbe plus on attein la limite facilement let limit = 0.45; // plus c'est haut, plus on tolere de changement entre 2 image @@ -289,7 +293,7 @@ pub fn get_horizontal_segment(m: &Mat) -> Result Result Result Result Result Result Result (f32, f32) { let (mut mean_x, mut mean_y) = (0., 0.); let len = vals.len() as f32; @@ -566,6 +571,7 @@ fn get_id_groups(limits: &Vec<(usize, usize)>, id: usize) -> Option { //return usize::MAX; // im lazy to have Option return... } +#[allow(dead_code)] pub fn annalyse_segment(m: &Mat) -> Result>> { // on recupere les coordoner des point selectioner let mut seg_pt = HashSet::from([]); @@ -585,7 +591,7 @@ pub fn annalyse_segment(m: &Mat) -> Result>> { let mut selected: HashSet<(i32, i32)> = seg_pt .iter() .filter_map(|(x, y)| { - for (k, (i, j)) in around_all.iter().enumerate() { + for (_k, (i, j)) in around_all.iter().enumerate() { if seg_pt.get(&(*x + i, *y + j)).is_none() { return Some((*x, *y)); } @@ -642,6 +648,7 @@ pub fn annalyse_segment(m: &Mat) -> Result>> { Ok(lines) } +#[allow(dead_code)] pub fn image_mean(frames: &[Mat]) -> Result { /* * Il faudrait pouvoir changer les matrice de type pour avoir des valeur plus grande @@ -802,6 +809,7 @@ pub fn first_invert(histo: &Vec) -> ((usize, f64), (usize, f64)) { ) } +#[allow(dead_code)] pub fn trackbar_init_param(mem: &mut Param, winname: &str) -> Result<()> { named_window(winname, WINDOW_AUTOSIZE)?; highgui::move_window(winname, 20, 20)?; @@ -818,6 +826,7 @@ pub fn trackbar_init_param(mem: &mut Param, winname: &str) -> Result<()> { Ok(()) } +#[allow(dead_code)] pub fn trackbar_line_segment(mem: &mut Param, winname: &str) -> Result<()> { //highgui let winname = format!("{}: {}", winname, 0); //"bord selected: 0"; @@ -881,6 +890,7 @@ pub fn trackbar_line_segment(mem: &mut Param, winname: &str) -> Result<()> { Ok(()) } +#[allow(dead_code)] pub fn line_pos(mem: &mut Param, winname: &str) -> Result<()> { named_window(winname, WINDOW_AUTOSIZE)?; highgui::move_window(winname, 20, 20)?; @@ -901,7 +911,7 @@ pub fn line_pos(mem: &mut Param, winname: &str) -> Result<()> { Ok(()) } -pub fn adding_trackbar(mut mem: &mut Param, winname: &str) -> Result<()> { +pub fn adding_trackbar(mem: &mut Param, _winname: &str) -> Result<()> { //println!("winname: {winname}"); //line_pos(&mut mem, "Play Line")?; //trackbar_init_param(mem, "init_param")?; diff --git a/src/qualibration/borders.rs b/src/qualibration/borders.rs index 326176f..78543b2 100644 --- a/src/qualibration/borders.rs +++ b/src/qualibration/borders.rs @@ -7,6 +7,7 @@ use opencv::prelude::*; //MatTraitConst; use opencv::types::VectorOfVec4i; use opencv::Result; +#[allow(dead_code)] pub fn mix_borders(background: &Mat, borders: Vec) -> Result { let (row, col) = (background.rows(), background.cols()); //let mask = Mat::default(); @@ -74,8 +75,9 @@ pub fn bord_mult(pt: Vec<(f64, f64)>, factor: f64) -> Vec<(f64, f64)> { } // en fait ca marche pas dutout...next time +#[allow(dead_code)] pub fn bord_mult_v2(pt: Vec<(f64, f64)>, factor: f64) -> Vec<(f64, f64)> { - let mut pt: Vec = pt.iter().map(|p| Pt::from(p)).collect(); + let pt: Vec = pt.iter().map(|p| Pt::from(p)).collect(); let mut pn = vec![]; for i in 0..pt.len() { @@ -159,7 +161,7 @@ pub fn get_extermities(lines: &Vector>, id: usize) -> ((f64, f64), pub fn probabilistic_hough( edges: &Mat, hough_param: &HoughLine, - id: usize, + _id: usize, ) -> Result>> { let mut p_lines = VectorOfVec4i::new(); let mut probabalistic_hough = Mat::default(); diff --git a/src/qualibration/compute_image.rs b/src/qualibration/compute_image.rs index 1072dd8..ebee19b 100644 --- a/src/qualibration/compute_image.rs +++ b/src/qualibration/compute_image.rs @@ -31,6 +31,7 @@ pub fn image_treshold(img: &Mat, tresh: &Treshold) -> Result { Ok(bord_treshed) } +#[allow(dead_code)] pub fn image_warp_treshold( img: &Mat, homography: &Mat, diff --git a/src/qualibration/sequence/init_border.rs b/src/qualibration/sequence/init_border.rs index 237de4a..bcdd4e6 100644 --- a/src/qualibration/sequence/init_border.rs +++ b/src/qualibration/sequence/init_border.rs @@ -18,6 +18,7 @@ use opencv::{ }; opencv::opencv_branch_4! { + #[allow(unused)] use opencv::imgproc::LINE_AA; } opencv::not_opencv_branch_4! { @@ -27,8 +28,8 @@ opencv::not_opencv_branch_4! { #[derive(Debug, Clone, Copy)] pub struct InitBorder { finished: bool, - borders: [Point; 4], cnt: usize, + borders: [Point; 4], } impl InitBorder { diff --git a/src/qualibration/sequence/init_idcode.rs b/src/qualibration/sequence/init_idcode.rs index 81c527c..1fbd900 100644 --- a/src/qualibration/sequence/init_idcode.rs +++ b/src/qualibration/sequence/init_idcode.rs @@ -63,7 +63,7 @@ impl Sequence for InitIdcode { fn compute_sequence(&mut self, mem: &mut Param) -> Result<(), Box> { if self.cnt == 0 { self.cnt += 1; - return Ok(()) + return Ok(()); } let id = mem.seq_id; let mut id_code_1 = image_diff(&mem.imgs[id][1], &mem.imgs[id][0])?; diff --git a/src/qualibration/sequence/wait_space.rs b/src/qualibration/sequence/wait_space.rs index ff359dd..db26bcf 100644 --- a/src/qualibration/sequence/wait_space.rs +++ b/src/qualibration/sequence/wait_space.rs @@ -1,13 +1,84 @@ use super::{super::Param, Sequence}; -use crate::point::Point; +use crate::{ + draw::{draw_line, draw_line_dotted}, + point::{Color, Point}, +}; + use opencv::Result; #[derive(Debug, Clone, Copy)] -pub struct WaitSpace {} +pub struct WaitSpace { + borders: [Point; 4], + red: [Point; 2], + green: [Point; 2], + blue: [Point; 2], +} impl WaitSpace { - pub fn new() -> Self { - Self {} + pub fn new(beg: Point, end: Point) -> Self { + let red_y = (end.y - beg.y) * 1./5. + beg.y; + let green_y = (end.y - beg.y) * 2./5. + beg.y; + let blue_y = (end.y - beg.y) * 3./5. + beg.y; + Self { + borders: [ + Point { + x: beg.x, + y: beg.y, + color: end.color, + }, + Point { + x: end.x, + y: beg.y, + color: end.color, + }, + Point { + x: end.x, + y: end.y, + color: end.color, + }, + Point { + x: beg.x, + y: end.y, + color: end.color, + }, + ], + red: [ + Point { + x: beg.x, + y: red_y, + color: end.color, + }, + Point { + x: end.x, + y: red_y, + color: end.color, + }, + ], + blue: [ + Point { + x: beg.x, + y: blue_y, + color: end.color, + }, + Point { + x: end.x, + y: blue_y, + color: end.color, + }, + ], + green: [ + Point { + x: beg.x, + y: green_y, + color: end.color, + }, + Point { + x: end.x, + y: green_y, + color: end.color, + }, + ], + } } } @@ -16,7 +87,85 @@ impl Sequence for WaitSpace { if mem.key == 32 || !mem.capture_mode { return None; } - Some(vec![]) + + let mut pl = vec![]; + let color = Color { + r: mem.r as u8, + g: mem.g as u8, + b: mem.b as u8, + }; + let red = Color { + r: mem.r as u8, + g: 0, + b: 0, + }; + let green = Color { + r: 0, + g: mem.g as u8, + b: 0, + }; + let blue = Color { + r: 0, + g: 0, + b: mem.b as u8, + }; + for i in 0..self.borders.len() { + let id1 = (i + 1) % self.borders.len(); + let p0 = Point { + color, + ..self.borders[i] + }; + let p1 = Point { + color, + ..self.borders[id1] + }; + pl.extend(draw_line( + &p0, + &p1, + mem.nb_all as usize, + mem.nb_visible as usize, + )); + pl.extend(draw_line_dotted( + &Point{ + color: blue, + ..self.blue[0] + }, + &Point{ + color: blue, + ..self.blue[1] + }, + mem.nb_all as usize, + mem.nb_visible as usize, + true, + )); + pl.extend(draw_line_dotted( + &Point{ + color: green, + ..self.green[0] + }, + &Point{ + color: green, + ..self.green[1] + }, + mem.nb_all as usize, + mem.nb_visible as usize, + true, + )); + pl.extend(draw_line_dotted( + &Point{ + color: red, + ..self.red[0] + }, + &Point{ + color: red, + ..self.red[1] + }, + mem.nb_all as usize, + mem.nb_visible as usize, + true, + )); + } + Some(pl) } fn compute_sequence(&mut self, _mem: &mut Param) -> Result<(), Box> { Ok(())