1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
use crate::core;
use crate::core::{Point3_, Point_, Rect_, Size_, VecN};
#[inline]
pub const fn CV_MAT_DEPTH(flags: i32) -> i32 {
#![allow(non_snake_case)]
flags & core::Mat_DEPTH_MASK
}
#[inline]
pub const fn CV_MAKETYPE(depth: i32, cn: i32) -> i32 {
#![allow(non_snake_case)]
CV_MAT_DEPTH(depth) + ((cn - 1) << core::CV_CN_SHIFT)
}
pub trait DataType: Copy + private::Sealed {
fn opencv_depth() -> i32;
fn opencv_channels() -> i32;
#[inline]
fn opencv_type() -> i32 {
CV_MAKETYPE(Self::opencv_depth(), Self::opencv_channels())
}
#[inline]
#[deprecated(note = "Use opencv_depth() instead. Removal in July 2023")]
fn depth() -> i32 {
Self::opencv_depth()
}
#[inline]
#[deprecated(note = "Use opencv_channels() instead. Removal in July 2023")]
fn channels() -> i32 {
Self::opencv_channels()
}
#[inline]
#[deprecated(note = "Use opencv_type() instead. Removal in July 2023")]
fn typ() -> i32 {
Self::opencv_type()
}
}
macro_rules! data_type {
($rust_type: ty, $mat_depth: expr, $channels: expr) => {
impl $crate::core::DataType for $rust_type {
#[inline]
fn opencv_depth() -> i32 {
$mat_depth
}
#[inline]
fn opencv_channels() -> i32 {
$channels
}
}
impl private::Sealed for $rust_type {}
};
}
data_type!(u8, core::CV_8U, 1);
data_type!(i8, core::CV_8S, 1);
data_type!(u16, core::CV_16U, 1);
data_type!(i16, core::CV_16S, 1);
data_type!(i32, core::CV_32S, 1);
data_type!(f32, core::CV_32F, 1);
data_type!(f64, core::CV_64F, 1);
#[cfg(feature = "rgb")]
data_type!(rgb::RGB8, core::CV_8U, 3);
#[cfg(feature = "rgb")]
data_type!(rgb::RGBA8, core::CV_8U, 4);
#[cfg(feature = "rgb")]
data_type!(rgb::alt::GRAY8, core::CV_8U, 1);
#[cfg(feature = "rgb")]
data_type!(rgb::alt::GRAYA8, core::CV_8U, 2);
#[cfg(feature = "rgb")]
data_type!(rgb::alt::BGR8, core::CV_8U, 3);
#[cfg(feature = "rgb")]
data_type!(rgb::alt::ARGB8, core::CV_8U, 4);
#[cfg(feature = "rgb")]
data_type!(rgb::alt::BGRA8, core::CV_8U, 4);
#[cfg(feature = "rgb")]
data_type!(rgb::alt::ABGR8, core::CV_8U, 4);
impl<T: DataType, const N: usize> DataType for VecN<T, N> {
#[inline]
fn opencv_depth() -> i32 {
T::opencv_depth()
}
#[inline]
fn opencv_channels() -> i32 {
N as i32
}
}
impl<T: DataType> DataType for Point_<T> {
#[inline]
fn opencv_depth() -> i32 {
T::opencv_depth()
}
#[inline]
fn opencv_channels() -> i32 {
2
}
}
impl<T: DataType> DataType for Point3_<T> {
#[inline]
fn opencv_depth() -> i32 {
T::opencv_depth()
}
#[inline]
fn opencv_channels() -> i32 {
3
}
}
impl<T: DataType> DataType for Size_<T> {
#[inline]
fn opencv_depth() -> i32 {
T::opencv_depth()
}
#[inline]
fn opencv_channels() -> i32 {
2
}
}
impl<T: DataType> DataType for Rect_<T> {
#[inline]
fn opencv_depth() -> i32 {
T::opencv_depth()
}
#[inline]
fn opencv_channels() -> i32 {
4
}
}
mod private {
pub trait Sealed {}
}
impl<T: DataType, const N: usize> private::Sealed for VecN<T, N> {}
impl<T: DataType> private::Sealed for Point_<T> {}
impl<T: DataType> private::Sealed for Point3_<T> {}
impl<T: DataType> private::Sealed for Size_<T> {}
impl<T: DataType> private::Sealed for Rect_<T> {}