fix: save and load

This commit is contained in:
Lapin Raving 2023-09-21 03:20:35 +02:00
parent 7460b74c15
commit fef7e1387b
11 changed files with 267 additions and 227 deletions

View File

@ -87,46 +87,36 @@ fn run_all() -> Result<(), Box<dyn std::error::Error>> {
)?;
while running.load(Ordering::SeqCst) {
//let _t = _framerate_handler.handle_time()?;
/////////////////
let key = highgui::wait_key(1)?;
let key = highgui::wait_key(20)?;
let v = qualibration.draw_sequence();
if key != -1 {
println!("key: {key}");
// 81 <- -> 83
}
qualibration.param.key = key;
if key == 27 {
break;
}
let v = qualibration.draw_sequence();
if v.is_some() {
if qualibration.param.capture_mode {
let pl: Vec<(f32, f32, u32)> = v
.unwrap()
.iter()
.map(|pt| (pt.x, pt.y, u32::from(pt.color)))
.collect();
let _ = con.set(
format!("/pl/{}/{}", config.client_id, config.laser_id),
format!("{:?}", pl),
)?;
qualibration.param.save_image()?;
}
qualibration.run_step()?;
break;
} else if v.is_none() {
continue;
}
//qualibration.id = next_id;
//let q_id = qualibration.id.clone();
//let mut n = 65534;
//if let Sequence::TakeMultiple(m) = q_id.clone().unwrap_or(Sequence::Finish) {
// n = m;
//};
//if qualibration.capture_mode
// && (q_id != Some(Sequence::WaitSpace)
// || q_id != Some(Sequence::PlayLineDotted)
// || n != 65534)
//{
// let millis = std::time::Duration::from_millis(400); // TODO: find solution to know when change has been done
// std::thread::sleep(millis);
//}
if qualibration.param.capture_mode {
let pl: Vec<(f32, f32, u32)> = v
.unwrap()
.iter()
.map(|pt| (pt.x, pt.y, u32::from(pt.color)))
.collect();
con.set(
format!("/pl/{}/{}", config.client_id, config.laser_id),
format!("{:?}", pl),
)?;
}
qualibration.run_step()?;
}
let _ = con.set(
@ -135,3 +125,21 @@ fn run_all() -> Result<(), Box<dyn std::error::Error>> {
)?;
Ok(())
}
//let _t = _framerate_handler.handle_time()?;
/////////////////
//qualibration.id = next_id;
//let q_id = qualibration.id.clone();
//let mut n = 65534;
//if let Sequence::TakeMultiple(m) = q_id.clone().unwrap_or(Sequence::Finish) {
// n = m;
//};
//if qualibration.capture_mode
// && (q_id != Some(Sequence::WaitSpace)
// || q_id != Some(Sequence::PlayLineDotted)
// || n != 65534)
//{
// let millis = std::time::Duration::from_millis(400); // TODO: find solution to know when change has been done
// std::thread::sleep(millis);
//}

View File

@ -37,7 +37,7 @@ pub struct Qualibration {
}
impl Qualibration {
pub fn new() -> Result<Self> {
pub fn new() -> Result<Self, Box<dyn std::error::Error>> {
//let v: Vec<Box<dyn Sequence>> = vec![];
let mut dir_name = "".to_string(); //"building.jpg".to_string(); // by default
@ -54,23 +54,25 @@ impl Qualibration {
let mut frame = Mat::default();
cam.read(&mut frame)?;
// 38400 -> r:150, v:0, b:0
let beg = Point::from((0., 0., 38400));
let beg2 = Point::from((4095., 0., 38400));
let end = Point::from((4095., 4095., 38400));
// 9830400 -> r:150, v:0, b:0
let beg = Point::from((0., 0., 9830400));
let beg2 = Point::from((0., 4095., 9830400));
let end = Point::from((4095., 4095., 9830400));
let seq: Vec<Box<dyn Sequence>> = vec![
Box::new(LoadImage::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)),
Box::new(SaveImage::new()),
Box::new(WaitSpace::new(beg, end, 400)),
Box::new(InitBorder::new(beg, end, 400)),
Box::new(LineDotted::new(beg, end, 2, true, false, 400)),
Box::new(InitIdcode::new(beg2, end, 400)),
];
//let now = std::time::Instant::now();
let seq_names = get_sequence_name(&seq);
let mut param = Param::new(dir_name.to_owned(), seq_names)?;
if !param.capture_mode {
param.load_image()?;
}
Ok(Qualibration {
seq,
cam,
param: Param::new(dir_name.to_owned())?,
param,
})
}
@ -92,7 +94,18 @@ impl Qualibration {
}
pub fn run_step(self: &mut Self) -> Result<(), Box<dyn std::error::Error>> {
let seq_id = self.param.seq_id;
let seq_name = self.seq[seq_id].sequence_name();
println!("seq[{seq_id}]: {seq_name}");
if self.param.capture_mode {
let millis_nb = self.seq[self.param.seq_id].wait_milis();
let millis = std::time::Duration::from_millis(millis_nb); // TODO: find solution to know when change has been done
std::thread::sleep(millis);
}
let mut frame = Mat::default();
//println!("sequence: {}:{:?}", self.param.seq_id, &self.seq[self.param.seq_id]);
if self.param.capture_mode {
self.cam.read(&mut frame)?;
highgui::imshow("camera", &frame)?;
@ -108,4 +121,16 @@ impl Qualibration {
Ok(())
}
}
pub fn get_sequence_name(seq: &Vec<Box<dyn Sequence>>) -> Vec<String> {
let mut v = vec![];
for i in 0..seq.len() {
v.push(seq[i].sequence_name());
}
v
}

View File

@ -819,6 +819,7 @@ pub fn trackbar_init_param(mem: &mut Param, winname: &str) -> Result<()> {
create_trackbar("nb_all", winname, Some(&mut mem.nb_all), 400, None)?;
create_trackbar("nb_visible", winname, Some(&mut mem.nb_visible), 400, None)?;
create_trackbar("nb_wait", winname, Some(&mut mem.nb_wait), 40, None)?;
create_trackbar("r", winname, Some(&mut mem.r), MAX_TRACKBAR, None)?;
create_trackbar("g", winname, Some(&mut mem.g), MAX_TRACKBAR, None)?;
create_trackbar("b", winname, Some(&mut mem.b), MAX_TRACKBAR, None)?;
@ -914,7 +915,7 @@ pub fn line_pos(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")?;
trackbar_init_param(mem, "init_param")?;
named_window("histo bgr", WINDOW_AUTOSIZE)?;
associate_trackbar("histo bgr", &mut mem.tresh)?;

View File

@ -10,6 +10,7 @@ use std::time::Instant;
#[derive(Clone, Debug)]
pub struct Param {
pub seq_id: usize,
pub seq_names: Vec<String>,
pub imgs: Vec<Vec<Mat>>,
pub dst_size: i32,
pub r: i32,
@ -35,7 +36,7 @@ pub struct Param {
}
impl Param {
pub fn new(dir_name: String) -> Result<Self> {
pub fn new(dir_name: String, seq_names: Vec<String>) -> Result<Self> {
Ok(Self {
begin: std::time::Instant::now(),
capture_mode: dir_name.len() == 0,
@ -43,6 +44,7 @@ impl Param {
key: -1,
imgs: vec![vec![]],
seq_id: 0,
seq_names,
dst_size: 900,
r: 150,
g: 0,
@ -50,7 +52,7 @@ impl Param {
nb_all: 120,
nb_visible: 40,
nb_liss: 10,
nb_wait: 30,
nb_wait: 3,
tresh: Treshold::new("histogram", 160, 255)?,
canny_v1: 170,
canny_v2: 255,
@ -80,11 +82,11 @@ impl Param {
);
create_dir(&new_dir).unwrap_or(());
for (i, img_seq) in self.imgs.iter().enumerate() {
let seq_dir_name = format!("{new_dir}/{i}");
let seq_dir_name = format!("{new_dir}/seq_{i}_{}", self.seq_names[i]);
create_dir(&seq_dir_name).unwrap_or(());
for img in img_seq {
for (id, img) in img_seq.iter().enumerate() {
let mut name_img = format!("{seq_dir_name}/");
name_img.push_str(&format!("img_{i}.png"));
name_img.push_str(&format!("img_{id}.png"));
imwrite(&name_img, img, &Vector::from_slice(&[6, 6, 6, 0]))?;
}
}
@ -100,11 +102,16 @@ impl Param {
let dir = entry?;
let path = dir.path(); // sequence directory
let names: Vec<&str> = path.to_str().unwrap().split("/").collect();
let seq_id: usize = names[names.len() - 1].parse()?;
let parts: Vec<&str> = names[names.len() - 1].split("_").collect();
let nbr = parts[1];
//println!("\t\t=> '{}'", names[names.len() - 1]);
let seq_id: usize = parts[1].parse()?;
for entry in read_dir(&path)? {
let sub_path = entry?.path();
let names: Vec<&str> = path.to_str().unwrap().split("/").collect();
let names: Vec<&str> = sub_path.to_str().unwrap().split("/").collect();
let img_name = names[names.len() - 1];
//println!("all_names: {:?}", &names);
//println!("img_name: {}", img_name);
let img_id: usize = img_name[4..img_name.len() - 4].parse()?;
let img: Mat = imread(
&find_file(&sub_path.to_str().unwrap(), false, false)?,

View File

@ -18,6 +18,8 @@ pub trait Sequence {
fn draw(&self, mem: &Param) -> Option<Vec<Point>>;
fn compute_sequence(&mut self, mem: &mut Param) -> Result<(), Box<dyn std::error::Error>>;
fn is_capture(&self) -> bool;
fn sequence_name(&self) -> String;
fn wait_milis(&self) -> u64;
}
impl std::fmt::Debug for dyn Sequence {

View File

@ -7,14 +7,15 @@ use crate::qualibration::{
use crate::qualibration::annalyse::image_diff;
use crate::qualibration::borders::{
bord_mult, get_extermities, get_intersection, probabilistic_hough,
bord_mult, get_extermities, get_intersection, probabilistic_hough, mix_borders,
};
use opencv::{
calib3d,
core::{Mat, Point as OcvPoint, Size, VecN, Vector},
imgproc::{canny, cvt_color, COLOR_BGR2GRAY},
core::{Mat, Point as OcvPoint, Size, VecN, Vector, Scalar, BORDER_CONSTANT},
imgproc::{self, canny, cvt_color, COLOR_BGR2GRAY, line},
Result,
highgui,
};
opencv::opencv_branch_4! {
@ -30,10 +31,11 @@ pub struct InitBorder {
finished: bool,
cnt: usize,
borders: [Point; 4],
nb_millis: u64,
}
impl InitBorder {
pub fn new(beg: Point, end: Point) -> Self {
pub fn new(beg: Point, end: Point, nb_millis: u64) -> Self {
InitBorder {
borders: [
Point {
@ -57,6 +59,7 @@ impl InitBorder {
color: end.color,
},
],
nb_millis,
cnt: 0,
finished: false,
}
@ -67,7 +70,7 @@ impl Sequence for InitBorder {
//type Obj = Self;
fn draw(&self, mem: &Param) -> Option<Vec<Point>> {
if self.cnt > self.borders.len() {
if self.cnt > self.borders.len() || self.finished {
return None;
}
if self.cnt == self.borders.len() {
@ -126,19 +129,19 @@ impl Sequence for InitBorder {
let border_pt = get_intersection(&bords_pts);
mem.border_pt = bord_mult(border_pt, 1.1);
//// on dessine le cadre
//let color: VecN<f64, 4> = VecN::new(255., 128., 0., 255.);
//let mut mixed = mix_borders(&background, borders)?;
//let b = &mem.border_pt;
//for i in 0..b.len() {
// let j = (i + 1) % mem.border_pt.len();
// let pa = VecN::from_array([b[i].0 as i32, b[i].1 as i32]);
// let pb = VecN::from_array([b[j].0 as i32, b[j].1 as i32]);
// let a = OcvPoint::from_vec2(pa);
// let b = OcvPoint::from_vec2(pb);
// line(&mut mixed, a, b, color, 1, LINE_AA, 0)?;
//}
//highgui::imshow("mixed bored", &mixed)?;
// on dessine le cadre
let color: VecN<f64, 4> = VecN::new(255., 128., 0., 255.);
let mut mixed = mix_borders(&background, borders)?;
let b = &mem.border_pt;
for i in 0..b.len() {
let j = (i + 1) % mem.border_pt.len();
let pa = VecN::from_array([b[i].0 as i32, b[i].1 as i32]);
let pb = VecN::from_array([b[j].0 as i32, b[j].1 as i32]);
let a = OcvPoint::from_vec2(pa);
let b = OcvPoint::from_vec2(pb);
line(&mut mixed, a, b, color, 1, LINE_AA, 0)?;
}
highgui::imshow("mixed bored", &mixed)?;
// on calcule l'homography
let size = mem.dst_size;
@ -150,7 +153,7 @@ impl Sequence for InitBorder {
.map(|(x, y)| OcvPoint::new(*x as i32, *y as i32))
.collect();
//let dst = [(0, 0), (0, size), (size, size), (size, 0)]; // in: laser repere
let dst = [(0, size), (0, 0), (size, 0), (size, size)];
let dst = [(size, size), (size, 0), (0, 0), (0, size)];
let dst_corners: Vec<OcvPoint> = dst.iter().map(|(x, y)| OcvPoint::new(*x, *y)).collect();
let roi_corners_mat = Mat::from_slice(&roi_corners[..])?;
let dst_corners_mat = Mat::from_slice(&dst_corners)?;
@ -163,17 +166,17 @@ impl Sequence for InitBorder {
)?; //get homography
mem.homography = h.clone();
mem.h_size = warped_image_size.clone();
//let mut warped_image = Mat::default();
//imgproc::warp_perspective(
// &mixed,
// &mut warped_image,
// &h,
// warped_image_size,
// imgproc::INTER_CUBIC, // I dont see difference with INTER_CUBIC
// core::BORDER_CONSTANT,
// Scalar::default(),
//)?; // do perspective transformation
//highgui::imshow("Warped Image", &warped_image)?;
let mut warped_image = Mat::default();
imgproc::warp_perspective(
&mixed,
&mut warped_image,
&h,
warped_image_size,
imgproc::INTER_CUBIC, // I dont see difference with INTER_CUBIC
BORDER_CONSTANT,
Scalar::default(),
)?; // do perspective transformation
highgui::imshow("Warped Image", &warped_image)?;
self.finished = true;
Ok(())
}
@ -181,6 +184,14 @@ impl Sequence for InitBorder {
fn is_capture(&self) -> bool {
true
}
fn sequence_name(&self) -> String {
"Init_Border".to_owned()
}
fn wait_milis(&self) -> u64 {
self.nb_millis
}
}
pub fn get_lines(

View File

@ -2,7 +2,7 @@ use crate::{
draw::draw_line_dotted,
point::Point,
qualibration::{
annalyse::{get_horizontal_segment, image_diff},
annalyse::{get_horizontal_segment, get_vertical_segment, image_diff},
compute_image::{image_treshold, image_warp},
param::Param,
Sequence,
@ -29,15 +29,17 @@ pub struct InitIdcode {
cnt: usize,
beg: Point,
end: Point,
nb_millis: u64,
}
impl InitIdcode {
pub fn new(beg: Point, end: Point) -> InitIdcode {
pub fn new(beg: Point, end: Point, nb_millis: u64) -> InitIdcode {
InitIdcode {
finished: false,
cnt: 0,
beg,
end,
nb_millis,
}
}
}
@ -99,7 +101,16 @@ impl Sequence for InitIdcode {
self.finished = true;
Ok(())
}
fn is_capture(&self) -> bool {
true
}
fn sequence_name(&self) -> String {
"init_Id-Code".to_owned()
}
fn wait_milis(&self) -> u64 {
self.nb_millis
}
}

View File

@ -1,11 +1,14 @@
use crate::point::{Color, Point};
use crate::qualibration::{
annalyse::{
draw_histograme_bgr_tresh, get_horizontal_segment, get_vertical_segment, histogram_3d,
image_diff,
use crate::{
point::{Color, Point},
qualibration::{
annalyse::{
draw_histograme_bgr_tresh, get_horizontal_segment, get_vertical_segment, histogram_3d,
image_diff,
},
compute_image::{image_treshold, image_warp},
param::Param,
Sequence,
},
param::Param,
Sequence,
};
use opencv::{
@ -20,6 +23,7 @@ opencv::opencv_branch_4! {
}
opencv::not_opencv_branch_4! {
use opencv::core::LINE_AA;
use opencv::imgproc::LINE_8;
}
#[derive(Debug, Clone)]
@ -30,10 +34,12 @@ pub struct LineDotted {
end: Point,
continuous_y: bool,
continuous_x: bool,
nb_millis: u64,
factor: usize,
}
impl LineDotted {
pub fn new(beg: Point, end: Point, continuous_y: bool, continuous_x: bool) -> Self {
pub fn new(beg: Point, end: Point, factor: usize, continuous_y: bool, continuous_x: bool, nb_millis: u64) -> Self {
Self {
finished: false,
cnt: 0,
@ -41,6 +47,8 @@ impl LineDotted {
end,
continuous_x,
continuous_y,
factor,
nb_millis,
}
}
}
@ -55,36 +63,47 @@ impl Sequence for LineDotted {
}
let nb_all = mem.nb_all;
let nb_wait = mem.nb_wait as usize;
let nb_visible = mem.nb_visible as usize;
//let nb_visible = mem.nb_visible as usize;
let len = (self.factor * mem.line_pos.len() + nb_wait) as f32;
let mut pl = vec![];
let black = Color { r: 0, g: 0, b: 0 };
let color = Color {
r: mem.r as u8,
g: mem.g as u8,
b: mem.b as u8,
};
let black = Color { r: 0, g: 0, b: 0 };
// go to firsst point
for _ in 0..nb_all {
pl.push(Point {
color: black,
..self.beg
});
}
let len = (2 * mem.line_pos.len() + nb_wait) as f32;
// go on the continus_axes in black to gain speed
for i in 0..nb_wait {
let val_x = i as f32 / len * (self.end.x - self.beg.x) + self.beg.x;
let val_y = i as f32 / len * (self.end.y - self.beg.y) + self.beg.y;
let val_x = self.end.x;//i as f32 / len * (self.end.x - self.beg.x) + self.beg.x;
let val_y = self.end.y;//i as f32 / len * (self.end.y - self.beg.y) + self.beg.y;
pl.push(Point {
x: if self.continuous_x { val_x } else { self.beg.x },
y: if self.continuous_y { val_y } else { self.beg.y },
color: black,
});
}
for i in 0..(mem.line_pos.len() * 2) {
// donne each pose lavue acording to the slide bar value and the continus axes
for i in 0..(mem.line_pos.len() * self.factor) {
let val_cont_x = (i + nb_wait) as f32 / len * (self.end.x - self.beg.x) + self.beg.x;
let val_cont_y = (i + nb_wait) as f32 / len * (self.end.y - self.beg.y) + self.beg.y;
let val_x = mem.line_pos[i / 2] as f32 + self.beg.x;
let val_y = mem.line_pos[i / 2] as f32 + self.beg.y;
let is_visible = (i + nb_wait) % 2 == 0 && i < nb_visible;
let val_x = mem.line_pos[i / self.factor] as f32 + self.beg.x;
let val_y = mem.line_pos[i / self.factor] as f32 + self.beg.y;
//let is_visible = (i + nb_wait) % 2 == 0;// && i < nb_visible;
let is_visible = match (self.cnt, i) {
(1, _) => true,
(2, i) => i & 1 == 0,
(cnt, i) => i & (1 << (cnt - 3)) != 0,
};
let c = if is_visible { color } else { black };
pl.push(Point {
x: if self.continuous_x { val_cont_x } else { val_x },
@ -97,52 +116,37 @@ impl Sequence for LineDotted {
}
fn compute_sequence(&mut self, mem: &mut Param) -> Result<(), Box<dyn std::error::Error>> {
if self.cnt < 1 {
if self.cnt <= ((self.factor * mem.line_pos.len()) as f64).log2() as usize + 2 {
self.cnt += 1;
return Ok(())
}
let ids = mem.seq_id;
let background = mem.imgs[ids][0].to_owned();
let line_dot = mem.imgs[ids][1].to_owned();
let diff = image_diff(&background, &line_dot)?;
//let len = ((self.factor * mem.line_pos.len()) as f64).log2() as usize + 1;
let mut warped_image = Mat::default();
imgproc::warp_perspective(
&diff,
&mut warped_image,
&mem.homography,
mem.h_size,
imgproc::INTER_CUBIC, // I dont see difference with INTER_CUBIC
BORDER_CONSTANT,
Scalar::default(),
)?;
//highgui::imshow("Warped Image", &warped_image)?;
//if self.cnt > ((self.factor * mem.line_pos.len()) as f64).log2() as usize + 1 {
// if mem.capture_mode {
// self.finished = true;
// } else {
// self.cnt = 0;
// }
// return Ok(())
//}
//println!("Groboulli: {}", line!());
let ids = mem.seq_id;
let img_len = mem.imgs[ids].len();
let img_id = 2;//(img_len-1).min(self.cnt);
let background = mem.imgs[ids][0].to_owned();
let line_dot = mem.imgs[ids][img_id].to_owned();
let diff = image_diff(&line_dot, &background)?;
//highgui::imshow("lone dotted", &diff)?;
let warped_image = image_warp(&diff, &mem.homography, mem.h_size)?;
let mut bord_treshed = image_treshold(&warped_image, &mem.tresh)?;
highgui::imshow("Warped and treshed Image", &bord_treshed)?;
let histo = histogram_3d(&warped_image, mem.nb_liss)?;
draw_histograme_bgr_tresh("histo bgr", &histo, &mem.tresh)?;
let (t1, s1, l1) = (
mem.tresh.min_0 as f64,
mem.tresh.min_1 as f64,
mem.tresh.min_2 as f64,
);
let (t2, s2, l2) = (
mem.tresh.max_0 as f64,
mem.tresh.max_1 as f64,
mem.tresh.max_2 as f64,
);
let min = Mat::from_slice(&[t1, s1, l1])?;
let max = Mat::from_slice(&[t2, s2, l2])?;
let mut color_selected = Mat::default();
let _ = in_range(&warped_image, &min, &max, &mut color_selected);
let mut bord_treshed = Mat::default();
bitwise_and(
&warped_image,
&warped_image,
&mut bord_treshed,
&color_selected,
)?;
//highgui::imshow(format!("warped_image & mask").as_str(), &bord_treshed)?;
let segments = if self.continuous_y {
get_vertical_segment(&bord_treshed)?
} else {
@ -158,10 +162,18 @@ impl Sequence for LineDotted {
line(&mut bord_treshed, a, b, color, 1, LINE_8, 0)?;
}
highgui::imshow("segemnt detector", &bord_treshed)?;
self.cnt += 1;
self.finished = true;
Ok(())
}
fn is_capture(&self) -> bool {
true
}
fn sequence_name(&self) -> String {
"line_Dotted".to_owned()
}
fn wait_milis(&self) -> u64 {
self.nb_millis
}
}

View File

@ -5,11 +5,12 @@ use opencv::Result;
#[derive(Debug, Clone, Copy)]
pub struct LoadImage {
finished: bool,
nb_millis: u64,
}
impl LoadImage {
pub fn new() -> LoadImage {
LoadImage { finished: false }
LoadImage { finished: false, nb_millis: 0 }
}
}
@ -20,6 +21,7 @@ impl Sequence for LoadImage {
}
Some(vec![])
}
fn compute_sequence(&mut self, mem: &mut Param) -> Result<(), Box<dyn std::error::Error>> {
if !mem.capture_mode {
mem.load_image()?;
@ -27,7 +29,16 @@ impl Sequence for LoadImage {
self.finished = true;
Ok(())
}
fn is_capture(&self) -> bool {
false
}
fn sequence_name(&self) -> String {
"Load_Image".to_owned()
}
fn wait_milis(&self) -> u64 {
self.nb_millis
}
}

View File

@ -5,11 +5,12 @@ use opencv::Result;
#[derive(Debug, Clone, Copy)]
pub struct SaveImage {
finished: bool,
nb_millis: u64,
}
impl SaveImage {
pub fn new() -> SaveImage {
SaveImage { finished: false }
SaveImage { finished: false, nb_millis: 0}
}
}
@ -20,12 +21,22 @@ impl Sequence for SaveImage {
}
Some(vec![])
}
fn compute_sequence(&mut self, mem: &mut Param) -> Result<(), Box<dyn std::error::Error>> {
mem.save_image()?;
self.finished = true;
Ok(())
}
fn is_capture(&self) -> bool {
false
}
fn sequence_name(&self) -> String {
"Save_Image".to_owned()
}
fn wait_milis(&self) -> u64 {
self.nb_millis
}
}

View File

@ -9,16 +9,13 @@ use opencv::Result;
#[derive(Debug, Clone, Copy)]
pub struct WaitSpace {
borders: [Point; 4],
red: [Point; 2],
green: [Point; 2],
blue: [Point; 2],
mid: [Point; 2],
nb_millis: u64,
}
impl WaitSpace {
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;
pub fn new(beg: Point, end: Point, nb_millis: u64) -> Self {
let mid = (end.y - beg.y) * 0.5 + beg.y;
Self {
borders: [
Point {
@ -42,42 +39,19 @@ impl WaitSpace {
color: end.color,
},
],
red: [
mid: [
Point {
x: beg.x,
y: red_y,
y: mid,
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,
y: mid,
color: end.color,
},
],
nb_millis,
}
}
}
@ -94,21 +68,6 @@ impl Sequence for WaitSpace {
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 {
@ -126,44 +85,18 @@ impl Sequence for WaitSpace {
mem.nb_visible as usize,
));
pl.extend(draw_line_dotted(
&Point{
color: blue,
..self.blue[0]
&Point {
color,
..self.mid[0]
},
&Point{
color: blue,
..self.blue[1]
&Point {
color,
..self.mid[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)
}
@ -173,4 +106,12 @@ impl Sequence for WaitSpace {
fn is_capture(&self) -> bool {
false
}
fn sequence_name(&self) -> String {
"Wait_Space".to_owned()
}
fn wait_milis(&self) -> u64 {
self.nb_millis
}
}