111 lines
2.9 KiB
Rust
111 lines
2.9 KiB
Rust
//use opencv::Result;
|
|
//use opencv::core::{self, Mat};
|
|
|
|
static DEBUG: bool = true;
|
|
|
|
pub mod annalyse;
|
|
pub mod borders;
|
|
pub mod compute_image;
|
|
|
|
use std::env::args;
|
|
|
|
use crate::point::Point;
|
|
|
|
use opencv::core::Mat;
|
|
use opencv::Result;
|
|
//use std::f64::consts::PI;
|
|
|
|
use opencv::prelude::*;
|
|
use opencv::{
|
|
highgui,
|
|
videoio::{self, VideoCapture},
|
|
};
|
|
|
|
mod param;
|
|
use param::Param;
|
|
|
|
mod sequence;
|
|
pub use sequence::{InitBorder, LineDotted, LoadImage, SaveImage, Sequence, WaitSpace, InitIdcode};
|
|
|
|
#[derive(Debug)]
|
|
pub struct Qualibration {
|
|
seq: Vec<Box<dyn Sequence>>,
|
|
cam: VideoCapture,
|
|
|
|
pub param: Param,
|
|
}
|
|
|
|
impl Qualibration {
|
|
pub fn new() -> Result<Self> {
|
|
//let v: Vec<Box<dyn Sequence>> = vec![];
|
|
|
|
let mut dir_name = "".to_string(); //"building.jpg".to_string(); // by default
|
|
if let Some(dir_name_arg) = args().nth(1) {
|
|
dir_name = dir_name_arg;
|
|
}
|
|
|
|
let mut cam = videoio::VideoCapture::new(0, videoio::CAP_ANY)?; // 0 is the default camera ;
|
|
let opened_cam = videoio::VideoCapture::is_opened(&cam)?;
|
|
if !opened_cam {
|
|
panic!("Unable to open default camera!");
|
|
}
|
|
|
|
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));
|
|
let seq: Vec<Box<dyn Sequence>> = vec![
|
|
Box::new(LoadImage::new()),
|
|
Box::new(WaitSpace::new()),
|
|
Box::new(InitBorder::new(beg, end)),
|
|
Box::new(LineDotted::new(beg, end, true, false)),
|
|
Box::new(InitIdcode::new(beg2, end)),
|
|
Box::new(SaveImage::new()),
|
|
];
|
|
//let now = std::time::Instant::now();
|
|
Ok(Qualibration {
|
|
seq,
|
|
cam,
|
|
param: Param::new(dir_name.to_owned())?,
|
|
})
|
|
}
|
|
|
|
pub fn draw_sequence(&mut self) -> Option<Vec<Point>> {
|
|
if self.param.seq_id >= self.seq.len() {
|
|
return None;
|
|
}
|
|
|
|
let pl = self.seq[self.param.seq_id].draw(&self.param);
|
|
|
|
if pl.is_none() {
|
|
self.param.seq_id += 1;
|
|
if self.param.capture_mode {
|
|
self.param.imgs.push(vec![]);
|
|
}
|
|
}
|
|
|
|
pl
|
|
}
|
|
|
|
pub fn run_step(self: &mut Self) -> Result<(), Box<dyn std::error::Error>> {
|
|
let mut frame = Mat::default();
|
|
if self.param.capture_mode {
|
|
self.cam.read(&mut frame)?;
|
|
highgui::imshow("camera", &frame)?;
|
|
|
|
if frame.size()?.width > 0 && self.seq[self.param.seq_id].is_capture() {
|
|
self.param.imgs[self.param.seq_id].push(frame.clone());
|
|
}
|
|
}
|
|
|
|
if frame.size()?.width > 0 || !self.param.capture_mode {
|
|
self.seq[self.param.seq_id].compute_sequence(&mut self.param)?;
|
|
}
|
|
|
|
Ok(())
|
|
}
|
|
}
|