opencv_core/
traits.rs

1//! Common traits for OpenCV types
2
3use crate::{Result, Size, MatType};
4
5/// Trait for objects that have dimensions
6pub trait Dimensioned {
7    /// Get width
8    fn width(&self) -> i32;
9    /// Get height
10    fn height(&self) -> i32;
11    /// Get size
12    fn size(&self) -> Size;
13}
14
15/// Trait for image-like objects
16pub trait ImageTrait: Dimensioned {
17    /// Get image type
18    fn image_type(&self) -> MatType;
19    /// Get number of channels
20    fn channels(&self) -> i32;
21    /// Check if empty
22    fn is_empty(&self) -> bool;
23}
24
25/// Trait for objects that can be converted to/from arrays
26pub trait ArrayConvertible<T, const N: usize> {
27    /// Convert to array
28    fn to_array(&self) -> [T; N];
29    /// Create from array
30    fn from_array(arr: [T; N]) -> Self;
31}
32
33/// Trait for objects that support arithmetic operations
34pub trait Arithmetic: Sized {
35    /// Add two objects
36    fn add(&self, other: &Self) -> Result<Self>;
37    /// Subtract two objects
38    fn sub(&self, other: &Self) -> Result<Self>;
39    /// Multiply by scalar
40    fn mul_scalar(&self, scalar: f64) -> Result<Self>;
41    /// Divide by scalar
42    fn div_scalar(&self, scalar: f64) -> Result<Self>;
43}