Skip to content
This repository was archived by the owner on Mar 20, 2026. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion backend/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ reqwest = { version = "0.12.20", features = ["multipart"] }
include_dir = "0.7.4"

[build-dependencies]
tonic-build = "*"
tonic-build = "0.13.1"

[dev-dependencies]
mockall = { version = "0.13.1", features = ["nightly"] }
Expand Down
17 changes: 9 additions & 8 deletions backend/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ fn main() {
let admin = resources_dir.join("admin_ideal_ratio.png");
let timer = resources_dir.join("timer_ideal_ratio.png");
let level = resources_dir.join("level_ideal_ratio.png");
let lie_detector_shape = resources_dir.join("lie_detector_shape_ideal_ratio.png");
let lie_detector_new = resources_dir.join("lie_detector_new_ideal_ratio.png");
let lie_detector_old = resources_dir.join("lie_detector_old_ideal_ratio.png");
let lie_detector_shape_prepare =
resources_dir.join("lie_detector_shape_prepare_ideal_ratio.png");
let lie_detector_violetta = resources_dir.join("lie_detector_violetta_ideal_ratio.png");
let lie_detector_violetta_face =
resources_dir.join("lie_detector_violetta_face_ideal_ratio.png");
let lie_detector_violetta_prepare =
Expand Down Expand Up @@ -159,6 +159,7 @@ fn main() {
let out_dir = dir.join("src").join("grpc");
tonic_build::configure()
.out_dir(out_dir)
.build_server(false)
.compile_protos(&[proto_file], &[proto_dir])
.unwrap();

Expand Down Expand Up @@ -261,16 +262,16 @@ fn main() {
println!("cargo:rustc-env=TIMER_TEMPLATE={}", timer.to_str().unwrap());
println!("cargo:rustc-env=LEVEL_TEMPLATE={}", level.to_str().unwrap());
println!(
"cargo:rustc-env=LIE_DETECTOR_SHAPE_TEMPLATE={}",
lie_detector_shape.to_str().unwrap()
"cargo:rustc-env=LIE_DETECTOR_NEW_TEMPLATE={}",
lie_detector_new.to_str().unwrap()
);
println!(
"cargo:rustc-env=LIE_DETECTOR_SHAPE_PREPARE_TEMPLATE={}",
lie_detector_shape_prepare.to_str().unwrap()
"cargo:rustc-env=LIE_DETECTOR_OLD_TEMPLATE={}",
lie_detector_old.to_str().unwrap()
);
println!(
"cargo:rustc-env=LIE_DETECTOR_VIOLETTA_TEMPLATE={}",
lie_detector_violetta.to_str().unwrap()
"cargo:rustc-env=LIE_DETECTOR_SHAPE_PREPARE_TEMPLATE={}",
lie_detector_shape_prepare.to_str().unwrap()
);
println!(
"cargo:rustc-env=LIE_DETECTOR_VIOLETTA_FACE_TEMPLATE={}",
Expand Down
67 changes: 47 additions & 20 deletions backend/src/detect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -511,15 +511,15 @@ impl Detector for DefaultDetector {
}

fn detect_lie_detector_shape(&self) -> Result<Rect> {
detect_lie_detector_shape(self.bgr())
detect_lie_detector_shape(self.bgr(), &self.localization)
}

fn detect_lie_detector_shape_preparing(&self) -> bool {
detect_lie_detector_shape_preparing(self.bgr()).is_ok()
}

fn detect_lie_detector_violetta(&self) -> Result<Rect> {
detect_lie_detector_violetta(self.bgr())
detect_lie_detector_violetta(self.bgr(), &self.localization)
}

fn detect_lie_detector_violetta_preparing(&self) -> bool {
Expand Down Expand Up @@ -2285,16 +2285,28 @@ fn detect_timer_visible(grayscale: &impl ToInputArray, localization: &Localizati
.is_ok()
}

fn detect_lie_detector_shape(bgr: &impl ToInputArray) -> Result<Rect> {
static TEMPLATE: LazyLock<Mat> = LazyLock::new(|| {
imgcodecs::imdecode(
include_bytes!(env!("LIE_DETECTOR_SHAPE_TEMPLATE")),
IMREAD_COLOR,
)
.unwrap()
});
pub static LIE_DETECTOR_TRANSPARENT_SHAPE_TEMPLATE: LazyLock<Mat> = LazyLock::new(|| {
imgcodecs::imdecode(
include_bytes!(env!("LIE_DETECTOR_NEW_TEMPLATE")),
IMREAD_COLOR,
)
.unwrap()
});

detect_template(bgr, &*TEMPLATE, Point::default(), 0.6)
fn detect_lie_detector_shape(bgr: &impl ToInputArray, localization: &Localization) -> Result<Rect> {
let template = localization
.lie_detector_new_base64
.as_ref()
.and_then(|base64| to_mat_from_base64(base64, false).ok());

detect_template(
bgr,
template
.as_ref()
.unwrap_or(&*LIE_DETECTOR_TRANSPARENT_SHAPE_TEMPLATE),
Point::default(),
0.6,
)
}

fn detect_lie_detector_shape_preparing(bgr: &impl ToInputArray) -> Result<Rect> {
Expand All @@ -2309,16 +2321,31 @@ fn detect_lie_detector_shape_preparing(bgr: &impl ToInputArray) -> Result<Rect>
detect_template(bgr, &*TEMPLATE, Point::default(), 0.6)
}

fn detect_lie_detector_violetta(bgr: &impl ToInputArray) -> Result<Rect> {
static TEMPLATE: LazyLock<Mat> = LazyLock::new(|| {
imgcodecs::imdecode(
include_bytes!(env!("LIE_DETECTOR_VIOLETTA_TEMPLATE")),
IMREAD_COLOR,
)
.unwrap()
});
pub static LIE_DETECTOR_VIOLETTA_TEMPLATE: LazyLock<Mat> = LazyLock::new(|| {
imgcodecs::imdecode(
include_bytes!(env!("LIE_DETECTOR_OLD_TEMPLATE")),
IMREAD_COLOR,
)
.unwrap()
});

detect_template(bgr, &*TEMPLATE, Point::default(), 0.6)
fn detect_lie_detector_violetta(
bgr: &impl ToInputArray,
localization: &Localization,
) -> Result<Rect> {
let template = localization
.lie_detector_old_base64
.as_ref()
.and_then(|base64| to_mat_from_base64(base64, false).ok());

detect_template(
bgr,
template
.as_ref()
.unwrap_or(&*LIE_DETECTOR_VIOLETTA_TEMPLATE),
Point::default(),
0.6,
)
}

#[allow(unused)]
Expand Down
48 changes: 36 additions & 12 deletions backend/src/ecs.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
#[cfg(test)]
use std::rc::Rc;
use std::sync::Arc;

#[cfg(debug_assertions)]
use opencv::{
core::Size,
videoio::{VideoWriter, VideoWriterTrait},
};

use crate::services::Event;
#[cfg(test)]
use crate::{Settings, bridge::MockInput, detect::MockDetector};
Expand All @@ -11,28 +15,48 @@ use crate::{
skill::SkillEntities,
};
#[cfg(debug_assertions)]
use crate::{debug::save_rune_for_training, solvers::SolvedArrow};
use crate::{debug::save_rune_for_training, run::FPS, solvers::SolvedArrow, utils::DatasetDir};

#[derive(Debug)]
#[cfg(debug_assertions)]
pub struct RecordingHandle {
writer: VideoWriter,
}

impl RecordingHandle {
pub fn write(&mut self, detector: &dyn Detector) {
self.writer.write(&detector.mat()).unwrap()
}
}

#[derive(Debug, Default)]
#[cfg(debug_assertions)]
pub struct Debug {
auto_save: bool,
pub auto_save_rune: bool,
pub auto_record_lie_detector: bool,
last_rune_detector: Option<Arc<dyn Detector>>,
last_rune_result: Option<[SolvedArrow; 4]>,
}

#[cfg(debug_assertions)]
impl Debug {
pub fn auto_save_rune(&self) -> bool {
self.auto_save
}

pub fn set_auto_save_rune(&mut self, auto_save: bool) {
self.auto_save = auto_save
pub fn new_recording(&self, frame_size: Size) -> RecordingHandle {
use rand::distr::SampleString;
use rand_distr::Alphanumeric;

let id = Alphanumeric.sample_string(&mut rand::rng(), 8);
let file = DatasetDir::Recordings
.to_folder()
.join(format!("ld_{id}.mp4"));
let fourcc = VideoWriter::fourcc('H', 'V', 'C', '1').unwrap();
let writer =
VideoWriter::new(file.to_str().unwrap(), fourcc, FPS as f64, frame_size, true).unwrap();

RecordingHandle { writer }
}

pub fn save_last_rune_result(&self) {
if !self.auto_save {
if !self.auto_save_rune {
return;
}

Expand Down Expand Up @@ -76,7 +100,7 @@ pub struct Resources {
impl Resources {
#[cfg(test)]
pub fn new(input: Option<MockInput>, detector: Option<MockDetector>) -> Self {
use std::cell::RefCell;
use std::{cell::RefCell, rc::Rc};

use crate::operation::{OperationConfiguration, OperationState};

Expand Down
Loading
Loading