Skip to content

Commit 5970f20

Browse files
authored
allow use of jpg images (#11)
Sounds reasonable. Thanks again.
1 parent 24d7ac1 commit 5970f20

File tree

1 file changed

+23
-11
lines changed

1 file changed

+23
-11
lines changed

src/data_loader.rs

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,17 @@ fn image_to_option_feature_frame(
6060
}
6161
}
6262

63+
fn img_filter(rp: glob::GlobResult) -> Option<std::path::PathBuf> {
64+
if let Ok(p) = rp {
65+
for ext in &[".png", ".jpg"] {
66+
if p.as_os_str().to_string_lossy().ends_with(ext) {
67+
return Some(p);
68+
}
69+
}
70+
}
71+
None
72+
}
73+
6374
pub fn load_euroc(
6475
root_folder: &str,
6576
tag_detector: &TagDetector,
@@ -72,18 +83,18 @@ pub fn load_euroc(
7283
(0..cam_num)
7384
.map(|cam_idx| {
7485
log::trace!("loading cam{}", cam_idx);
75-
let img_paths =
76-
glob(format!("{}/mav0/cam{}/data/*.png", root_folder, cam_idx).as_str())
77-
.expect("failed");
78-
let mut sorted_path: Vec<_> = img_paths.collect();
79-
sorted_path.sort_by(|a, b| a.as_ref().unwrap().cmp(b.as_ref().unwrap()));
86+
let img_paths = glob(format!("{}/mav0/cam{}/data/*", root_folder, cam_idx).as_str())
87+
.expect("failed");
88+
let mut sorted_path: Vec<std::path::PathBuf> =
89+
img_paths.into_iter().filter_map(img_filter).collect();
90+
91+
sorted_path.sort_by(|a, b| a.cmp(b));
8092
let new_paths: Vec<_> = sorted_path.iter().skip(start_idx).step_by(step).collect();
8193
let mut time_frame: Vec<_> = new_paths
8294
.iter()
8395
.par_bridge()
8496
.progress_count(new_paths.len() as u64)
8597
.map(|path| {
86-
let path = path.as_ref().unwrap();
8798
let time_ns = path_to_timestamp(path);
8899
let img = ImageReader::open(path).unwrap().decode().unwrap();
89100
if let Some(recording) = recording_option {
@@ -120,11 +131,13 @@ pub fn load_others(
120131
) -> Vec<Vec<Option<FrameFeature>>> {
121132
(0..cam_num)
122133
.map(|cam_idx| {
123-
let img_paths = glob(format!("{}/**/cam{}/**/*.png", root_folder, cam_idx).as_str())
124-
.expect("failed");
134+
let img_paths =
135+
glob(format!("{}/**/cam{}/**/*", root_folder, cam_idx).as_str()).expect("failed");
125136
log::trace!("loading cam{}", cam_idx);
126-
let mut sorted_path: Vec<_> = img_paths.collect();
127-
sorted_path.sort_by(|a, b| a.as_ref().unwrap().cmp(b.as_ref().unwrap()));
137+
let mut sorted_path: Vec<std::path::PathBuf> =
138+
img_paths.into_iter().filter_map(img_filter).collect();
139+
140+
sorted_path.sort_by(|a, b| a.cmp(b));
128141
let new_paths: Vec<_> = sorted_path
129142
.iter()
130143
.skip(start_idx)
@@ -136,7 +149,6 @@ pub fn load_others(
136149
.par_bridge()
137150
.progress_count(new_paths.len() as u64)
138151
.map(|(idx, path)| {
139-
let path = path.as_ref().unwrap();
140152
let time_ns = *idx as i64 * 100000000;
141153
let img = ImageReader::open(path).unwrap().decode().unwrap();
142154
if let Some(recording) = recording_option {

0 commit comments

Comments
 (0)