Skip to content

CvType and CvDepth trait bounds on several types.#6

Open
uttarayan21 wants to merge 39 commits intomasterfrom
xdog-operator
Open

CvType and CvDepth trait bounds on several types.#6
uttarayan21 wants to merge 39 commits intomasterfrom
xdog-operator

Conversation

@uttarayan21
Copy link
Copy Markdown
Member

@uttarayan21 uttarayan21 commented Feb 16, 2026

Added CvType and CvDepth

Support for ndarray::Array<[T;N]> and similar types (nalgebra::Vector<T,N>, glam::{D, B}Vec{3, 4, 5, 6})

Support for sobel and absdiff operators from opencv

Copilot AI review requested due to automatic review settings February 16, 2026 16:16

This comment was marked as outdated.

@uttarayan21 uttarayan21 changed the title Xdog operator sobel absdiff operators and xdog implementation and CvType trait bound Feb 18, 2026
@uttarayan21 uttarayan21 changed the title sobel absdiff operators and xdog implementation and CvType trait bound sobel absdiff operators, xdog implementation and CvType trait bound Feb 18, 2026
@codecov
Copy link
Copy Markdown

codecov bot commented Feb 18, 2026

Codecov Report

❌ Patch coverage is 66.00000% with 204 lines in your changes missing coverage. Please review.
✅ Project coverage is 69.89%. Comparing base (1e26059) to head (edafc76).

Files with missing lines Patch % Lines
ndarray-image/src/image.rs 0.00% 158 Missing ⚠️
ndarray-resize/src/lib.rs 40.00% 9 Missing ⚠️
ndcv-bridge/src/lib.rs 18.18% 9 Missing ⚠️
ndcv-bridge/src/types.rs 70.00% 9 Missing ⚠️
ndcv-bridge/src/gaussian.rs 80.64% 6 Missing ⚠️
ndcv-bridge/src/connected_components.rs 0.00% 4 Missing ⚠️
ndarray-image/src/percentile.rs 0.00% 3 Missing ⚠️
ndcv-bridge/src/sobel.rs 98.96% 2 Missing ⚠️
bounding-box/src/lib.rs 80.00% 1 Missing ⚠️
ndcv-bridge/src/absdiff.rs 99.01% 1 Missing ⚠️
... and 2 more
Additional details and impacted files
@@            Coverage Diff             @@
##           master       #6      +/-   ##
==========================================
+ Coverage   66.91%   69.89%   +2.97%     
==========================================
  Files          27       29       +2     
  Lines        3854     4026     +172     
==========================================
+ Hits         2579     2814     +235     
+ Misses       1275     1212      -63     
Flag Coverage Δ
unittests 69.89% <66.00%> (+2.97%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

This comment was marked as outdated.

@uttarayan21 uttarayan21 changed the title sobel absdiff operators, xdog implementation and CvType trait bound CvType and CvDepth trait bounds on several types. Mar 16, 2026
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 34 out of 40 changed files in this pull request and generated 5 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +13 to +34
impl<'a> opencv::core::ToOutputArray for MatRefMut<'a> {
fn output_array(
&mut self,
) -> std::result::Result<
opencv::boxed_ref::BoxedRefMut<'a, opencv::core::_OutputArray>,
opencv::Error,
> {
unsafe { core::mem::transmute(self.mat.output_array()) }
}
}

impl<'a> opencv::core::ToInputArray for MatRef<'a> {
fn input_array(
&self,
) -> std::result::Result<
opencv::boxed_ref::BoxedRef<'a, opencv::core::_InputArray>,
opencv::Error,
> {
unsafe { core::mem::transmute(self.mat.input_array()) }
}
}

Comment on lines 40 to +112
@@ -46,36 +64,17 @@ pub use contours::{
#[allow(deprecated)]
pub use conversions::NdCvConversion;

#[cfg(feature = "opencv")]
pub use absdiff::{NdCvAbsDiff, NdCvAbsDiffInPlace};
pub use bounding_rect::BoundingRect;
#[cfg(feature = "opencv")]
pub use connected_components::{Connectivity, NdCvConnectedComponents};
#[cfg(feature = "opencv")]
pub use conversions::{MatAsNd, NdAsImage, NdAsImageMut, NdAsMat, NdAsMatMut};
#[cfg(feature = "opencv")]
pub use resize::{Interpolation, NdCvResize};

pub(crate) mod prelude_ {
pub use crate::errors::NdCvError;
pub use error_stack::*;
pub type Result<T, C> = core::result::Result<T, Report<C>>;
}

#[cfg(feature = "opencv")]
pub fn type_depth<T>() -> i32 {
match std::any::type_name::<T>() {
"u8" => opencv::core::CV_8U,
"i8" => opencv::core::CV_8S,
"u16" => opencv::core::CV_16U,
"i16" => opencv::core::CV_16S,
"i32" => opencv::core::CV_32S,
"f32" => opencv::core::CV_32F,
"f64" => opencv::core::CV_64F,
_ => panic!("Unsupported type"),
}
pub fn type_depth<T: types::CvType>() -> i32 {
use types::CvType;
<T as CvType>::cv_depth()
}

#[cfg(feature = "opencv")]
pub const fn depth_type(depth: i32) -> &'static str {
match depth {
opencv::core::CV_8U => "u8",
@@ -88,3 +87,36 @@ pub const fn depth_type(depth: i32) -> &'static str {
_ => panic!("Unsupported depth"),
}
}

use opencv::core::AlgorithmHint as OpencvAlgorithmHint;
#[repr(C)]
#[derive(Default, Debug, Copy, Clone)]
pub enum BorderType {
#[default]
BorderConstant = 0,
BorderReplicate = 1,
BorderReflect = 2,
BorderWrap = 3,
BorderReflect101 = 4,
BorderTransparent = 5,
BorderIsolated = 16,
}

#[repr(C)]
#[derive(Default, Debug, Copy, Clone)]
pub enum AlgorithmHint {
#[default]
AlgoHintDefault = OpencvAlgorithmHint::ALGO_HINT_DEFAULT as isize,
AlgoHintAccurate = OpencvAlgorithmHint::ALGO_HINT_ACCURATE as isize,
AlgoHintApprox = OpencvAlgorithmHint::ALGO_HINT_APPROX as isize,
}
Comment on lines +33 to +37
if self.ksize.is_some_and(|k| {
k == Ksize::Scharr && !((dxy.x >= 0 && dxy.y >= 0) && (dxy.x + dxy.y == 1))
}) {
return Err("ksize cannot be Scharr when both dxy.x and dxy.y are non-negative and their sum is 1".into());
}
Comment on lines +31 to +38
pub fn validate(&self) -> Result<(), String> {
let dxy = self.dxy.ok_or("dxy is required")?;
if self.ksize.is_some_and(|k| {
k == Ksize::Scharr && !((dxy.x >= 0 && dxy.y >= 0) && (dxy.x + dxy.y == 1))
}) {
return Err("ksize cannot be Scharr when both dxy.x and dxy.y are non-negative and their sum is 1".into());
}
Ok(())
Comment on lines +179 to +183
#[test]
fn test_cv_type() {
assert_eq!(<u8 as CvType>::cv_type(), opencv::core::CV_8UC1);
assert_eq!(<glam::Vec3 as CvType>::cv_type(), opencv::core::CV_32FC3);
}
@uttarayan21 uttarayan21 requested a review from CeNiEi March 16, 2026 11:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants