meteor_detect/src/utils/opencv_compat.rs

55 lines
1.7 KiB
Rust

use anyhow::Result;
use opencv::{core, imgproc};
use opencv::prelude::*;
/// Convert an image from one color space to another, with compatibility across OpenCV versions
///
/// This function wraps imgproc::cvt_color with version-specific adaptations
///
/// # Arguments
/// * `src` - Source image
/// * `dst` - Destination image
/// * `code` - Color conversion code (e.g., COLOR_BGR2GRAY)
/// * `dstCn` - Number of channels in the destination image (0 means auto)
///
/// # Returns
/// * `Result<()>` - Success or error
#[cfg(feature = "opencv-4-11-plus")]
pub fn convert_color(
src: &core::Mat,
dst: &mut core::Mat,
code: i32,
dst_cn: i32,
) -> Result<(), opencv::Error> {
// OpenCV 4.11+ version with ALGO_HINT_APPROX parameter
imgproc::cvt_color(src, dst, code, dst_cn, opencv::core::AlgorithmHint::ALGO_HINT_APPROX)
}
/// Convert an image from one color space to another, with compatibility across OpenCV versions
///
/// This function wraps imgproc::cvt_color with version-specific adaptations
///
/// # Arguments
/// * `src` - Source image
/// * `dst` - Destination image
/// * `code` - Color conversion code (e.g., COLOR_BGR2GRAY)
/// * `dstCn` - Number of channels in the destination image (0 means auto)
///
/// # Returns
/// * `Result<()>` - Success or error
#[cfg(not(feature = "opencv-4-11-plus"))]
pub fn convert_color(
src: &core::Mat,
dst: &mut core::Mat,
code: i32,
dst_cn: i32,
) -> Result<(), opencv::Error> {
// OpenCV 4.10 and earlier version without ALGO_HINT_APPROX parameter
imgproc::cvt_color(src, dst, code, dst_cn)
}
/// Get the OpenCV version string from environment
pub fn get_opencv_version_string() -> String {
option_env!("OPENCV_VERSION").unwrap_or("unknown").to_string()
}