From 3f51e731b18d9b4d494b0ff7f181714b08b7b1d4 Mon Sep 17 00:00:00 2001 From: Scott Pruett Date: Wed, 8 Jun 2022 22:35:10 -0400 Subject: [PATCH] minor fixes --- config.json | 8 ++++++-- race_stats.csv | 33 +++++++++++++++++++++++++++++++++ src/analysis.rs | 2 +- src/ocr.rs | 9 +++++---- src/ocr_db.rs | 7 ++++++- src/test_data/test-pos-2.png | Bin 0 -> 942 bytes suggestions.md | 4 +++- 7 files changed, 54 insertions(+), 9 deletions(-) create mode 100644 src/test_data/test-pos-2.png diff --git a/config.json b/config.json index 47cb404..4123b48 100644 --- a/config.json +++ b/config.json @@ -91,6 +91,10 @@ "track_recognition_threshold": 10, "dump_frame_fraction": null, "light_mode": false, - "font_scale": 1.2, - "tts": {} + "font_scale": 1.3, + "tts": { + "pre_race": true, + "first_lap_summary": true, + "every_lap_summary": false + } } \ No newline at end of file diff --git a/race_stats.csv b/race_stats.csv index 969f133..0042180 100644 --- a/race_stats.csv +++ b/race_stats.csv @@ -179,3 +179,36 @@ 2022-06-03-00:30 (Magdalena Club),Magdalena Club,60s GP,12,20.942,20.296,100,39,61, 2022-06-03-00:30 (Magdalena Club),Magdalena Club,60s GP,13,20.576,20.296,100,30,52, 2022-06-04-02:10,,,3,25.000,25.000,75,75,75, +2022-06-08-21:54 (Thunder Point),Thunder Point,GT,1,40.652,39.191,100,84,86,lemons +2022-06-08-21:54 (Thunder Point),Thunder Point,GT,2,40.818,39.191,100,68,72,lemons +2022-06-08-21:54 (Thunder Point),Thunder Point,GT,3,40.994,39.191,100,53,57,lemons +2022-06-08-21:54 (Thunder Point),Thunder Point,GT,4,41.794,39.191,100,38,41,lemons +2022-06-08-21:54 (Thunder Point),Thunder Point,GT,5,41.051,39.191,100,23,24,lemons +2022-06-08-21:54 (Thunder Point),Thunder Point,GT,6,45.019,39.191,92,8,7,lemons +2022-06-08-21:54 (Thunder Point),Thunder Point,GT,7,51.638,39.191,100,85,87,lemons +2022-06-08-21:54 (Thunder Point),Thunder Point,GT,8,39.737,39.191,100,69,73,lemons +2022-06-08-21:54 (Thunder Point),Thunder Point,GT,9,40.078,39.191,100,54,57,lemons +2022-06-08-21:54 (Thunder Point),Thunder Point,GT,10,41.059,39.191,100,39,42,lemons +2022-06-08-21:54 (Thunder Point),Thunder Point,GT,11,40.371,39.191,100,24,25,lemons +2022-06-08-21:54 (Thunder Point),Thunder Point,GT,12,44.996,39.191,100,10,6,lemons +2022-06-08-21:54 (Thunder Point),Thunder Point,GT,13,50.701,39.191,100,85,87,lemons +2022-06-08-21:54 (Thunder Point),Thunder Point,GT,14,40.009,39.191,100,70,74,lemons +2022-06-08-21:54 (Thunder Point),Thunder Point,GT,15,39.801,39.191,100,54,59,lemons +2022-06-08-21:54 (Thunder Point),Thunder Point,GT,16,39.700,39.191,100,39,43,lemons +2022-06-08-21:54 (Thunder Point),Thunder Point,GT,17,40.301,39.191,100,24,26,lemons +2022-06-08-21:54 (Thunder Point),Thunder Point,GT,18,41.423,39.191,100,8,8,lemons +2022-06-08-21:54 (Thunder Point),Thunder Point,GT,19,67.145,39.191,100,85,88,lemons +2022-06-08-21:54 (Thunder Point),Thunder Point,GT,20,39.191,39.191,100,70,74,lemons +2022-06-08-21:54 (Thunder Point),Thunder Point,GT,21,39.892,39.191,100,55,59,lemons +2022-06-08-21:54 (Thunder Point),Thunder Point,GT,22,40.615,39.191,100,39,43,lemons +2022-06-08-21:54 (Thunder Point),Thunder Point,GT,23,40.599,39.191,100,24,26,lemons +2022-06-08-21:54 (Thunder Point),Thunder Point,GT,24,44.018,39.191,100,10,7,lemons +2022-06-08-21:54 (Thunder Point),Thunder Point,GT,25,50.979,39.191,100,84,87,lemons +2022-06-08-21:54 (Thunder Point),Thunder Point,GT,26,39.414,39.191,100,69,73,lemons +2022-06-08-21:54 (Thunder Point),Thunder Point,GT,27,40.233,39.191,100,39,42,lemons +2022-06-08-21:54 (Thunder Point),Thunder Point,GT,28,44.599,39.191,92,25,26,lemons +2022-06-08-21:54 (Thunder Point),Thunder Point,GT,29,49.873,39.191,100,84,87,lemons +2022-06-08-21:54 (Thunder Point),Thunder Point,GT,30,39.518,39.191,100,68,73,lemons +2022-06-08-21:54 (Thunder Point),Thunder Point,GT,31,40.392,39.191,100,53,57,lemons +2022-06-08-21:54 (Thunder Point),Thunder Point,GT,32,40.085,39.191,100,37,40,lemons +2022-06-08-21:54 (Thunder Point),Thunder Point,GT,33,40.355,39.191,100,22,23,lemons diff --git a/src/analysis.rs b/src/analysis.rs index d7d14e1..0797060 100644 --- a/src/analysis.rs +++ b/src/analysis.rs @@ -55,7 +55,7 @@ fn is_finished_lap(state: &AppState, frame: &LapState) -> bool { } } if let Some(prev_frame) = state.buffered_frames.back() { - prev_frame.lap_time.is_some() && (prev_frame.lap_time == frame.lap_time || prev_frame.lap.unwrap_or(usize::MAX - 1) + 1 == frame.lap.unwrap_or_default()) + prev_frame.lap_time.is_some() && prev_frame.lap_time == frame.lap_time } else { false } diff --git a/src/ocr.rs b/src/ocr.rs index ade8037..36d411f 100644 --- a/src/ocr.rs +++ b/src/ocr.rs @@ -16,8 +16,8 @@ fn is_dark_pixel(image: &RgbImage, x: u32, y: u32) -> bool { r < 100 && g < 100 && b < 100 } -fn column_has_any_dark(image: &RgbImage, x: u32) -> bool { - for y in 0..image.height() { +fn column_has_any_dark(image: &RgbImage, x: u32, start_y: u32) -> bool { + for y in start_y..image.height() { if is_dark_pixel(image, x, y) { return true; } @@ -60,10 +60,11 @@ fn get_character_bounding_boxes(image: &RgbImage) -> Vec { let mut boxes = Vec::new(); let (cutoff_x, cutoff_y) = find_vertical_cutoff_from_right(image).unwrap_or_default(); while x < image.width() { - take_while(&mut x, image.width(), |x| !column_has_any_dark(image, x)); + let start_y = if x > cutoff_x { cutoff_y } else { 0 }; + take_while(&mut x, image.width(), |x| !column_has_any_dark(image, x, start_y)); let start_x = x; - take_while(&mut x, image.width(), |x| column_has_any_dark(image, x)); + take_while(&mut x, image.width(), |x| column_has_any_dark(image, x, start_y)); let width = x - start_x; if width >= 1 { diff --git a/src/ocr_db.rs b/src/ocr_db.rs index b8d8f5f..1f29492 100644 --- a/src/ocr_db.rs +++ b/src/ocr_db.rs @@ -99,7 +99,7 @@ impl OcrDatabase { .filter_map(|hash| self.ocr_char(hash)) .collect(); buffer - .trim_end_matches(|c: char| !c.is_alphanumeric()) + .trim_matches(|c: char| !c.is_alphanumeric()) .to_owned() } @@ -143,5 +143,10 @@ mod test { .unwrap() .to_rgb8(); assert_eq!(db.ocr_image(&image), "10/12"); + + let image = image::load_from_memory(include_bytes!("test_data/test-pos-2.png")) + .unwrap() + .to_rgb8(); + assert_eq!(db.ocr_image(&image), "1/2"); } } diff --git a/src/test_data/test-pos-2.png b/src/test_data/test-pos-2.png new file mode 100644 index 0000000000000000000000000000000000000000..b5091e65d612c1cc322e8d65623774ba51c4a22d GIT binary patch literal 942 zcmeAS@N?(olHy`uVBq!ia0y~yVB`m~BRH6VWXi^;lYkUsage(c!@6@aFM%AEbVpxD z28NCO+M1MG6B0v$Lm*V@O5Z+bhv!a|{Gr1JBoA;&WTR zw}mmVY18G7&HFE{Vm~=4&(2Qu=nOH|>7oVX}&&a{5DSxamVFMBF| z_fqP1e{TD2Q`$K9FU@xIJH6zK&kx;LfnWPAxvM9$l(XGdTe|syM%zqDcd5YFWjp`d zyzv#fQ+XpyO6||Q!jdiZcQ@NzG;lhv0aSgY-0apZZ@$%kJkMX)_5M?s&_;95n&)xR zDb9RDcf<= zo@=$!!zXp@^;EK!wr$_M_3X3C@=x|&@7I*xd}^walt1a)xgcGOs9VAy)FC0_gSUNYpefOb*{WI`^lqo zKPvWoj?Ukox3F~O)2SdMUt2dnR^M0jQGeO@E4!|&KR%;tujjh=Jvkj;*36Z-_}jX2 z~%`)ycM+AL^E_{ML-mnRhaFZbpg}be7KkYoe{rCjdy}r zSh&WQ~Zm(1$2R*wc#G8$XR!-b>FNFcyaIvSL(~BFEbN!xMeS$4#<3H z(z8*w#AB-T^46uIT!v@X1WXH)n;nfEte za?0jcTbg+3P^R$Oxf0XzW{F)3)iAkut26OsNz^}mxuRAlu*5MB?&a<;-W}Oca(v5& zE^U#%3wMD^0y8J-?YbGPEHBD+>Af*9EwA^5C22&+;R#d}sWZ=?+b>p^