fix: unsued and draw

- remove all warning about unused function and variable.
- adding draw figure to wait_space sequence
This commit is contained in:
Lapin Raving 2023-09-20 16:52:51 +02:00
parent 21700d5806
commit 7460b74c15
9 changed files with 190 additions and 22 deletions

View File

@ -1,8 +1,10 @@
#[allow(unused)]
use log::{debug, warn}; use log::{debug, warn};
use std::thread; use std::thread;
use std::time::{Duration, Instant}; use std::time::{Duration, Instant};
/// Converts helios Geometry to Helios /// Converts helios Geometry to Helios
#[allow(dead_code)]
#[derive(Debug, Clone, Copy)] #[derive(Debug, Clone, Copy)]
pub struct Framerate { pub struct Framerate {
start: Instant, start: Instant,
@ -10,6 +12,7 @@ pub struct Framerate {
framerate: u8, framerate: u8,
} }
#[allow(dead_code)]
impl Framerate { impl Framerate {
pub fn new(framerate: u8) -> Result<Self, Box<dyn std::error::Error>> { pub fn new(framerate: u8) -> Result<Self, Box<dyn std::error::Error>> {
Ok(Framerate { Ok(Framerate {
@ -18,7 +21,7 @@ impl Framerate {
framerate, framerate,
}) })
} }
pub fn handle_time(&mut self) -> Result<(f64), Box<dyn std::error::Error>> { pub fn handle_time(&mut self) -> Result<f64, Box<dyn std::error::Error>> {
let frame_time = 1000000000 / self.framerate as u128; let frame_time = 1000000000 / self.framerate as u128;
let now = Instant::now(); let now = Instant::now();
// How long since last loop ? // How long since last loop ?

View File

@ -1,3 +1,4 @@
#[allow(dead_code)]
pub type Line = Vec<(f32, f32, u32)>; pub type Line = Vec<(f32, f32, u32)>;
#[derive(Debug, Clone, Copy, Default, PartialEq)] #[derive(Debug, Clone, Copy, Default, PartialEq)]

View File

@ -1,6 +1,7 @@
//use opencv::Result; //use opencv::Result;
//use opencv::core::{self, Mat}; //use opencv::core::{self, Mat};
#[allow(dead_code)]
static DEBUG: bool = true; static DEBUG: bool = true;
pub mod annalyse; pub mod annalyse;
@ -25,7 +26,7 @@ mod param;
use param::Param; use param::Param;
mod sequence; mod sequence;
pub use sequence::{InitBorder, LineDotted, LoadImage, SaveImage, Sequence, WaitSpace, InitIdcode}; pub use sequence::{InitBorder, InitIdcode, LineDotted, LoadImage, SaveImage, Sequence, WaitSpace};
#[derive(Debug)] #[derive(Debug)]
pub struct Qualibration { pub struct Qualibration {
@ -54,12 +55,12 @@ impl Qualibration {
cam.read(&mut frame)?; cam.read(&mut frame)?;
// 38400 -> r:150, v:0, b:0 // 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 beg2 = Point::from((4095., 0., 38400));
let end = Point::from((4095., 4095., 38400)); let end = Point::from((4095., 4095., 38400));
let seq: Vec<Box<dyn Sequence>> = vec![ let seq: Vec<Box<dyn Sequence>> = vec![
Box::new(LoadImage::new()), Box::new(LoadImage::new()),
Box::new(WaitSpace::new()), Box::new(WaitSpace::new(beg, end)),
Box::new(InitBorder::new(beg, end)), Box::new(InitBorder::new(beg, end)),
Box::new(LineDotted::new(beg, end, true, false)), Box::new(LineDotted::new(beg, end, true, false)),
Box::new(InitIdcode::new(beg2, end)), Box::new(InitIdcode::new(beg2, end)),

View File

@ -28,6 +28,7 @@ opencv::not_opencv_branch_4! {
use super::param::Treshold; use super::param::Treshold;
const MAX_TRACKBAR: i32 = 255; const MAX_TRACKBAR: i32 = 255;
#[allow(dead_code)]
pub fn draw_histograme_dbg( pub fn draw_histograme_dbg(
window_name: &str, window_name: &str,
histo: &Vec<f64>, histo: &Vec<f64>,
@ -66,6 +67,7 @@ pub fn draw_histograme_dbg(
Ok(()) Ok(())
} }
#[allow(dead_code)]
pub fn draw_histograme(window_name: &str, histo: &Vec<f64>) -> Result<()> { pub fn draw_histograme(window_name: &str, histo: &Vec<f64>) -> Result<()> {
let v: VecN<f64, 4> = VecN::new(0., 0., 0., 255.); let v: VecN<f64, 4> = VecN::new(0., 0., 0., 255.);
let color: VecN<f64, 4> = VecN::new(255., 255., 255., 255.); let color: VecN<f64, 4> = VecN::new(255., 255., 255., 255.);
@ -104,6 +106,7 @@ pub fn draw_histograme(window_name: &str, histo: &Vec<f64>) -> Result<()> {
Ok(()) Ok(())
} }
#[allow(dead_code)]
pub fn draw_histograme_bgr(window_name: &str, histo: &Vec<Vec<f64>>) -> Result<()> { pub fn draw_histograme_bgr(window_name: &str, histo: &Vec<Vec<f64>>) -> Result<()> {
let v: VecN<f64, 4> = VecN::new(0., 0., 0., 255.); let v: VecN<f64, 4> = VecN::new(0., 0., 0., 255.);
let b: VecN<f64, 4> = VecN::new(255., 0., 0., 255.); let b: VecN<f64, 4> = VecN::new(255., 0., 0., 255.);
@ -196,6 +199,7 @@ pub fn draw_histograme_bgr_tresh(
} }
// limit = 0.35 c'est bien // limit = 0.35 c'est bien
#[allow(dead_code)]
pub fn is_same_frame(frame: &Mat, frame_prev: &Mat) -> Result<bool> { pub fn is_same_frame(frame: &Mat, frame_prev: &Mat) -> Result<bool> {
let nb_liss: i32 = 50; // plus on lisse la courbe plus on attein la limite facilement 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 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<Vec<(((f32, f32), (f32, f32)),
.collect(); .collect();
let mut segments = vec![]; let mut segments = vec![];
for (i, iland) in segment_iland_pt.iter().enumerate() { for (_i, iland) in segment_iland_pt.iter().enumerate() {
let mut center = Pt { x: 0., y: 0. }; let mut center = Pt { x: 0., y: 0. };
for p in iland { for p in iland {
center += *p; center += *p;
@ -452,7 +456,7 @@ pub fn get_vertical_segment(m: &Mat) -> Result<Vec<(((f32, f32), (f32, f32)), f3
// TODO: La selection des pixel pour chaque illot pourrait etre ameliorer // TODO: La selection des pixel pour chaque illot pourrait etre ameliorer
// En fait elle me va bien. C'est vrai que il ne sont pas ouf mais bon... // En fait elle me va bien. C'est vrai que il ne sont pas ouf mais bon...
let mut segments = vec![]; let mut segments = vec![];
for (i, iland) in segment_iland_pt.iter().enumerate() { for (_i, iland) in segment_iland_pt.iter().enumerate() {
let mut center = Pt { x: 0., y: 0. }; let mut center = Pt { x: 0., y: 0. };
for p in iland { for p in iland {
center += *p; center += *p;
@ -460,7 +464,7 @@ pub fn get_vertical_segment(m: &Mat) -> Result<Vec<(((f32, f32), (f32, f32)), f3
center /= iland.len() as f64; center /= iland.len() as f64;
let max_deg = 360; let max_deg = 360;
let (mut err_min, mut rad_min, mut x_min) = (f64::MAX, 0., f64::MAX); let (mut _err_min, mut rad_min, mut x_min) = (f64::MAX, 0., f64::MAX);
let mut iland_min = vec![]; let mut iland_min = vec![];
for deg in 0..max_deg { for deg in 0..max_deg {
let rad = (deg as f64) / (max_deg as f64) * PI * 2.; let rad = (deg as f64) / (max_deg as f64) * PI * 2.;
@ -472,7 +476,7 @@ pub fn get_vertical_segment(m: &Mat) -> Result<Vec<(((f32, f32), (f32, f32)), f3
x: -y_axis.y, x: -y_axis.y,
y: y_axis.x, y: y_axis.x,
}; };
let mut err = 0.; let mut _err = 0.;
let mut tmp_iland = vec![]; let mut tmp_iland = vec![];
let mut x_abs_max = f64::MIN; let mut x_abs_max = f64::MIN;
for pt in iland { for pt in iland {
@ -481,7 +485,7 @@ pub fn get_vertical_segment(m: &Mat) -> Result<Vec<(((f32, f32), (f32, f32)), f3
x: p.cross(&x_axis), x: p.cross(&x_axis),
y: p.cross(&y_axis), y: p.cross(&y_axis),
}; };
err += p.x * p.x; _err += p.x * p.x;
tmp_iland.push(p); tmp_iland.push(p);
if x_abs_max < p.x.abs() { if x_abs_max < p.x.abs() {
x_abs_max = p.x.abs(); x_abs_max = p.x.abs();
@ -492,8 +496,8 @@ pub fn get_vertical_segment(m: &Mat) -> Result<Vec<(((f32, f32), (f32, f32)), f3
rad_min = rad; rad_min = rad;
iland_min = tmp_iland; iland_min = tmp_iland;
} }
//if err < err_min { //if _err < _err_min {
// err_min = err; // err_min = _err;
// rad_min = rad; // rad_min = rad;
// iland_min = tmp_iland; // iland_min = tmp_iland;
//} //}
@ -545,6 +549,7 @@ pub fn get_vertical_segment(m: &Mat) -> Result<Vec<(((f32, f32), (f32, f32)), f3
Ok(segments) Ok(segments)
} }
#[allow(dead_code)]
fn average_pt_i32(vals: &[(i32, i32)]) -> (f32, f32) { fn average_pt_i32(vals: &[(i32, i32)]) -> (f32, f32) {
let (mut mean_x, mut mean_y) = (0., 0.); let (mut mean_x, mut mean_y) = (0., 0.);
let len = vals.len() as f32; let len = vals.len() as f32;
@ -566,6 +571,7 @@ fn get_id_groups(limits: &Vec<(usize, usize)>, id: usize) -> Option<usize> {
//return usize::MAX; // im lazy to have Option return... //return usize::MAX; // im lazy to have Option return...
} }
#[allow(dead_code)]
pub fn annalyse_segment(m: &Mat) -> Result<Vec<Vec<(i32, i32)>>> { pub fn annalyse_segment(m: &Mat) -> Result<Vec<Vec<(i32, i32)>>> {
// on recupere les coordoner des point selectioner // on recupere les coordoner des point selectioner
let mut seg_pt = HashSet::from([]); let mut seg_pt = HashSet::from([]);
@ -585,7 +591,7 @@ pub fn annalyse_segment(m: &Mat) -> Result<Vec<Vec<(i32, i32)>>> {
let mut selected: HashSet<(i32, i32)> = seg_pt let mut selected: HashSet<(i32, i32)> = seg_pt
.iter() .iter()
.filter_map(|(x, y)| { .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() { if seg_pt.get(&(*x + i, *y + j)).is_none() {
return Some((*x, *y)); return Some((*x, *y));
} }
@ -642,6 +648,7 @@ pub fn annalyse_segment(m: &Mat) -> Result<Vec<Vec<(i32, i32)>>> {
Ok(lines) Ok(lines)
} }
#[allow(dead_code)]
pub fn image_mean(frames: &[Mat]) -> Result<Mat> { pub fn image_mean(frames: &[Mat]) -> Result<Mat> {
/* /*
* Il faudrait pouvoir changer les matrice de type pour avoir des valeur plus grande * Il faudrait pouvoir changer les matrice de type pour avoir des valeur plus grande
@ -802,6 +809,7 @@ pub fn first_invert(histo: &Vec<f64>) -> ((usize, f64), (usize, f64)) {
) )
} }
#[allow(dead_code)]
pub fn trackbar_init_param(mem: &mut Param, winname: &str) -> Result<()> { pub fn trackbar_init_param(mem: &mut Param, winname: &str) -> Result<()> {
named_window(winname, WINDOW_AUTOSIZE)?; named_window(winname, WINDOW_AUTOSIZE)?;
highgui::move_window(winname, 20, 20)?; highgui::move_window(winname, 20, 20)?;
@ -818,6 +826,7 @@ pub fn trackbar_init_param(mem: &mut Param, winname: &str) -> Result<()> {
Ok(()) Ok(())
} }
#[allow(dead_code)]
pub fn trackbar_line_segment(mem: &mut Param, winname: &str) -> Result<()> { pub fn trackbar_line_segment(mem: &mut Param, winname: &str) -> Result<()> {
//highgui //highgui
let winname = format!("{}: {}", winname, 0); //"bord selected: 0"; let winname = format!("{}: {}", winname, 0); //"bord selected: 0";
@ -881,6 +890,7 @@ pub fn trackbar_line_segment(mem: &mut Param, winname: &str) -> Result<()> {
Ok(()) Ok(())
} }
#[allow(dead_code)]
pub fn line_pos(mem: &mut Param, winname: &str) -> Result<()> { pub fn line_pos(mem: &mut Param, winname: &str) -> Result<()> {
named_window(winname, WINDOW_AUTOSIZE)?; named_window(winname, WINDOW_AUTOSIZE)?;
highgui::move_window(winname, 20, 20)?; highgui::move_window(winname, 20, 20)?;
@ -901,7 +911,7 @@ pub fn line_pos(mem: &mut Param, winname: &str) -> Result<()> {
Ok(()) 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}"); //println!("winname: {winname}");
//line_pos(&mut mem, "Play Line")?; //line_pos(&mut mem, "Play Line")?;
//trackbar_init_param(mem, "init_param")?; //trackbar_init_param(mem, "init_param")?;

View File

@ -7,6 +7,7 @@ use opencv::prelude::*; //MatTraitConst;
use opencv::types::VectorOfVec4i; use opencv::types::VectorOfVec4i;
use opencv::Result; use opencv::Result;
#[allow(dead_code)]
pub fn mix_borders(background: &Mat, borders: Vec<Mat>) -> Result<Mat> { pub fn mix_borders(background: &Mat, borders: Vec<Mat>) -> Result<Mat> {
let (row, col) = (background.rows(), background.cols()); let (row, col) = (background.rows(), background.cols());
//let mask = Mat::default(); //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 // 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)> { pub fn bord_mult_v2(pt: Vec<(f64, f64)>, factor: f64) -> Vec<(f64, f64)> {
let mut pt: Vec<Pt> = pt.iter().map(|p| Pt::from(p)).collect(); let pt: Vec<Pt> = pt.iter().map(|p| Pt::from(p)).collect();
let mut pn = vec![]; let mut pn = vec![];
for i in 0..pt.len() { for i in 0..pt.len() {
@ -159,7 +161,7 @@ pub fn get_extermities(lines: &Vector<VecN<i32, 4>>, id: usize) -> ((f64, f64),
pub fn probabilistic_hough( pub fn probabilistic_hough(
edges: &Mat, edges: &Mat,
hough_param: &HoughLine, hough_param: &HoughLine,
id: usize, _id: usize,
) -> Result<Vector<VecN<i32, 4>>> { ) -> Result<Vector<VecN<i32, 4>>> {
let mut p_lines = VectorOfVec4i::new(); let mut p_lines = VectorOfVec4i::new();
let mut probabalistic_hough = Mat::default(); let mut probabalistic_hough = Mat::default();

View File

@ -31,6 +31,7 @@ pub fn image_treshold(img: &Mat, tresh: &Treshold) -> Result<Mat> {
Ok(bord_treshed) Ok(bord_treshed)
} }
#[allow(dead_code)]
pub fn image_warp_treshold( pub fn image_warp_treshold(
img: &Mat, img: &Mat,
homography: &Mat, homography: &Mat,

View File

@ -18,6 +18,7 @@ use opencv::{
}; };
opencv::opencv_branch_4! { opencv::opencv_branch_4! {
#[allow(unused)]
use opencv::imgproc::LINE_AA; use opencv::imgproc::LINE_AA;
} }
opencv::not_opencv_branch_4! { opencv::not_opencv_branch_4! {
@ -27,8 +28,8 @@ opencv::not_opencv_branch_4! {
#[derive(Debug, Clone, Copy)] #[derive(Debug, Clone, Copy)]
pub struct InitBorder { pub struct InitBorder {
finished: bool, finished: bool,
borders: [Point; 4],
cnt: usize, cnt: usize,
borders: [Point; 4],
} }
impl InitBorder { impl InitBorder {

View File

@ -63,7 +63,7 @@ impl Sequence for InitIdcode {
fn compute_sequence(&mut self, mem: &mut Param) -> Result<(), Box<dyn std::error::Error>> { fn compute_sequence(&mut self, mem: &mut Param) -> Result<(), Box<dyn std::error::Error>> {
if self.cnt == 0 { if self.cnt == 0 {
self.cnt += 1; self.cnt += 1;
return Ok(()) return Ok(());
} }
let id = mem.seq_id; let id = mem.seq_id;
let mut id_code_1 = image_diff(&mem.imgs[id][1], &mem.imgs[id][0])?; let mut id_code_1 = image_diff(&mem.imgs[id][1], &mem.imgs[id][0])?;

View File

@ -1,13 +1,84 @@
use super::{super::Param, Sequence}; use super::{super::Param, Sequence};
use crate::point::Point; use crate::{
draw::{draw_line, draw_line_dotted},
point::{Color, Point},
};
use opencv::Result; use opencv::Result;
#[derive(Debug, Clone, Copy)] #[derive(Debug, Clone, Copy)]
pub struct WaitSpace {} pub struct WaitSpace {
borders: [Point; 4],
red: [Point; 2],
green: [Point; 2],
blue: [Point; 2],
}
impl WaitSpace { impl WaitSpace {
pub fn new() -> Self { pub fn new(beg: Point, end: Point) -> Self {
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 { if mem.key == 32 || !mem.capture_mode {
return None; 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<dyn std::error::Error>> { fn compute_sequence(&mut self, _mem: &mut Param) -> Result<(), Box<dyn std::error::Error>> {
Ok(()) Ok(())