viuer terminal images
This commit is contained in:
+10
-1
@@ -3,6 +3,7 @@ use image_similarity::descriptors::{DCT, Descriptor};
|
||||
use image_similarity::store::DescriptorStore;
|
||||
use std::env;
|
||||
use log::{info, debug, error};
|
||||
use viuer::{Config, print};
|
||||
|
||||
struct Cfg {
|
||||
path: String
|
||||
@@ -31,6 +32,14 @@ fn main() {
|
||||
|
||||
let img = image::open(cfg.path)
|
||||
.expect("Unable to open file");
|
||||
println!("Iamge");
|
||||
let conf = viuer::Config {
|
||||
width: Some(16),
|
||||
height: Some(8),
|
||||
..Default::default()
|
||||
};
|
||||
viuer::print(&img, &conf).expect("Image printing failed.");
|
||||
println!("Iamge");
|
||||
let store =
|
||||
DescriptorStore::new()
|
||||
.with_file("store.messagepack");
|
||||
@@ -38,5 +47,5 @@ fn main() {
|
||||
let phash: u64 = desc.describe(&img);
|
||||
info!("Phash integer:\n{phash}");
|
||||
info!("Phash binary:\n{phash:064b}");
|
||||
store.knn(phash, 4);
|
||||
store.knn(phash, 10);
|
||||
}
|
||||
+23
-1
@@ -8,6 +8,7 @@ use std::path::Path;
|
||||
use std::fmt;
|
||||
use log::{info, debug, error};
|
||||
use bktree::*;
|
||||
use viuer::{Config, print};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum SaveError {
|
||||
@@ -102,10 +103,31 @@ impl DescriptorStore {
|
||||
/// K-nearest neighbors
|
||||
pub fn knn(&self, from: u64, k: isize) {
|
||||
println!("{from:b}");
|
||||
let mut x = 0;
|
||||
let mut y = 8;
|
||||
let (term_width, _) = viuer::terminal_size();
|
||||
println!("\t\t\t\t\tTERMWIDTH {term_width}");
|
||||
for (element, distance) in self.bktree.find(from, k) {
|
||||
let name = self.map.get(element);
|
||||
match name {
|
||||
Some(n) => println!("{element:b}: {n} (distance: {distance})"),
|
||||
Some(n) => {
|
||||
println!("{element:b}: {n} (distance: {distance})");
|
||||
if x+16 >= term_width {
|
||||
x = 0;
|
||||
y += 8;
|
||||
}
|
||||
let conf = viuer::Config {
|
||||
width: Some(16),
|
||||
height: Some(8),
|
||||
x: x,
|
||||
y: y,
|
||||
..Default::default()
|
||||
};
|
||||
x += 16;
|
||||
let path = "data/".to_string() + &n;
|
||||
let img = image::open(&path).unwrap();
|
||||
viuer::print(&img, &conf).expect("Image printing failed.");
|
||||
},
|
||||
None => ()
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user