1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
use thiserror::Error;
pub mod vocab;
pub use vocab::Vocabulary;
pub mod opencv_utils;
#[cfg(feature = "opencv")]
pub use opencv_utils::*;
pub type Desc = [u8; 32];
pub type BoW = Vec<f32>;
pub type DirectIdx = Vec<Vec<usize>>;
pub trait BoWTrait {
fn l1(&self, other: &Self) -> f32;
fn l2(&self, other: &Self) -> f32;
}
impl BoWTrait for BoW {
fn l1(&self, other: &Self) -> f32 {
1. - 0.5
* (self
.iter()
.zip(other)
.fold(0., |a, (b, c)| a + (b - c).abs()))
}
fn l2(&self, _other: &Self) -> f32 {
unimplemented!()
}
}
type Result<T> = std::result::Result<T, BowErr>;
#[derive(Error, Debug)]
pub enum BowErr {
#[error("Io Error")]
Io(#[from] std::io::Error),
#[cfg(feature = "bincode")]
#[error("Vocabulary Serialization Error")]
Bincode(#[from] bincode::Error),
#[cfg(feature = "opencv")]
#[error("Opencv Error")]
OpenCvInternal(#[from] opencv::Error),
#[cfg(feature = "opencv")]
#[error("Opencv Descriptor decode error")]
OpenCvDecode,
}