Skip to content

Commit

Permalink
feat: fit video to terminal size
Browse files Browse the repository at this point in the history
  • Loading branch information
polyesterswing committed Jul 2, 2024
1 parent 6fc6b10 commit cb0ab15
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use opencv::prelude::*;
use opencv::{highgui, imgproc, videoio, Result};
use opencv::{highgui, imgproc, videoio, core, Result};

fn map_range(from_range: (i32, i32), to_range: (i32, i32), s: i32) -> i32 {
to_range.0 + (s - from_range.0) * (to_range.1 - to_range.0) / (from_range.1 - from_range.0)
Expand Down Expand Up @@ -30,6 +30,8 @@ fn main() -> Result<()> {
" .'`^\",:;Il!i><~+_-?][}{1)(|\\/tfjrxnuvczXYUJCLQ0OZmwqpdbkhao*#MW&8%B@$";
let ascii_table_len = ascii_table.len();

let term_size = termion::terminal_size().unwrap();

let window = "Video";
highgui::named_window(window, 1)?;

Expand All @@ -46,9 +48,12 @@ fn main() -> Result<()> {
if frame.size()?.width > 0 {
let mut gray = Mat::default();
imgproc::cvt_color_def(&frame, &mut gray, imgproc::COLOR_BGR2GRAY)?;
highgui::imshow(window, &gray)?;

println!("{}", encode_frame(gray, ascii_table, ascii_table_len)?);
let mut smaller = Mat::default();
imgproc::resize(&gray, &mut smaller, core::Size::new(term_size.0.into(), term_size.1.into()), 0.0, 0.0, imgproc::INTER_AREA)?;
highgui::imshow(window, &smaller)?;

println!("{}", encode_frame(smaller, ascii_table, ascii_table_len)?);
}

if highgui::wait_key(10)? > 0 {
Expand Down

0 comments on commit cb0ab15

Please sign in to comment.