store compressed lap images
This commit is contained in:
parent
a6d5af8bbd
commit
b69a7dddb6
|
@ -12,7 +12,7 @@ use scrap::{Capturer, Display};
|
|||
use crate::{
|
||||
capture,
|
||||
config::{Config, LearnedConfig},
|
||||
image_processing::{self, extract_and_filter, hash_image, Region},
|
||||
image_processing::{self, extract_and_filter, hash_image, Region, to_png_bytes},
|
||||
ocr,
|
||||
state::{AppState, DebugOcrFrame, LapState, RaceState, SharedAppState},
|
||||
};
|
||||
|
@ -111,7 +111,7 @@ fn handle_new_frame(state: &mut AppState, frame: LapState, image: RgbImage) {
|
|||
if let Some(lap) = &merged.lap {
|
||||
merged.lap = Some(lap - 1);
|
||||
}
|
||||
merged.screenshot = Some(image);
|
||||
merged.screenshot = Some(to_png_bytes(&image));
|
||||
|
||||
if let Some(race) = state.current_race.as_mut() {
|
||||
if let Some(prev_lap) = race.laps.last() {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use image::{codecs::png::PngEncoder, ColorType, ImageEncoder, Rgb, RgbImage};
|
||||
use image::{codecs::png::{PngEncoder, PngDecoder}, ColorType, ImageEncoder, Rgb, RgbImage, DynamicImage};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
|
||||
|
@ -74,6 +74,11 @@ pub fn to_png_bytes(image: &RgbImage) -> Vec<u8> {
|
|||
buffer
|
||||
}
|
||||
|
||||
pub fn from_png_bytes(bytes: &[u8]) -> RgbImage {
|
||||
let image = image::load_from_memory(bytes).expect("expected valid image");
|
||||
image.to_rgb8()
|
||||
}
|
||||
|
||||
pub fn hash_image(image: &RgbImage) -> String {
|
||||
let hasher = img_hash::HasherConfig::new().hash_alg(img_hash::HashAlg::Mean).hash_size(16, 16).to_hasher();
|
||||
let have_to_use_other_image_library_version =
|
||||
|
|
11
src/main.rs
11
src/main.rs
|
@ -24,7 +24,7 @@ use eframe::{
|
|||
epaint::Color32,
|
||||
};
|
||||
use egui_extras::RetainedImage;
|
||||
use image_processing::to_png_bytes;
|
||||
use image_processing::{to_png_bytes, from_png_bytes};
|
||||
use state::{AppState, DebugOcrFrame, LapState, OcrCache, RaceState, SharedAppState};
|
||||
use stats_writer::export_race_stats;
|
||||
|
||||
|
@ -296,12 +296,13 @@ fn open_debug_lap(
|
|||
learned: Arc<LearnedConfig>,
|
||||
ocr_cache: Arc<OcrCache>,
|
||||
) {
|
||||
if let Some(screenshot) = &lap.screenshot {
|
||||
let ocr_results = ocr::ocr_all_regions(screenshot, config.clone(), learned, ocr_cache);
|
||||
if let Some(screenshot_bytes) = &lap.screenshot {
|
||||
let screenshot = from_png_bytes(screenshot_bytes);
|
||||
let ocr_results = ocr::ocr_all_regions(&screenshot, config.clone(), learned, ocr_cache);
|
||||
let debug_lap = DebugLap {
|
||||
screenshot: RetainedImage::from_image_bytes("debug-lap", &to_png_bytes(screenshot))
|
||||
screenshot: RetainedImage::from_image_bytes("debug-lap", &to_png_bytes(&screenshot))
|
||||
.unwrap(),
|
||||
debug_regions: save_frames_from(screenshot, &*config, &ocr_results),
|
||||
debug_regions: save_frames_from(&screenshot, &*config, &ocr_results),
|
||||
};
|
||||
|
||||
ui_state.debug_lap = Some(debug_lap);
|
||||
|
|
|
@ -19,7 +19,7 @@ pub struct LapState {
|
|||
pub lap_time: Option<Duration>,
|
||||
|
||||
pub striked: bool,
|
||||
pub screenshot: Option<RgbImage>,
|
||||
pub screenshot: Option<Vec<u8>>,
|
||||
pub debug: bool,
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue