Skip to content

Commit

Permalink
style: run cargo fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
polyesterswing committed Jul 10, 2024
1 parent 72d8a54 commit 1769480
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use opencv::prelude::*;
use opencv::{highgui, imgproc, videoio, core, Result};
use opencv::core::VecN;
use opencv::prelude::*;
use opencv::{core, highgui, imgproc, videoio, 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 All @@ -18,14 +18,19 @@ fn find_colors(frame: &Mat, gray: &Mat, table: &str, table_len: usize) -> Result

let gray_pixel = gray.at_2d::<u8>(row, col)?;
let new_pixel = map_range((0, 255), (0, (table_len - 1) as i32), *gray_pixel as i32);
out_colors.push_str(&*format!("\x1b[38;2;{};{};{}m{}", pixel[2], pixel[1], pixel[0], table.as_bytes()[new_pixel as usize] as char))
out_colors.push_str(&*format!(
"\x1b[38;2;{};{};{}m{}",
pixel[2],
pixel[1],
pixel[0],
table.as_bytes()[new_pixel as usize] as char
))
}

out_colors.push_str("\n");
}

Ok(out_colors)

}

fn main() -> Result<()> {
Expand All @@ -50,7 +55,14 @@ fn main() -> Result<()> {

if frame.size()?.width > 0 {
let mut smaller = Mat::default();
imgproc::resize(&frame, &mut smaller, core::Size::new(term_size.0.into(), term_size.1.into()), 0.0, 0.0, imgproc::INTER_AREA)?;
imgproc::resize(
&frame,
&mut smaller,
core::Size::new(term_size.0.into(), term_size.1.into()),
0.0,
0.0,
imgproc::INTER_AREA,
)?;

//let _ = find_colors(&smaller)?;
//println!("{}", find_colors(&smaller)?);
Expand All @@ -60,7 +72,10 @@ fn main() -> Result<()> {

highgui::imshow(window, &smaller)?;

println!("{}", find_colors(&smaller, &gray, ascii_table, ascii_table_len)?);
println!(
"{}",
find_colors(&smaller, &gray, ascii_table, ascii_table_len)?
);
}

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

0 comments on commit 1769480

Please sign in to comment.