fix: compile error

This commit is contained in:
grabbit 2025-03-20 08:59:39 +08:00
parent 7bbbea6140
commit 92eee703a1
7 changed files with 33 additions and 37 deletions

View File

@ -82,7 +82,7 @@ impl BrightnessDetector {
/// Update the background model with a new frame /// Update the background model with a new frame
fn update_background(&mut self, frame: &core::Mat) -> Result<()> { fn update_background(&mut self, frame: &core::Mat) -> Result<()> {
// Convert frame to grayscale // Convert frame to grayscale
let mut gray = core::Mat::default()?; let mut gray = core::Mat::default();
imgproc::cvt_color(frame, &mut gray, imgproc::COLOR_BGR2GRAY, 0)?; imgproc::cvt_color(frame, &mut gray, imgproc::COLOR_BGR2GRAY, 0)?;
match &mut self.background { match &mut self.background {
@ -101,13 +101,13 @@ impl BrightnessDetector {
} }
/// Calculate the absolute difference between current frame and background /// Calculate the absolute difference between current frame and background
fn compute_difference(&self, frame: &core::Mat) -> Result<core::Mat> { fn compute_difference(&mut self, frame: &core::Mat) -> Result<core::Mat> {
// Convert frame to grayscale // Convert frame to grayscale
let mut gray = core::Mat::default()?; let mut gray = core::Mat::default();
imgproc::cvt_color(frame, &mut gray, imgproc::COLOR_BGR2GRAY, 0)?; imgproc::cvt_color(frame, &mut gray, imgproc::COLOR_BGR2GRAY, 0)?;
// Calculate absolute difference from background // Calculate absolute difference from background
let mut diff = core::Mat::default()?; let mut diff = core::Mat::default();
if let Some(bg) = &self.background { if let Some(bg) = &self.background {
core::absdiff(bg, &gray, &mut diff)?; core::absdiff(bg, &gray, &mut diff)?;
} else { } else {
@ -124,7 +124,7 @@ impl BrightnessDetector {
self.prev_frame = Some(gray); self.prev_frame = Some(gray);
// Apply threshold to highlight significant changes // Apply threshold to highlight significant changes
let mut thresholded = core::Mat::default()?; let mut thresholded = core::Mat::default();
imgproc::threshold(&diff, &mut thresholded, 25.0, 255.0, imgproc::THRESH_BINARY)?; imgproc::threshold(&diff, &mut thresholded, 25.0, 255.0, imgproc::THRESH_BINARY)?;
Ok(thresholded) Ok(thresholded)
@ -133,13 +133,11 @@ impl BrightnessDetector {
/// Find contours in the thresholded difference image /// Find contours in the thresholded difference image
fn find_meteor_candidates(&self, diff: &core::Mat) -> Result<Vec<core::Vector<core::Point>>> { fn find_meteor_candidates(&self, diff: &core::Mat) -> Result<Vec<core::Vector<core::Point>>> {
let mut contours = core::Vector::<core::Vector<core::Point>>::new(); let mut contours = core::Vector::<core::Vector<core::Point>>::new();
let mut hierarchy = core::Vector::<core::Vec4i>::new();
// Find contours in the thresholded image // Find contours in the thresholded image
imgproc::find_contours( imgproc::find_contours(
diff, diff,
&mut contours, &mut contours,
&mut hierarchy,
imgproc::RETR_EXTERNAL, imgproc::RETR_EXTERNAL,
imgproc::CHAIN_APPROX_SIMPLE, imgproc::CHAIN_APPROX_SIMPLE,
core::Point::new(0, 0), core::Point::new(0, 0),
@ -154,7 +152,7 @@ impl BrightnessDetector {
/// Calculate the brightness change in the frame /// Calculate the brightness change in the frame
fn calculate_brightness(&self, frame: &core::Mat) -> Result<f32> { fn calculate_brightness(&self, frame: &core::Mat) -> Result<f32> {
// Convert to grayscale // Convert to grayscale
let mut gray = core::Mat::default()?; let mut gray = core::Mat::default();
imgproc::cvt_color(frame, &mut gray, imgproc::COLOR_BGR2GRAY, 0)?; imgproc::cvt_color(frame, &mut gray, imgproc::COLOR_BGR2GRAY, 0)?;
// Calculate mean brightness // Calculate mean brightness

View File

@ -7,8 +7,7 @@ use std::path::PathBuf;
use std::sync::{Arc, Mutex}; use std::sync::{Arc, Mutex};
use std::time::{Duration, Instant}; use std::time::{Duration, Instant};
use uuid::Uuid; use uuid::Uuid;
use crate::camera::Frame;
use crate::camera::frame_buffer::Frame;
use crate::config::Config; use crate::config::Config;
use crate::detection::{ use crate::detection::{
DetectionResult, DetectorConfig, FeatureImages, FrameStacker, MeteorDetector, SharedFrameStacker, DetectionResult, DetectorConfig, FeatureImages, FrameStacker, MeteorDetector, SharedFrameStacker,

View File

@ -12,7 +12,7 @@ use std::collections::VecDeque;
use std::path::PathBuf; use std::path::PathBuf;
use std::sync::{Arc, Mutex}; use std::sync::{Arc, Mutex};
use crate::camera::frame_buffer::Frame; use crate::camera::Frame;
/// Configuration for the frame stacker /// Configuration for the frame stacker
#[derive(Debug, Clone, Serialize, Deserialize)] #[derive(Debug, Clone, Serialize, Deserialize)]
@ -177,9 +177,9 @@ impl FrameStacker {
// Get dimensions from the first frame // Get dimensions from the first frame
let first_frame = &self.frame_buffer[0]; let first_frame = &self.frame_buffer[0];
let width = first_frame.data.cols(); let width = first_frame.mat.cols();
let height = first_frame.data.rows(); let height = first_frame.mat.rows();
let channels = first_frame.data.channels(); let channels = first_frame.mat.channels();
if channels != 1 { if channels != 1 {
// Convert any color frames to grayscale // Convert any color frames to grayscale
@ -195,12 +195,12 @@ impl FrameStacker {
// Process all frames // Process all frames
for (frame_idx, frame) in self.frame_buffer.iter().enumerate() { for (frame_idx, frame) in self.frame_buffer.iter().enumerate() {
// Convert to grayscale if needed // Convert to grayscale if needed
let gray_frame = if frame.data.channels() != 1 { let gray_frame = if frame.mat.channels() != 1 {
let mut gray = core::Mat::default(); let mut gray = core::Mat::default();
imgproc::cvt_color(&frame.data, &mut gray, imgproc::COLOR_BGR2GRAY, 0)?; imgproc::cvt_color(&frame.mat, &mut gray, imgproc::COLOR_BGR2GRAY, 0)?;
gray gray
} else { } else {
frame.data.clone() frame.mat.clone()
}; };
// Make sure the grayscale image is 8-bit // Make sure the grayscale image is 8-bit

View File

@ -11,7 +11,7 @@ use tokio::sync::{broadcast, mpsc};
use tokio::time; use tokio::time;
use tokio::task::JoinSet; use tokio::task::JoinSet;
use crate::camera::frame_buffer::{Frame, SharedFrameBuffer}; use crate::camera::{Frame};
use crate::camera::{CameraController, MeteorEvent}; use crate::camera::{CameraController, MeteorEvent};
use crate::config::Config; use crate::config::Config;
use crate::detection::{ use crate::detection::{
@ -380,11 +380,6 @@ impl DetectionPipeline {
.cloned() .cloned()
} }
/// Get a receiver for meteor events
pub fn subscribe_to_events(&self) -> mpsc::Receiver<MeteorEvent> {
self.event_rx.clone()
}
/// Stop the detection pipeline /// Stop the detection pipeline
pub async fn stop(&self) -> Result<()> { pub async fn stop(&self) -> Result<()> {
{ {

View File

@ -99,11 +99,11 @@ fn parse_gga(fields: &[&str]) -> Result<Option<NmeaPosition>> {
let mut position = NmeaPosition::default(); let mut position = NmeaPosition::default();
// Parse time // // Parse time
if let Some(time) = parse_nmea_time(fields[1]) { // if let Some(time) = parse_nmea_time(fields[1]) {
// This only has time, not date // // This only has time, not date
position.timestamp = Some(Utc.from_utc_datetime(&time.and_utc())); // position.timestamp = Some(Utc.from_utc_datetime(&time.and_utc()));
} // }
// Parse latitude (field 2 & 3) // Parse latitude (field 2 & 3)
if !fields[2].is_empty() && !fields[3].is_empty() { if !fields[2].is_empty() && !fields[3].is_empty() {
@ -280,6 +280,7 @@ fn calculate_checksum(message: &str) -> u8 {
/// Unit tests for NMEA parser /// Unit tests for NMEA parser
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use chrono::{Datelike, Timelike};
use super::*; use super::*;
#[test] #[test]

View File

@ -1,3 +1,4 @@
use chrono::DateTime;
use anyhow::{anyhow, Context, Result}; use anyhow::{anyhow, Context, Result};
use chrono::Utc; use chrono::Utc;
use log::{debug, error, info, warn}; use log::{debug, error, info, warn};
@ -297,7 +298,7 @@ impl SensorController {
} }
// Broadcast update // Broadcast update
let _ = data_tx.send(data); let _ = data_tx.send(data.clone());
debug!("Sensor data updated: temp={:.1}°C, humidity={:.1}%, light={:.3}", debug!("Sensor data updated: temp={:.1}°C, humidity={:.1}%, light={:.3}",
data.temperature, data.humidity, data.sky_brightness); data.temperature, data.humidity, data.sky_brightness);

View File

@ -44,13 +44,15 @@ impl Dht22Sensor {
.context(format!("Failed to access GPIO pin {}", self.pin))?; .context(format!("Failed to access GPIO pin {}", self.pin))?;
// Send start signal // Send start signal
pin.set_mode(Mode::Output); let mut pin = pin.into_output_low();
pin.set_low(); pin.set_low();
thread::sleep(Duration::from_millis(20)); // At least 18ms for DHT22 thread::sleep(Duration::from_millis(20)); // At least 18ms for DHT22
pin.set_high(); pin.set_high();
// Switch to input mode to read response // Switch to input mode to read response
pin.set_mode(Mode::Input); let mut pin = gpio.get(self.pin)
.context(format!("Failed to access GPIO pin {}", self.pin))?;
let mut pin = pin.into_input();
// Wait for sensor to respond // Wait for sensor to respond
let mut cycles = 0; let mut cycles = 0;