Skip to content

Commit

Permalink
Sharpen filter
Browse files Browse the repository at this point in the history
  • Loading branch information
naps62 committed Aug 9, 2020
1 parent e8c8d85 commit d4dd044
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 0 deletions.
1 change: 1 addition & 0 deletions daemon/src/app/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ pub enum Proc {
Pixelate { k: i32 },
Sepia,
Edges { t1: f64, t2: f64 },
Sharpen,
}

impl Settings {
Expand Down
1 change: 1 addition & 0 deletions daemon/src/filters/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ pub mod blur;
pub mod edges;
pub mod pixelate;
pub mod sepia;
pub mod sharpen;
mod utils;

use crate::types::Frame;
Expand Down
43 changes: 43 additions & 0 deletions daemon/src/filters/sharpen.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
use opencv::core::{BorderTypes, Mat, Point};
use opencv::imgproc;

use super::{utils, Filter};

use crate::types::Frame;

#[derive(Clone, Debug)]
pub struct Sharpen {
kernel: Mat,
out: Frame,
}

pub fn new(out: Frame) -> Sharpen {
let kernel =
Mat::from_slice_2d(&vec![vec![-1, -1, -1], vec![-1, 9, -1], vec![-1, -1, -1]]).unwrap();

Sharpen { kernel, out }
}

impl Filter for Sharpen {
fn run(&mut self, src_frame: Frame) -> Frame {
let src = utils::frame_to_mat(src_frame);
let mut dst = utils::frame_to_mat(self.out);

imgproc::filter_2d(
&src,
&mut dst,
-1,
&self.kernel,
Point::new(-1, -1),
0.0,
BorderTypes::BORDER_REPLICATE as i32,
)
.unwrap();

self.out
}

fn output(&self) -> Frame {
self.out
}
}
1 change: 1 addition & 0 deletions daemon/src/pipeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ pub fn alloc_filters(args: &Args, settings: &Settings) -> Vec<Box<dyn Filter>> {
Pixelate { k } => Box::new(pixelate::new(*k, frame)),
Sepia => Box::new(sepia::new(frame)),
Edges { t1, t2 } => Box::new(edges::new(*t1, *t2, frame)),
Sharpen => Box::new(sharpen::new(frame)),
}
})
.collect()
Expand Down

0 comments on commit d4dd044

Please sign in to comment.