117 lines
3.1 KiB
Rust
117 lines
3.1 KiB
Rust
use crate::{
|
|
draw::draw_line_dotted,
|
|
point::Point,
|
|
qualibration::{
|
|
annalyse::{get_horizontal_segment, get_vertical_segment, image_diff},
|
|
compute_image::{image_treshold, image_warp},
|
|
param::Param,
|
|
Sequence,
|
|
},
|
|
};
|
|
|
|
use opencv::{
|
|
core::{Point as OcvPoint, VecN},
|
|
highgui,
|
|
imgproc::line,
|
|
Result,
|
|
};
|
|
|
|
opencv::opencv_branch_4! {
|
|
use opencv::imgproc::LINE_8;
|
|
}
|
|
opencv::not_opencv_branch_4! {
|
|
use opencv::core::LINE_AA;
|
|
}
|
|
|
|
#[derive(Debug, Clone, Copy)]
|
|
pub struct InitIdcode {
|
|
finished: bool,
|
|
cnt: usize,
|
|
beg: Point,
|
|
end: Point,
|
|
nb_millis: u64,
|
|
}
|
|
|
|
impl InitIdcode {
|
|
pub fn new(beg: Point, end: Point, nb_millis: u64) -> InitIdcode {
|
|
InitIdcode {
|
|
finished: false,
|
|
cnt: 0,
|
|
beg,
|
|
end,
|
|
nb_millis,
|
|
}
|
|
}
|
|
}
|
|
|
|
impl Sequence for InitIdcode {
|
|
fn draw(&self, mem: &Param) -> Option<Vec<Point>> {
|
|
if self.finished {
|
|
return None;
|
|
}
|
|
if self.cnt == 0 {
|
|
return Some(vec![]);
|
|
}
|
|
let mut pl = vec![];
|
|
pl.extend(draw_line_dotted(
|
|
&self.beg,
|
|
&self.end,
|
|
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>> {
|
|
if self.cnt == 0 {
|
|
self.cnt += 1;
|
|
return Ok(());
|
|
}
|
|
let id = mem.seq_id;
|
|
let mut id_code_1 = image_diff(&mem.imgs[id][1], &mem.imgs[id][0])?;
|
|
|
|
id_code_1 = image_warp(&id_code_1, &mem.homography, mem.h_size)?;
|
|
id_code_1 = image_treshold(&id_code_1, &mem.tresh)?;
|
|
|
|
let code_seg_1 = get_horizontal_segment(&id_code_1)?;
|
|
let code_seg_1 = code_seg_1[1..(code_seg_1.len() - 1)].to_owned();
|
|
|
|
// on dessine
|
|
let color_1: VecN<f64, 4> = VecN::new(255., 0., 0., 255.);
|
|
for i in 0..code_seg_1.len() {
|
|
let (((x0, y0), (x1, y1)), size) = code_seg_1[i];
|
|
//line(&mut id_code_1, );
|
|
let s = size as i32;
|
|
let x = ((x0 + x1) / 2.) as i32;
|
|
let y = ((y0 + y1) / 2.) as i32;
|
|
let a = OcvPoint::from_vec2(VecN::from_array([x, y - s]));
|
|
let b = OcvPoint::from_vec2(VecN::from_array([x, y + s]));
|
|
line(&mut id_code_1, a, b, color_1, 1, LINE_8, 0)?;
|
|
if i < (code_seg_1.len() - 1) {
|
|
let (((x2, _), _), _) = code_seg_1[i + 1];
|
|
let x = ((x1 + x2) / 2.) as i32;
|
|
let y = ((y0 + y1) / 2.) as i32;
|
|
let a = OcvPoint::from_vec2(VecN::from_array([x, y - s]));
|
|
let b = OcvPoint::from_vec2(VecN::from_array([x, y + s]));
|
|
line(&mut id_code_1, a, b, color_1, 1, LINE_8, 0)?;
|
|
}
|
|
}
|
|
|
|
highgui::imshow("code 1", &id_code_1)?;
|
|
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
|
|
}
|
|
}
|