From 1bfe1801537913c3f907e71ec654a94ebdd18e5f Mon Sep 17 00:00:00 2001 From: grabbit Date: Sat, 5 Apr 2025 01:27:37 +0800 Subject: [PATCH] fix: opencv compatiable --- src/detection/brightness_detector.rs | 7 +++---- src/detection/feature_images.rs | 9 ++++----- src/detection/frame_stacker.rs | 3 +-- 3 files changed, 8 insertions(+), 11 deletions(-) diff --git a/src/detection/brightness_detector.rs b/src/detection/brightness_detector.rs index 3a28200..b56b7bc 100644 --- a/src/detection/brightness_detector.rs +++ b/src/detection/brightness_detector.rs @@ -1,7 +1,6 @@ use anyhow::{Context, Result}; use log::{debug, error, info, warn}; use opencv::{core, imgproc, prelude::*}; -use opencv::core::AlgorithmHint::ALGO_HINT_APPROX; use serde::{Deserialize, Serialize}; use uuid::Uuid; @@ -88,7 +87,7 @@ impl BrightnessDetector { fn update_background(&mut self, frame: &core::Mat) -> Result<()> { // Convert frame to grayscale let mut gray = core::Mat::default(); - imgproc::cvt_color(frame, &mut gray, imgproc::COLOR_BGR2GRAY, 0,ALGO_HINT_APPROX)?; + imgproc::cvt_color(frame, &mut gray, imgproc::COLOR_BGR2GRAY, 0)?; match &mut self.background { Some(bg) => { // Gradually update background model (running average) @@ -112,7 +111,7 @@ impl BrightnessDetector { fn compute_difference(&mut self, frame: &core::Mat) -> Result { // Convert frame to grayscale let mut gray = core::Mat::default(); - imgproc::cvt_color(frame, &mut gray, imgproc::COLOR_BGR2GRAY, 0,ALGO_HINT_APPROX)?; + imgproc::cvt_color(frame, &mut gray, imgproc::COLOR_BGR2GRAY, 0)?; // Calculate absolute difference from background let mut diff = core::Mat::default(); @@ -161,7 +160,7 @@ impl BrightnessDetector { fn calculate_brightness(&self, frame: &core::Mat) -> Result { // Convert to grayscale let mut gray = core::Mat::default(); - imgproc::cvt_color(frame, &mut gray, imgproc::COLOR_BGR2GRAY, 0,ALGO_HINT_APPROX)?; + imgproc::cvt_color(frame, &mut gray, imgproc::COLOR_BGR2GRAY, 0)?; // Calculate mean brightness let mean = core::mean(&gray, &core::no_array())?; diff --git a/src/detection/feature_images.rs b/src/detection/feature_images.rs index b77fd95..078485a 100644 --- a/src/detection/feature_images.rs +++ b/src/detection/feature_images.rs @@ -3,7 +3,6 @@ use chrono::{DateTime, Utc}; use log::{debug, info}; use opencv::{core, imgcodecs, prelude::*}; use std::path::Path; -use opencv::core::AlgorithmHint::ALGO_HINT_APPROX; /// CAMS FTP format feature images /// Used for meteor detection analysis @@ -148,10 +147,10 @@ impl FeatureImages { let mut stdpixel_color = core::Mat::default(); let mut maxframe_color = core::Mat::default(); - opencv::imgproc::cvt_color(&self.maxpixel, &mut maxpixel_color, opencv::imgproc::COLOR_GRAY2BGR, 0,ALGO_HINT_APPROX)?; - opencv::imgproc::cvt_color(&self.avepixel, &mut avepixel_color, opencv::imgproc::COLOR_GRAY2BGR, 0,ALGO_HINT_APPROX)?; - opencv::imgproc::cvt_color(&self.stdpixel, &mut stdpixel_color, opencv::imgproc::COLOR_GRAY2BGR, 0,ALGO_HINT_APPROX)?; - opencv::imgproc::cvt_color(&self.maxframe, &mut maxframe_color, opencv::imgproc::COLOR_GRAY2BGR, 0,ALGO_HINT_APPROX)?; + opencv::imgproc::cvt_color(&self.maxpixel, &mut maxpixel_color, opencv::imgproc::COLOR_GRAY2BGR, 0)?; + opencv::imgproc::cvt_color(&self.avepixel, &mut avepixel_color, opencv::imgproc::COLOR_GRAY2BGR, 0)?; + opencv::imgproc::cvt_color(&self.stdpixel, &mut stdpixel_color, opencv::imgproc::COLOR_GRAY2BGR, 0)?; + opencv::imgproc::cvt_color(&self.maxframe, &mut maxframe_color, opencv::imgproc::COLOR_GRAY2BGR, 0)?; // Create a region of interest for each quadrant let roi_top_left = core::Rect::new(0, 0, width, height); diff --git a/src/detection/frame_stacker.rs b/src/detection/frame_stacker.rs index f88125e..cd341e5 100644 --- a/src/detection/frame_stacker.rs +++ b/src/detection/frame_stacker.rs @@ -11,7 +11,6 @@ use serde::{Deserialize, Serialize}; use std::collections::VecDeque; use std::path::PathBuf; use std::sync::{Arc, Mutex}; -use opencv::core::AlgorithmHint::ALGO_HINT_APPROX; use crate::camera::Frame; use crate::detection::feature_images::FeatureImages; @@ -288,7 +287,7 @@ impl FrameStacker { // Convert to grayscale if needed let gray_frame = if frame.mat.channels() != 1 { let mut gray = core::Mat::default(); - imgproc::cvt_color(&frame.mat, &mut gray, imgproc::COLOR_BGR2GRAY, 0,ALGO_HINT_APPROX)?; + imgproc::cvt_color(&frame.mat, &mut gray, imgproc::COLOR_BGR2GRAY, 0)?; gray } else { frame.mat.clone()