dctfilename binary in base64
This commit is contained in:
Generated
+7
@@ -14,6 +14,12 @@ version = "1.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
|
||||
|
||||
[[package]]
|
||||
name = "base64"
|
||||
version = "0.22.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6"
|
||||
|
||||
[[package]]
|
||||
name = "bit_field"
|
||||
version = "0.10.1"
|
||||
@@ -234,6 +240,7 @@ dependencies = [
|
||||
name = "image_similarity"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"base64",
|
||||
"image",
|
||||
"rmp-serde",
|
||||
"serde",
|
||||
|
||||
@@ -9,3 +9,4 @@ edition = "2021"
|
||||
image = "0.24.4"
|
||||
serde = "1.0.147"
|
||||
rmp-serde = "1.1.1"
|
||||
base64 = "0.22.1"
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
use image_similarity::descriptors::{Descriptor, DCT};
|
||||
use std::env;
|
||||
use base64::{engine::general_purpose::URL_SAFE_NO_PAD, Engine as _};
|
||||
|
||||
struct Cfg {
|
||||
path: String
|
||||
}
|
||||
|
||||
impl Cfg{
|
||||
fn load(args: &[String]) -> Result<Cfg, &'static str> {
|
||||
if args.len() < 2 {
|
||||
return Err("Filename argument required");
|
||||
}
|
||||
let path = args[1].clone();
|
||||
Ok(Cfg { path })
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
//Init all descriptors:
|
||||
let desc = DCT;
|
||||
|
||||
let args: Vec<String> = env::args().collect();
|
||||
//dbg!(args);
|
||||
|
||||
let cfg = Cfg::load(&args)
|
||||
.expect("Error loading config");
|
||||
|
||||
let img = image::open(cfg.path)
|
||||
.expect("Unable to open file");
|
||||
let phash: u64 = desc.describe(img);
|
||||
println!("{phash}\n{phash:b}");
|
||||
let output = URL_SAFE_NO_PAD.encode(phash.to_be_bytes());
|
||||
println!("{output}")
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user