heuristic learned tracks

This commit is contained in:
Scott Pruett 2022-06-01 00:28:14 -04:00
parent b69a7dddb6
commit 8d237fef68
5 changed files with 24 additions and 6 deletions

View File

@ -1,9 +1,13 @@
{
"learned_images": {},
"learned_tracks": {
"//8/5J/Ez8MfyX/g/8w/25/C3+nfzx/GH8D/+/////8=": "Tilksport GP",
"////5//Hf8I/4p/gz+DP99/zn4eflx+QP8D///////8=": "Whistle Valley",
"////5//Hf+I/4p/gz+DP99/zn4efnx+CP8D///////8=": "Whistle Valley",
"////z//Af55/zj/jn/Hf/c/Bz48Pgw/A//////////8=": "Sugar Hill",
"////5//Hf+I/4p/gz+DP99/zn4eflx+EP8D///////8=": "Whistle Valley",
"//8//z//H/gfwB/ET9DP04/MH+D/4f////////////8=": "Maple Ridge"
"////z//Af55/zj/jn/Hf/c/Bz48Pgw/A//////////8=": "Sugar Hill",
"//8//p/8z/0f/X/i/8w/25/C3+nPzx/EH8j///////8=": "Tilksport Club",
"//8//z//H/gfwB/ET9DP04/MH+D/4f////////////8=": "Maple Ridge",
"//8/+B/yT/RPxR/J/9Ofxw/mz8DP2x/BH8D///////8=": "Thunder Point"
}
}

View File

@ -75,3 +75,9 @@
2022-06-01-03:56 (Sugar Hill),Sugar Hill,GP,2,23.252,23.252,86,83,87,
2022-06-01-03:58 (Maple Ridge),Maple Ridge,GP,1,27.517,27.517,100,89,90,
2022-06-01-03:58 (Maple Ridge),Maple Ridge,GP,2,27.885,27.517,,78,79,
2022-06-01-04:18 (Whistle Valley),Whistle Valley,GP,1,23.457,23.457,96,,92,
2022-06-01-04:18 (Whistle Valley),Whistle Valley,GP,2,23.769,23.457,91,84,85,
2022-06-01-04:19 (Tilksport GP),Tilksport GP,GP,1,37.578,36.127,99,85,86,
2022-06-01-04:19 (Tilksport GP),Tilksport GP,GP,2,36.127,36.127,99,71,73,
2022-06-01-04:21 (Tilksport Club),Tilksport Club,GP,1,32.790,32.790,96,88,91,
2022-06-01-04:23 (Thunder Point),Thunder Point,GP,1,36.683,36.683,97,83,89,

1 2022-05-22-20:39,whistle valley,gp,1,22.349,22.349,100,,
75 2022-06-01-03:56 (Sugar Hill),Sugar Hill,GP,2,23.252,23.252,86,83,87,
76 2022-06-01-03:58 (Maple Ridge),Maple Ridge,GP,1,27.517,27.517,100,89,90,
77 2022-06-01-03:58 (Maple Ridge),Maple Ridge,GP,2,27.885,27.517,,78,79,
78 2022-06-01-04:18 (Whistle Valley),Whistle Valley,GP,1,23.457,23.457,96,,92,
79 2022-06-01-04:18 (Whistle Valley),Whistle Valley,GP,2,23.769,23.457,91,84,85,
80 2022-06-01-04:19 (Tilksport GP),Tilksport GP,GP,1,37.578,36.127,99,85,86,
81 2022-06-01-04:19 (Tilksport GP),Tilksport GP,GP,2,36.127,36.127,99,71,73,
82 2022-06-01-04:21 (Tilksport Club),Tilksport Club,GP,1,32.790,32.790,96,88,91,
83 2022-06-01-04:23 (Thunder Point),Thunder Point,GP,1,36.683,36.683,97,83,89,

View File

@ -7,6 +7,7 @@ use std::{
use anyhow::Result;
use egui_extras::RetainedImage;
use image::RgbImage;
use img_hash::ImageHash;
use scrap::{Capturer, Display};
use crate::{
@ -70,6 +71,13 @@ fn get_track_hash(config: &Config, image: &RgbImage) -> Option<String> {
fn get_track_name(learned: &LearnedConfig, hash: &Option<String>) -> Option<String> {
let hash = hash.as_ref()?;
for (learned_hash_b64, learned_track) in &learned.learned_tracks {
let learned_hash: ImageHash<Vec<u8>> = img_hash::ImageHash::from_base64(learned_hash_b64).ok()?;
let current_hash: ImageHash<Vec<u8>> = img_hash::ImageHash::from_base64(hash).ok()?;
if current_hash.dist(&learned_hash) <= 7 {
return Some(learned_track.to_owned())
}
}
learned.learned_tracks.get(hash).cloned()
}
@ -90,7 +98,7 @@ fn handle_new_frame(state: &mut AppState, frame: LapState, image: RgbImage) {
.expect("failed to save screenshot"),
),
race_time: Some(SystemTime::now()),
track_hash: track_hash.clone(),
track_hash,
track: track_name.unwrap_or_default(),
..Default::default()
};

View File

@ -1,4 +1,4 @@
use image::{codecs::png::{PngEncoder, PngDecoder}, ColorType, ImageEncoder, Rgb, RgbImage, DynamicImage};
use image::{codecs::png::{PngEncoder}, ColorType, ImageEncoder, Rgb, RgbImage};
use serde::{Deserialize, Serialize};

View File

@ -386,14 +386,14 @@ impl eframe::App for AppUi {
let learned = state.learned.clone();
let ocr_cache = state.ocr_cache.clone();
if let Some(race) = &mut state.current_race {
ui.heading("Current Race");
ui.heading(&format!("Current Race: {}", race.name()));
show_race_state(
ui,
&mut self.ui_state,
"current",
race,
config.clone(),
learned.clone(),
learned,
ocr_cache.clone(),
);
}