feat: mirror camera frames for selfie preview
This commit is contained in:
@@ -11,3 +11,4 @@
|
||||
- The monitor provides room lighting: keep the translucent white overlay on throughout the countdown and until photo capture returns; do not fade it out early.
|
||||
- Display the countdown as a large semi-transparent number directly over the lighting overlay, without a box or supporting text.
|
||||
- The primary kiosk monitor is a 19-inch 1907FPVT LCD at 1280×1024 (5:4). Check overlays at that resolution; constrain scaling by width as well as height, keep instructions in two columns, and leave the central camera area clear.
|
||||
- Always mirror camera frames horizontally for a selfie view, including the initial preview. Run palm detection in the same mirrored coordinates so overlays remain aligned.
|
||||
|
||||
16
src/main.rs
16
src/main.rs
@@ -11,7 +11,11 @@ use std::{
|
||||
time::{Duration, Instant},
|
||||
};
|
||||
|
||||
use opencv::{core::Mat, imgproc, prelude::*};
|
||||
use opencv::{
|
||||
core::{self, Mat},
|
||||
imgproc,
|
||||
prelude::*,
|
||||
};
|
||||
use slint::{Rgb8Pixel, SharedPixelBuffer};
|
||||
|
||||
slint::include_modules!();
|
||||
@@ -38,6 +42,7 @@ fn main() -> Result<(), Box<dyn Error>> {
|
||||
"Check camera passthrough and camera frame rate.",
|
||||
);
|
||||
let (mut cam, mut frame) = camera::wait_until_ready(&mut camera_log)?;
|
||||
mirror_frame(&mut frame)?;
|
||||
|
||||
let mut detector = palm::Detector::new()?;
|
||||
let ui = AppWindow::new()?;
|
||||
@@ -103,6 +108,8 @@ fn main() -> Result<(), Box<dyn Error>> {
|
||||
}
|
||||
|
||||
let now = Instant::now();
|
||||
// Use the same selfie coordinates for detection and the preview.
|
||||
mirror_frame(&mut frame)?;
|
||||
if now.duration_since(last_detection) >= palm::DETECTION_INTERVAL {
|
||||
let _ = detection_tx.try_send(frame.try_clone()?);
|
||||
last_detection = now;
|
||||
@@ -172,6 +179,13 @@ fn main() -> Result<(), Box<dyn Error>> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn mirror_frame(frame: &mut Mat) -> opencv::Result<()> {
|
||||
let mut mirrored = Mat::default();
|
||||
core::flip(frame, &mut mirrored, 1)?;
|
||||
*frame = mirrored;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn frame_to_buffer(frame: &Mat) -> opencv::Result<SharedPixelBuffer<Rgb8Pixel>> {
|
||||
let mut rgb = Mat::default();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user