feat: during IdCode implementation
The purpose is to include a en coded number in the image to be sure it's the right image.
This commit is contained in:
parent
6145b585f4
commit
910e340ec8
5 changed files with 607 additions and 285 deletions
43
src/qualibration/compute_image.rs
Normal file
43
src/qualibration/compute_image.rs
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
use super::Treshold;
|
||||
use opencv::core::{self, bitwise_and, in_range, Mat, Scalar, Size_};
|
||||
use opencv::imgproc;
|
||||
use opencv::Result;
|
||||
|
||||
pub fn image_warp(img: &Mat, homography: &Mat, h_size: Size_<i32>) -> Result<Mat> {
|
||||
let mut warped_image = Mat::default();
|
||||
imgproc::warp_perspective(
|
||||
&img,
|
||||
&mut warped_image,
|
||||
homography,
|
||||
h_size,
|
||||
imgproc::INTER_CUBIC, // I dont see difference with INTER_CUBIC
|
||||
core::BORDER_CONSTANT,
|
||||
Scalar::default(),
|
||||
)?;
|
||||
|
||||
Ok(warped_image)
|
||||
}
|
||||
|
||||
pub fn image_treshold(img: &Mat, tresh: &Treshold) -> Result<Mat> {
|
||||
let (t1, s1, l1) = (tresh.min_0 as f64, tresh.min_1 as f64, tresh.min_2 as f64);
|
||||
let (t2, s2, l2) = (tresh.max_0 as f64, tresh.max_1 as f64, 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(img, &min, &max, &mut color_selected);
|
||||
let mut bord_treshed = Mat::default();
|
||||
bitwise_and(&img, &img, &mut bord_treshed, &color_selected)?;
|
||||
|
||||
Ok(bord_treshed)
|
||||
}
|
||||
|
||||
pub fn image_warp_treshold(
|
||||
img: &Mat,
|
||||
homography: &Mat,
|
||||
h_size: Size_<i32>,
|
||||
tresh: &Treshold,
|
||||
) -> Result<Mat> {
|
||||
let warped = image_warp(img, homography, h_size)?;
|
||||
let treshed = image_treshold(&warped, tresh)?;
|
||||
Ok(treshed)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue