Skip to content

Commit

Permalink
Add some logging
Browse files Browse the repository at this point in the history
Fixes #19

Signed-off-by: Šimon Brandner <[email protected]>
  • Loading branch information
SimonBrandner committed Sep 6, 2024
1 parent 43e5a11 commit 6b56052
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 0 deletions.
8 changes: 8 additions & 0 deletions crates/oblichey-cli/src/camera/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ mod utils;

use crate::geometry::Vec2D;
use image::{ImageBuffer, ImageError, Rgb};
use log::{error, trace, warn};
use std::fmt::Display;
use std::io;
use std::sync::atomic::{AtomicBool, Ordering};
Expand Down Expand Up @@ -78,6 +79,8 @@ impl Camera {
///
/// This is going to panic if a supported output pixel format cannot be found
pub fn new(camera_path: &str) -> Result<Self, Error> {
trace!("Creating Camera");

let device = Device::with_path(camera_path)?;
let mut format = device.format()?;
let frame_size = Vec2D::new(format.width, format.height);
Expand All @@ -95,6 +98,9 @@ impl Camera {
let Some(pixel_format) = chosen_pixel_format else {
return Err(Error::CannotSetFormat);
};

trace!("Chosen camera format: {format:?}");

#[cfg(not(feature = "rgb-webcam"))]
assert_eq!(
pixel_format,
Expand Down Expand Up @@ -132,6 +138,8 @@ pub fn start(frame: &Arc<Mutex<Option<Frame>>>, finished: &Arc<AtomicBool>, came
let new_frame = match camera.get_frame() {
Ok(f) => f,
Err(e) => {
error!("Failed to get frame: {e}");

failed_frames_in_row += 1;
assert!(
failed_frames_in_row < MAX_FAILED_FRAMES_IN_ROW,
Expand Down
5 changes: 5 additions & 0 deletions crates/oblichey-cli/src/gui/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use eframe::{
},
EventLoopBuilderHook, NativeOptions,
};
use log::{trace, warn};
use std::{
fmt::Display,
sync::{
Expand Down Expand Up @@ -55,6 +56,8 @@ pub fn start(
faces: Arc<Mutex<Vec<FaceForGUI>>>,
finished: Arc<AtomicBool>,
) {
trace!("Creating GUI");

let event_loop_builder: Option<EventLoopBuilderHook> = Some(Box::new(|event_loop_builder| {
wayland::EventLoopBuilderExtWayland::with_any_thread(event_loop_builder, true);
x11::EventLoopBuilderExtX11::with_any_thread(event_loop_builder, true);
Expand Down Expand Up @@ -179,6 +182,7 @@ impl Gui {
impl eframe::App for Gui {
fn update(&mut self, ctx: &egui::Context, _: &mut eframe::Frame) {
if self.finished.load(Ordering::SeqCst) {
trace!("Sending viewport command to close window");
ctx.send_viewport_cmd(egui::ViewportCommand::Close);
return;
}
Expand All @@ -188,6 +192,7 @@ impl eframe::App for Gui {
Err(e) => panic!("Failed to get lock: {e}"),
};
let Some(image) = frame_lock.clone() else {
warn!("Do not have a frame to render");
ctx.request_repaint();
return;
};
Expand Down
5 changes: 5 additions & 0 deletions crates/oblichey-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use camera::Frame;
use clap::Parser;
use config::Config;
use flexi_logger::{FileSpec, Logger};
use log::trace;
use processors::auth_processor::AuthProcessor;
use processors::face::{FaceEmbedding, FaceForGUI};
use processors::face_processor::FaceProcessor;
Expand Down Expand Up @@ -99,6 +100,8 @@ fn handle_command(
config: &Config,
face_embeddings: HashMap<String, FaceEmbedding>,
) -> ExitCode {
trace!("Handling command: {command:?}");

match command {
Command::Remove { name } => {
if !face_embeddings.contains_key(&name) {
Expand Down Expand Up @@ -186,6 +189,8 @@ fn start_threads(
config: &Config,
gui: bool,
) {
trace!("Starting threads");

let frame: Arc<Mutex<Option<Frame>>> = Arc::new(Mutex::new(None));
let faces_for_gui: Arc<Mutex<Vec<FaceForGUI>>> = Arc::new(Mutex::new(Vec::new()));
let finished: Arc<AtomicBool> = Arc::new(AtomicBool::new(false));
Expand Down
1 change: 1 addition & 0 deletions crates/oblichey-cli/src/models/detector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use crate::camera::Frame;
use crate::geometry::{Rectangle, Vec2D};
use burn::tensor::backend::Backend;
use burn::tensor::{Tensor, TensorData};
use log::trace;
#[cfg(test)]
use mockall::automock;

Expand Down
2 changes: 2 additions & 0 deletions crates/oblichey-cli/src/processors/frame_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use crate::{
};
use burn::backend::{wgpu::WgpuDevice, Wgpu};
use image::imageops::{crop, resize, FilterType};
use log::trace;
use mockall_double::double;

type Backend = Wgpu<f32, i32>;
Expand Down Expand Up @@ -77,6 +78,7 @@ impl FrameProcessor {
let face = self.recognizer.forward(&face_image);
Ok(face)
} else {
trace!("Detected face too small");
Err(FaceRecognitionError::TooSmall)
},
});
Expand Down
3 changes: 3 additions & 0 deletions crates/oblichey-cli/src/processors/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ pub mod face_processor;
pub mod frame_processor;
pub mod scan_processor;

use log::warn;

use self::{face::FaceForGUI, face_processor::FaceProcessor, frame_processor::FrameProcessor};
use crate::camera::Frame;
use std::sync::{
Expand All @@ -30,6 +32,7 @@ pub fn start(
Err(e) => panic!("Failed to get lock: {e}"),
};
let Some(new_frame) = (*frame_lock).clone() else {
warn!("No frame to process");
continue;
};
drop(frame_lock);
Expand Down

0 comments on commit 6b56052

Please sign in to comment.