qualia_vision/
kitti_taxonomy.rs1use crate::semantic::q_hash;
7
8pub const KITTI_8_CLASSES: &[(&str, u32)] = &[
10 ("Car", 0),
11 ("Van", 1),
12 ("Truck", 2),
13 ("Pedestrian", 3),
14 ("Person_sitting", 4),
15 ("Cyclist", 5),
16 ("Tram", 6),
17 ("Misc", 7),
18];
19
20pub fn lookup_kitti_class_by_id(id: u32) -> Option<&'static str> {
22 KITTI_8_CLASSES
23 .iter()
24 .find(|(_, idx)| *idx == id)
25 .map(|(name, _)| *name)
26}
27
28pub fn lookup_kitti_class_by_hash(class_hash: u64) -> Option<&'static str> {
30 KITTI_8_CLASSES
31 .iter()
32 .find(|(name, _)| q_hash(name) == class_hash)
33 .map(|(name, _)| *name)
34}
35
36pub fn q_hash_kitti_class(display_name: &str) -> u64 {
38 q_hash(display_name)
39}
40
41pub fn kitti_category_count() -> usize {
43 KITTI_8_CLASSES.len()
44}
45
46#[cfg(test)]
47mod tests {
48 use super::*;
49
50 #[test]
51 fn test_kitti_taxonomy_lookups() {
52 assert_eq!(lookup_kitti_class_by_id(0), Some("Car"));
53 assert_eq!(lookup_kitti_class_by_id(3), Some("Pedestrian"));
54 assert_eq!(lookup_kitti_class_by_id(5), Some("Cyclist"));
55
56 let car_hash = q_hash("Car");
57 assert_eq!(lookup_kitti_class_by_hash(car_hash), Some("Car"));
58
59 assert_eq!(kitti_category_count(), 8);
60 }
61}