1use crate::semantic::q_hash;
7
8pub const CITYSCAPES_CLASSES: &[(&str, u32, &str, bool)] = &[
10 ("unlabeled", 0, "void", false),
11 ("ego vehicle", 1, "void", false),
12 ("rectification border", 2, "void", false),
13 ("out of roi", 3, "void", false),
14 ("static", 4, "void", false),
15 ("dynamic", 5, "void", false),
16 ("ground", 6, "void", false),
17 ("road", 7, "flat", true),
18 ("sidewalk", 8, "flat", true),
19 ("parking", 9, "flat", false),
20 ("rail track", 10, "flat", false),
21 ("building", 11, "construction", true),
22 ("wall", 12, "construction", true),
23 ("fence", 13, "construction", true),
24 ("guard rail", 14, "construction", false),
25 ("bridge", 15, "construction", false),
26 ("tunnel", 16, "construction", false),
27 ("pole", 17, "object", true),
28 ("polegroup", 18, "object", false),
29 ("traffic light", 19, "object", true),
30 ("traffic sign", 20, "object", true),
31 ("vegetation", 21, "nature", true),
32 ("terrain", 22, "nature", true),
33 ("sky", 23, "sky", true),
34 ("person", 24, "human", true),
35 ("rider", 25, "human", true),
36 ("car", 26, "vehicle", true),
37 ("truck", 27, "vehicle", true),
38 ("bus", 28, "vehicle", true),
39 ("caravan", 29, "vehicle", false),
40 ("trailer", 30, "vehicle", false),
41 ("train", 31, "vehicle", true),
42 ("motorcycle", 32, "vehicle", true),
43 ("bicycle", 33, "vehicle", true),
44 ("license plate", -1i32 as u32, "vehicle", false),
45];
46
47pub fn lookup_cityscapes_class_by_id(id: u32) -> Option<(&'static str, &'static str)> {
49 CITYSCAPES_CLASSES
50 .iter()
51 .find(|(_, class_id, _, _)| *class_id == id)
52 .map(|(name, _, group, _)| (*name, *group))
53}
54
55pub fn lookup_cityscapes_class_by_hash(class_hash: u64) -> Option<&'static str> {
57 CITYSCAPES_CLASSES
58 .iter()
59 .find(|(name, _, _, _)| q_hash(name) == class_hash)
60 .map(|(name, _, _, _)| *name)
61}
62
63pub fn q_hash_cityscapes_class(display_name: &str) -> u64 {
65 q_hash(display_name)
66}
67
68pub fn cityscapes_category_count() -> usize {
70 CITYSCAPES_CLASSES.len()
71}
72
73#[cfg(test)]
74mod tests {
75 use super::*;
76
77 #[test]
78 fn test_cityscapes_taxonomy_lookups() {
79 let (road, group_r) = lookup_cityscapes_class_by_id(7).unwrap();
80 assert_eq!(road, "road");
81 assert_eq!(group_r, "flat");
82
83 let (building, group_b) = lookup_cityscapes_class_by_id(11).unwrap();
84 assert_eq!(building, "building");
85 assert_eq!(group_b, "construction");
86
87 let (car, group_c) = lookup_cityscapes_class_by_id(26).unwrap();
88 assert_eq!(car, "car");
89 assert_eq!(group_c, "vehicle");
90
91 let person_hash = q_hash("person");
92 assert_eq!(lookup_cityscapes_class_by_hash(person_hash), Some("person"));
93
94 assert_eq!(cityscapes_category_count(), 35);
95 }
96}