Rename typ(), channels(), depth() to opencv_type(), opencv_channels(), opencv_depth()
MODIFY
examples/discrete_fourier_transform.rs
examples/discrete_fourier_transform.rs
@@ -31,9 +31,9 @@ fn main() -> opencv::Result<()> {
let plane_size = padded.size()?;
let mut planes = core::Vector::<Mat>::new();
let mut padded_f32 = Mat::default();
- padded.convert_to(&mut padded_f32, f32::typ(), 1., 0.)?;
+ padded.convert_to(&mut padded_f32, f32::opencv_type(), 1., 0.)?;
planes.push(padded_f32);
- planes.push(Mat::zeros_size(plane_size, f32::typ())?.to_mat()?);
+ planes.push(Mat::zeros_size(plane_size, f32::opencv_type())?.to_mat()?);
let mut complexI = Mat::default();
core::merge(&planes, &mut complexI)?;
let mut complexI_tmp = Mat::default();

MODIFY
src/manual/core/data_type.rs
src/manual/core/data_type.rs
@@ -15,12 +15,30 @@ pub const fn CV_MAKETYPE(depth: i32, cn: i32) -> i32 {
/// This sealed trait is implemented for types that are valid to use as Mat elements
pub trait DataType: Copy + private::Sealed {
- fn depth() -> i32;
- fn channels() -> i32;
+ 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 {
- CV_MAKETYPE(Self::depth(), Self::channels())
+ Self::opencv_type()
}
}
@@ -28,12 +46,12 @@ macro_rules! data_type {
($rust_type: ty, $mat_depth: expr, $channels: expr) => {
impl $crate::core::DataType for $rust_type {
#[inline]
- fn depth() -> i32 {
+ fn opencv_depth() -> i32 {
$mat_depth
}
#[inline]
- fn channels() -> i32 {
+ fn opencv_channels() -> i32 {
$channels
}
}
@@ -72,60 +90,60 @@ data_type!(rgb::alt::ABGR8, core::CV_8U, 4);
impl<T: DataType, const N: usize> DataType for VecN<T, N> {
#[inline]
- fn depth() -> i32 {
- T::depth()
+ fn opencv_depth() -> i32 {
+ T::opencv_depth()
}
#[inline]
- fn channels() -> i32 {
+ fn opencv_channels() -> i32 {
N as i32
}
}
impl<T: DataType> DataType for Point_<T> {
#[inline]
- fn depth() -> i32 {
- T::depth()
+ fn opencv_depth() -> i32 {
+ T::opencv_depth()
}
#[inline]
- fn channels() -> i32 {
+ fn opencv_channels() -> i32 {
2
}
}
impl<T: DataType> DataType for Point3_<T> {
#[inline]
- fn depth() -> i32 {
- T::depth()
+ fn opencv_depth() -> i32 {
+ T::opencv_depth()
}
#[inline]
- fn channels() -> i32 {
+ fn opencv_channels() -> i32 {
3
}
}
impl<T: DataType> DataType for Size_<T> {
#[inline]
- fn depth() -> i32 {
- T::depth()
+ fn opencv_depth() -> i32 {
+ T::opencv_depth()
}
#[inline]
- fn channels() -> i32 {
+ fn opencv_channels() -> i32 {
2
}
}
impl<T: DataType> DataType for Rect_<T> {
#[inline]
- fn depth() -> i32 {
- T::depth()
+ fn opencv_depth() -> i32 {
+ T::opencv_depth()
}
#[inline]
- fn channels() -> i32 {
+ fn opencv_channels() -> i32 {
4
}
}

MODIFY
src/manual/core/mat.rs
src/manual/core/mat.rs
@@ -25,7 +25,7 @@ unsafe fn convert_ptr_mut<'r, T>(r: *mut u8) -> &'r mut T {
#[inline]
fn match_format<T: DataType>(mat_type: i32) -> Result<()> {
- let out_type = T::typ();
+ let out_type = T::opencv_type();
if mat_type == out_type {
Ok(())
} else {
@@ -125,7 +125,7 @@ fn col_count_i32(col_count: usize) -> Result<i32> {
impl Mat {
/// Create new `Mat` from the iterator of known size
pub fn from_exact_iter<T: DataType>(s: impl ExactSizeIterator<Item = T>) -> Result<Self> {
- let mut out = unsafe { Self::new_rows_cols(row_count_i32(s.len())?, 1, T::typ()) }?;
+ let mut out = unsafe { Self::new_rows_cols(row_count_i32(s.len())?, 1, T::opencv_type()) }?;
for (i, x) in s.enumerate() {
// safe because `row_count_i32` ensures that len of `s` fits `i32`
let i = i as i32;
@@ -148,7 +148,7 @@ impl Mat {
} else {
0
};
- let mut out = Self::new_rows_cols_with_default(row_count, col_count, T::typ(), Scalar::all(0.))?;
+ let mut out = Self::new_rows_cols_with_default(row_count, col_count, T::opencv_type(), Scalar::all(0.))?;
for (row_n, row) in s.iter().enumerate() {
// safe because `row_count_i32` ensures that len of `s` fits `i32`
let row_n = row_n as i32;
@@ -185,7 +185,7 @@ impl Mat {
Self::new_rows_cols_with_data(
row_count_i32(row_count)?,
col_count_i32(col_count)?,
- T::typ(),
+ T::opencv_type(),
s.as_ptr() as *mut c_void,
core::Mat_AUTO_STEP,
)

MODIFY
tests/boxed.rs
tests/boxed.rs
@@ -9,7 +9,7 @@ use opencv::{
#[test]
fn layout() -> Result<()> {
- let mat = Mat::new_rows_cols_with_default(1, 3, f32::typ(), Scalar::all(10.))?;
+ let mat = Mat::new_rows_cols_with_default(1, 3, f32::opencv_type(), Scalar::all(10.))?;
let mut mat_ptr = mat.as_raw_Mat();
let mat_ref: &mut Mat = unsafe { transmute(&mut mat_ptr) };
assert_eq!(mat.size()?, mat_ref.size()?);
@@ -46,7 +46,7 @@ fn into_raw() -> Result<()> {
a.into_raw()
}
- let a = Mat::new_rows_cols_with_default(10, 10, u16::typ(), Scalar::all(9.))?;
+ let a = Mat::new_rows_cols_with_default(10, 10, u16::opencv_type(), Scalar::all(9.))?;
let ptr = into_raw(a);
let b = unsafe { Mat::from_raw(ptr) };
assert_eq!(100, b.total());
@@ -126,7 +126,7 @@ fn cast_descendant() -> Result<()> {
use opencv::rgbd::{OdometryFrame, RgbdFrame};
use std::convert::TryFrom;
- let image = Mat::new_rows_cols_with_default(1, 2, i32::typ(), Scalar::from(1.))?;
+ let image = Mat::new_rows_cols_with_default(1, 2, i32::opencv_type(), Scalar::from(1.))?;
let depth = Mat::default();
let mask = Mat::default();
let normals = Mat::default();
@@ -136,7 +136,7 @@ fn cast_descendant() -> Result<()> {
let mut base = RgbdFrame::from(child);
assert_eq!(345, base.id());
assert_eq!(2, base.image().cols());
- base.set_image(Mat::new_rows_cols_with_default(10, 20, f64::typ(), Scalar::from(2.))?);
+ base.set_image(Mat::new_rows_cols_with_default(10, 20, f64::opencv_type(), Scalar::from(2.))?);
let child = OdometryFrame::try_from(base)?;
assert_eq!(345, child.id());
assert_eq!(20, child.image().cols());

MODIFY
tests/core.rs
tests/core.rs
@@ -90,7 +90,7 @@ fn file_storage() -> Result<()> {
/// Make sure that arguments to min_max_loc are nullable
#[test]
fn min_max_loc() -> Result<()> {
- let mut m = Mat::new_rows_cols_with_default(10, 10, Vec3b::typ(), Scalar::all(5.))?;
+ let mut m = Mat::new_rows_cols_with_default(10, 10, Vec3b::opencv_type(), Scalar::all(5.))?;
let (mut min_val, mut max_val) = (90., 90.);
*m.at_2d_mut(5, 5)? = Vec3b::from([10, 20, 30]);
core::min_max_loc(&m, Some(&mut min_val), Some(&mut max_val), None, None, &core::no_array())?;

MODIFY
tests/imgcodecs.rs
tests/imgcodecs.rs
@@ -27,7 +27,7 @@ fn decode() -> Result<()> {
Mat::new_rows_cols_with_data(
1,
PIXEL.len() as _,
- u8::typ(),
+ u8::opencv_type(),
bytes.as_mut_ptr() as *mut c_void,
core::Mat_AUTO_STEP,
)

MODIFY
tests/imgproc.rs
tests/imgproc.rs
@@ -10,7 +10,7 @@ use opencv::{
#[test]
fn min_enclosing() -> Result<()> {
- let mut pts = Mat::new_rows_cols_with_default(1, 2, Vec2f::typ(), Scalar::default())?;
+ let mut pts = Mat::new_rows_cols_with_default(1, 2, Vec2f::opencv_type(), Scalar::default())?;
let points = pts.at_row_mut::<Vec2f>(0)?;
points[0].copy_from_slice(&[10., 10.]);
points[1].copy_from_slice(&[20., 10.]);
@@ -45,7 +45,7 @@ fn get_rotation_matrix_2d() -> Result<()> {
#[test]
fn line_iterator() -> Result<()> {
let mut data = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12u8];
- let mat = unsafe { Mat::new_rows_cols_with_data(4, 3, u8::typ(), data.as_mut_ptr() as *mut _, Mat_AUTO_STEP) }?;
+ let mat = unsafe { Mat::new_rows_cols_with_data(4, 3, u8::opencv_type(), data.as_mut_ptr() as *mut _, Mat_AUTO_STEP) }?;
let mut line_iter = imgproc::LineIterator::new(&mat, Point::new(0, 0), Point::new(2, 2), 8, false)?;
assert_eq!(3, line_iter.count());
assert_eq!(Point::new(0, 0), line_iter.pos()?);

MODIFY
tests/input_output_array.rs
tests/input_output_array.rs
@@ -13,7 +13,7 @@ use opencv::{
#[test]
fn input_array() -> Result<()> {
- let mat = Mat::new_rows_cols_with_default(10, 10, u8::typ(), Scalar::all(1.))?;
+ let mat = Mat::new_rows_cols_with_default(10, 10, u8::opencv_type(), Scalar::all(1.))?;
let input_array = mat.input_array()?;
assert_eq!(Scalar::from(100.), core::sum_elems(&input_array)?);
Ok(())
@@ -34,17 +34,17 @@ fn input_output_array_types() -> Result<()> {
assert!(Matx12d::default().input_output_array()?.is_matx()?);
assert!(
- UMat::new_rows_cols_with_default(1, 1, u8::typ(), Scalar::from(8.), UMatUsageFlags::USAGE_DEFAULT)?
+ UMat::new_rows_cols_with_default(1, 1, u8::opencv_type(), Scalar::from(8.), UMatUsageFlags::USAGE_DEFAULT)?
.input_array()?
.is_umat()?
);
assert!(
- UMat::new_rows_cols_with_default(1, 1, u8::typ(), Scalar::from(8.), UMatUsageFlags::USAGE_DEFAULT)?
+ UMat::new_rows_cols_with_default(1, 1, u8::opencv_type(), Scalar::from(8.), UMatUsageFlags::USAGE_DEFAULT)?
.output_array()?
.is_umat()?
);
assert!(
- UMat::new_rows_cols_with_default(1, 1, u8::typ(), Scalar::from(8.), UMatUsageFlags::USAGE_DEFAULT)?
+ UMat::new_rows_cols_with_default(1, 1, u8::opencv_type(), Scalar::from(8.), UMatUsageFlags::USAGE_DEFAULT)?
.input_output_array()?
.is_umat()?
);
@@ -66,8 +66,8 @@ fn input_output_array_types() -> Result<()> {
#[test]
fn input_output_array() -> Result<()> {
{
- let mat_expr = Mat::ones(1, 3, u8::typ())?;
- let mat = Mat::new_rows_cols_with_default(1, 3, u8::typ(), Scalar::all(3.))?;
+ let mat_expr = Mat::ones(1, 3, u8::opencv_type())?;
+ let mat = Mat::new_rows_cols_with_default(1, 3, u8::opencv_type(), Scalar::all(3.))?;
let umat = mat.get_umat(ACCESS_READ, UMatUsageFlags::USAGE_DEFAULT)?;
{
let mut trg = VectorOfu8::new();
@@ -111,7 +111,7 @@ fn no_array() -> Result<()> {
assert!(no_array().empty()?);
{
- let m = Mat::new_rows_cols_with_default(1, 1, u16::typ(), Scalar::all(0.))?;
+ let m = Mat::new_rows_cols_with_default(1, 1, u16::opencv_type(), Scalar::all(0.))?;
assert_matches!(core::mean_std_dev(&m, &mut no_array(), &mut no_array(), &no_array()), Ok(()));
}
Ok(())

MODIFY
tests/marshalling.rs
tests/marshalling.rs
@@ -22,7 +22,7 @@ fn simple_struct_arg() -> Result<()> {
#[test]
fn scalar_arg() -> Result<()> {
- let mut m = Mat::new_rows_cols_with_default(1, 3, u8::typ(), Scalar::new(2., 0., 0., 0.))?;
+ let mut m = Mat::new_rows_cols_with_default(1, 3, u8::opencv_type(), Scalar::new(2., 0., 0., 0.))?;
let sum = core::sum_elems(&m)?;
assert_eq!(sum[0], 6.);
let s = m.at_row_mut::<u8>(0)?;
@@ -113,7 +113,7 @@ fn callback() -> Result<()> {
fn fixed_array_return() -> Result<()> {
// mutable fixed array return and modification
{
- let m = Mat::new_rows_cols_with_default(5, 3, i32::typ(), Scalar::all(1.))?;
+ let m = Mat::new_rows_cols_with_default(5, 3, i32::opencv_type(), Scalar::all(1.))?;
let mut mat_step = m.mat_step();
assert_eq!([12, 4], *mat_step.buf());
mat_step.buf()[0] = 16;
@@ -231,7 +231,7 @@ fn tuple() -> Result<()> {
use opencv::core::{AccessFlag, UMatUsageFlags};
use opencv::types::TupleOfUMat_u8;
- let mat = Mat::new_rows_cols_with_default(10, 20, f64::typ(), Scalar::all(76.))?;
+ let mat = Mat::new_rows_cols_with_default(10, 20, f64::opencv_type(), Scalar::all(76.))?;
let src_tuple = (mat.get_umat(AccessFlag::ACCESS_READ, UMatUsageFlags::USAGE_DEFAULT)?, 8);
let tuple = TupleOfUMat_u8::new(src_tuple);
assert_eq!(10, tuple.get_0().rows());
@@ -255,7 +255,7 @@ fn tuple() -> Result<()> {
// use opencv::{tracking::TrackerSamplerPF_Params};
// let mut params = TrackerSamplerPF_Params::default()?;
// assert_eq!(&[15., 15., 15., 15.], params.std().data_typed()?);
-// let mat = Mat::new_rows_cols_with_default(1, 4, f64::typ(), Scalar::all(8.))?.try_into_typed::<f64>()?;
+// let mat = Mat::new_rows_cols_with_default(1, 4, f64::opencv_type(), Scalar::all(8.))?.try_into_typed::<f64>()?;
// let mat_src = mat.try_clone()?.try_into_typed::<f64>()?;
// params.set_std(mat);
// let mat = params.std();

MODIFY
tests/mat.rs
tests/mat.rs
@@ -12,9 +12,9 @@ const PIXEL: &[u8] = include_bytes!("pixel.png");
#[test]
fn mat_default() -> Result<()> {
let mat = Mat::default();
- assert_eq!(u8::typ(), mat.typ());
- assert_eq!(u8::depth(), mat.depth());
- assert_eq!(u8::channels(), mat.channels());
+ assert_eq!(u8::opencv_type(), mat.typ());
+ assert_eq!(u8::opencv_depth(), mat.depth());
+ assert_eq!(u8::opencv_channels(), mat.channels());
assert_eq!(Size::new(0, 0), mat.size()?);
assert_eq!(0, mat.dims());
assert!(!mat.is_allocated());
@@ -25,7 +25,7 @@ fn mat_default() -> Result<()> {
#[test]
fn mat_create() -> Result<()> {
let mut mat = Mat::default();
- unsafe { mat.create_rows_cols(10, 10, u16::typ())? };
+ unsafe { mat.create_rows_cols(10, 10, u16::opencv_type())? };
assert!(mat.is_allocated());
assert!(!mat.data().is_null());
mat.set(Scalar::from(7.))?;
@@ -49,7 +49,7 @@ fn mat_from_iter() -> Result<()> {
let mat = Mat::from_exact_iter(vec.into_iter())?;
assert_eq!(3, mat.rows());
assert_eq!(1, mat.cols());
- assert_eq!(i32::typ(), mat.typ());
+ assert_eq!(i32::opencv_type(), mat.typ());
assert_eq!(1, *mat.at_2d::<i32>(0, 0)?);
assert_eq!(2, *mat.at_2d::<i32>(1, 0)?);
assert_eq!(3, *mat.at_2d::<i32>(2, 0)?);
@@ -60,7 +60,7 @@ fn mat_from_iter() -> Result<()> {
let mat = Mat::from_exact_iter(vec.into_iter())?;
assert_eq!(3, mat.rows());
assert_eq!(1, mat.cols());
- assert_eq!(i32::typ(), mat.typ());
+ assert_eq!(i32::opencv_type(), mat.typ());
assert_eq!(1, *mat.at_2d::<i32>(0, 0)?);
assert_eq!(2, *mat.at_2d::<i32>(1, 0)?);
assert_eq!(3, *mat.at_2d::<i32>(2, 0)?);
@@ -70,10 +70,10 @@ fn mat_from_iter() -> Result<()> {
#[test]
fn mat_for_rows_and_cols() -> Result<()> {
- let mat = unsafe { Mat::new_rows_cols(400, 300, Vec3d::typ()) }?;
- assert_eq!(Vec3d::typ(), mat.typ());
- assert_eq!(Vec3d::depth(), mat.depth());
- assert_eq!(Vec3d::channels(), mat.channels());
+ let mat = unsafe { Mat::new_rows_cols(400, 300, Vec3d::opencv_type()) }?;
+ assert_eq!(Vec3d::opencv_type(), mat.typ());
+ assert_eq!(Vec3d::opencv_depth(), mat.depth());
+ assert_eq!(Vec3d::opencv_channels(), mat.channels());
assert!(mat.is_continuous());
assert!(!mat.is_submatrix());
assert_eq!(Size::new(300, 400), mat.size()?);
@@ -97,7 +97,7 @@ fn mat_for_rows_and_cols() -> Result<()> {
#[test]
fn mat_nd() -> Result<()> {
{
- let mut mat = Mat::new_nd_with_default(&[3, 3, 3], Vec4w::typ(), Scalar::default())?;
+ let mut mat = Mat::new_nd_with_default(&[3, 3, 3], Vec4w::opencv_type(), Scalar::default())?;
assert_matches!(
mat.at::<Vec4w>(0),
Err(Error {
@@ -115,7 +115,7 @@ fn mat_nd() -> Result<()> {
{
let dims = VectorOfi32::from_iter(vec![2, 3, 4, 5, 6, 7]);
- let mut mat = Mat::new_nd_vec_with_default(&dims, Vec4w::typ(), Scalar::default())?;
+ let mut mat = Mat::new_nd_vec_with_default(&dims, Vec4w::opencv_type(), Scalar::default())?;
assert_eq!(-1, mat.rows());
assert_eq!(-1, mat.cols());
assert_matches!(
@@ -293,7 +293,7 @@ fn mat_at_1d() -> Result<()> {
#[test]
fn mat_2d_i0_is_rows_i1_is_cols() -> Result<()> {
// Just a sanity check about which Mat dimension corresponds to which in Size
- let mat = Mat::new_size_with_default(Size::new(6, 5), f32::typ(), Scalar::from(1.23))?;
+ let mat = Mat::new_size_with_default(Size::new(6, 5), f32::opencv_type(), Scalar::from(1.23))?;
let size = mat.size()?;
assert_eq!(size.width, 6);
assert_eq!(size.height, 5);
@@ -302,7 +302,7 @@ fn mat_2d_i0_is_rows_i1_is_cols() -> Result<()> {
#[test]
fn mat_at_2d() -> Result<()> {
- let mut mat = Mat::new_rows_cols_with_default(100, 100, f32::typ(), Scalar::from(1.23))?;
+ let mut mat = Mat::new_rows_cols_with_default(100, 100, f32::opencv_type(), Scalar::from(1.23))?;
assert_eq!(*mat.at_2d::<f32>(0, 0)?, 1.23);
*mat.at_2d_mut::<f32>(0, 0)? = 1.;
assert_eq!(*mat.at_2d::<f32>(0, 0)?, 1.);
@@ -325,7 +325,7 @@ fn mat_at_2d() -> Result<()> {
#[test]
fn mat_at_2d_multichannel() -> Result<()> {
- let mut mat = Mat::new_rows_cols_with_default(100, 100, Vec3f::typ(), Scalar::all(1.23))?;
+ let mut mat = Mat::new_rows_cols_with_default(100, 100, Vec3f::opencv_type(), Scalar::all(1.23))?;
let pix = *mat.at_2d::<Vec3f>(0, 0)?;
assert_eq!(pix[0], 1.23);
assert_eq!(pix[1], 1.23);
@@ -364,7 +364,7 @@ fn mat_at_2d_multichannel() -> Result<()> {
#[test]
fn mat_at_row() -> Result<()> {
- let mut mat = Mat::new_rows_cols_with_default(100, 100, f32::typ(), Scalar::from(1.23))?;
+ let mut mat = Mat::new_rows_cols_with_default(100, 100, f32::opencv_type(), Scalar::from(1.23))?;
let row = mat.at_row::<f32>(0)?;
assert_eq!(row.len(), 100);
@@ -454,7 +454,7 @@ fn mat_vec() -> Result<()> {
dims.push(3);
dims.push(3);
dims.push(3);
- let mut mat = Mat::new_nd_vec_with_default(&dims, f64::typ(), Scalar::from(2.))?;
+ let mut mat = Mat::new_nd_vec_with_default(&dims, f64::opencv_type(), Scalar::from(2.))?;
*mat.at_3d_mut::<f64>(1, 1, 1)? = 10.;
assert_eq!(3, mat.dims());
if mat.to_vec_2d::<f64>().is_ok() {
@@ -545,11 +545,11 @@ fn mat_continuous() -> Result<()> {
#[test]
fn mat_operations() -> Result<()> {
let mut src = VectorOfMat::new();
- src.push(Mat::new_rows_cols_with_default(1, 3, u8::typ(), Scalar::from(1.))?);
- src.push(Mat::new_rows_cols_with_default(1, 3, u8::typ(), Scalar::from(2.))?);
+ src.push(Mat::new_rows_cols_with_default(1, 3, u8::opencv_type(), Scalar::from(1.))?);
+ src.push(Mat::new_rows_cols_with_default(1, 3, u8::opencv_type(), Scalar::from(2.))?);
let mut merged = Mat::default();
core::merge(&src, &mut merged)?;
- assert_eq!(merged.typ(), Vec2b::typ());
+ assert_eq!(merged.typ(), Vec2b::opencv_type());
assert_eq!(merged.at_2d::<Vec2b>(0, 1)?[0], 1);
assert_eq!(merged.at_2d::<Vec2b>(0, 2)?[1], 2);
@@ -557,11 +557,11 @@ fn mat_operations() -> Result<()> {
core::split(&merged, &mut split)?;
assert_eq!(2, split.len());
let mat = split.get(0)?;
- assert_eq!(u8::typ(), mat.typ());
+ assert_eq!(u8::opencv_type(), mat.typ());
assert_eq!(1, mat.channels());
assert_eq!(1, *mat.at_2d::<u8>(0, 2)?);
let mat = split.get(1)?;
- assert_eq!(u8::typ(), mat.typ());
+ assert_eq!(u8::opencv_type(), mat.typ());
assert_eq!(1, mat.channels());
assert_eq!(2, *mat.at_2d::<u8>(0, 0)?);
@@ -578,7 +578,7 @@ fn mat_from_data() -> Result<()> {
Mat::new_rows_cols_with_data(
1,
PIXEL.len() as _,
- u8::typ(),
+ u8::opencv_type(),
bytes.as_mut_ptr() as *mut c_void,
core::Mat_AUTO_STEP,
)?
@@ -594,7 +594,7 @@ fn mat_from_data() -> Result<()> {
}
{
- let src = unsafe { Mat::new_nd_with_data(&[3, 5, 6], u8::typ(), bytes.as_mut_ptr() as *mut c_void, None)? };
+ let src = unsafe { Mat::new_nd_with_data(&[3, 5, 6], u8::opencv_type(), bytes.as_mut_ptr() as *mut c_void, None)? };
assert_eq!(Size::new(5, 3), src.size()?);
assert_eq!(PIXEL.len(), src.total());
assert_eq!(0x89, *src.at_3d::<u8>(0, 0, 0)?);
@@ -610,7 +610,7 @@ fn mat_from_data() -> Result<()> {
Mat::new_rows_cols_with_data(
1,
bytes.len() as i32,
- u8::typ(),
+ u8::opencv_type(),
bytes.as_mut_ptr() as *mut c_void,
core::Mat_AUTO_STEP,
)?
@@ -638,7 +638,7 @@ fn mat_from_data() -> Result<()> {
#[test]
fn mat_from_matexpr() -> Result<()> {
{
- let mat = Mat::zeros(3, 4, f32::typ())?.to_mat()?;
+ let mat = Mat::zeros(3, 4, f32::opencv_type())?.to_mat()?;
assert_eq!(4, mat.cols());
assert_eq!(3, mat.rows());
assert_eq!(0., *mat.at_2d::<f32>(0, 0)?);
@@ -647,7 +647,7 @@ fn mat_from_matexpr() -> Result<()> {
}
{
- let mat = Mat::ones_nd(&[6, 5], f32::typ())?.to_mat()?;
+ let mat = Mat::ones_nd(&[6, 5], f32::opencv_type())?.to_mat()?;
assert_eq!(5, mat.cols());
assert_eq!(6, mat.rows());
assert_eq!(1., *mat.at_2d::<f32>(0, 0)?);
@@ -744,29 +744,29 @@ fn mat_convert() -> Result<()> {
#[test]
fn mat_mul() -> Result<()> {
{
- let expr = Mat::ones(1, 5, f64::typ())?;
+ let expr = Mat::ones(1, 5, f64::opencv_type())?;
let res = core::mul_matexpr_f64(&expr, 4.)?.to_mat()?;
- assert_eq!(res.typ(), f64::typ());
+ assert_eq!(res.typ(), f64::opencv_type());
assert_eq!(res.data_typed::<f64>()?, &[4., 4., 4., 4., 4.]);
}
{
- let expr = Mat::new_rows_cols_with_default(2, 3, i32::typ(), Scalar::from(9.))?;
+ let expr = Mat::new_rows_cols_with_default(2, 3, i32::opencv_type(), Scalar::from(9.))?;
let res = core::sub_mat_scalar(&expr, Scalar::from(5.))?.to_mat()?;
- assert_eq!(res.typ(), i32::typ());
+ assert_eq!(res.typ(), i32::opencv_type());
assert_eq!(res.data_typed::<i32>()?, &[4, 4, 4, 4, 4, 4]);
}
{
let mat1 = Mat::from_slice_2d(&[[1f32, 2., 3.], [4., 5., 6.]])?;
let mat2 = Mat::from_slice_2d(&[[7f32, 8.], [9., 10.], [11., 12.]])?;
let res = core::mul_mat_mat(&mat1, &mat2)?.to_mat()?;
- assert_eq!(res.typ(), f32::typ());
+ assert_eq!(res.typ(), f32::opencv_type());
assert_eq!(res.size()?, Size::new(2, 2));
assert_eq!(res.data_typed::<f32>()?, &[58., 64., 139., 154.]);
}
{
let mat = Mat::from_slice(&[1u8, 2, 3, 4, 5, 6])?;
let res = core::div_mat_f64(&mat, 2.)?.to_mat()?;
- assert_eq!(res.typ(), u8::typ());
+ assert_eq!(res.typ(), u8::opencv_type());
assert_eq!(res.data_typed::<u8>()?, &[0, 1, 2, 2, 2, 3]);
}
Ok(())
@@ -806,9 +806,9 @@ fn mat_data() -> Result<()> {
#[test]
fn mat_equals() -> Result<()> {
- let mat1 = Mat::new_rows_cols_with_default(3, 3, i32::typ(), Scalar::all(0.))?;
- let mat2 = Mat::new_rows_cols_with_default(3, 3, i32::typ(), Scalar::all(0.))?;
- let mat3 = Mat::new_rows_cols_with_default(3, 3, i32::typ(), Scalar::all(1.))?;
+ let mat1 = Mat::new_rows_cols_with_default(3, 3, i32::opencv_type(), Scalar::all(0.))?;
+ let mat2 = Mat::new_rows_cols_with_default(3, 3, i32::opencv_type(), Scalar::all(0.))?;
+ let mat3 = Mat::new_rows_cols_with_default(3, 3, i32::opencv_type(), Scalar::all(1.))?;
let res = core::equals_mat_mat(&mat1, &mat2)?.to_mat()?;
assert!(res.data_typed::<u8>()?.iter().all(|&e| e != 0));
let res = core::equals_mat_mat(&mat1, &mat3)?.to_mat()?;
@@ -819,7 +819,7 @@ fn mat_equals() -> Result<()> {
#[test]
fn mat_rgb() -> Result<()> {
#![cfg(feature = "rgb")]
- let m = Mat::new_rows_cols_with_default(3, 3, rgb::RGBA8::typ(), Scalar::all(1.))?;
+ let m = Mat::new_rows_cols_with_default(3, 3, rgb::RGBA8::opencv_type(), Scalar::all(1.))?;
assert_eq!(rgb::RGBA::new(1, 1, 1, 1), *m.at_2d(1, 1)?);
assert_matches!(
m.at_2d::<rgb::RGB8>(1, 1),

MODIFY
tests/ml.rs
tests/ml.rs
@@ -11,8 +11,8 @@ use opencv::{
fn knn() -> Result<()> {
let mut knn = <dyn KNearest>::create()?;
assert!(StatModelConst::empty(&knn)?);
- let samp = Mat::new_rows_cols_with_default(1, 1, f32::typ(), Scalar::all(1.))?;
- let resp = Mat::new_rows_cols_with_default(1, 1, f32::typ(), Scalar::all(2.))?;
+ let samp = Mat::new_rows_cols_with_default(1, 1, f32::opencv_type(), Scalar::all(1.))?;
+ let resp = Mat::new_rows_cols_with_default(1, 1, f32::opencv_type(), Scalar::all(2.))?;
knn.train(&samp, ml::ROW_SAMPLE, &resp)?;
let mut resp = Mat::default();
let mut neigh = Mat::default();

MODIFY
tests/slice.rs
tests/slice.rs
@@ -2,7 +2,7 @@ use opencv::{core::SparseMat_Hdr, prelude::*, Result};
#[test]
fn slice_override() -> Result<()> {
- let mut hdr = SparseMat_Hdr::new(&[4, 2], i32::typ())?;
+ let mut hdr = SparseMat_Hdr::new(&[4, 2], i32::opencv_type())?;
assert_eq!(4, hdr.size()[0]);
assert_eq!(2, hdr.size()[1]);
assert_eq!(0, hdr.size()[2]);

MODIFY
tests/umat.rs
tests/umat.rs
@@ -12,9 +12,9 @@ use opencv::{
#[test]
fn umat_default() -> Result<()> {
let mat = UMat::new(UMatUsageFlags::USAGE_DEFAULT);
- assert_eq!(u8::typ(), mat.typ());
- assert_eq!(u8::depth(), mat.depth());
- assert_eq!(u8::channels(), mat.channels());
+ assert_eq!(u8::opencv_type(), mat.typ());
+ assert_eq!(u8::opencv_depth(), mat.depth());
+ assert_eq!(u8::opencv_channels(), mat.channels());
assert_eq!(Size::new(0, 0), mat.size()?);
assert_eq!(0, mat.dims());
Ok(())
@@ -23,7 +23,7 @@ fn umat_default() -> Result<()> {
#[test]
fn umat_create() -> Result<()> {
let mut mat = UMat::new(UMatUsageFlags::USAGE_DEFAULT);
- unsafe { mat.create_rows_cols(10, 10, u16::typ(), UMatUsageFlags::USAGE_DEFAULT)? };
+ unsafe { mat.create_rows_cols(10, 10, u16::opencv_type(), UMatUsageFlags::USAGE_DEFAULT)? };
assert_eq!(Size::new(10, 10), mat.size()?);
assert_eq!(2, mat.dims());
Ok(())
@@ -40,7 +40,7 @@ fn umat_to_mat() -> Result<()> {
let umat = mat.get_umat(ACCESS_READ, UMatUsageFlags::USAGE_DEFAULT)?;
assert_eq!(3, umat.rows());
assert_eq!(1, umat.cols());
- assert_eq!(i32::typ(), umat.typ());
+ assert_eq!(i32::opencv_type(), umat.typ());
let mat = umat.get_mat(ACCESS_READ)?;
assert_eq!(1, *mat.at_2d::<i32>(0, 0)?);
assert_eq!(2, *mat.at_2d::<i32>(1, 0)?);
@@ -53,7 +53,7 @@ fn umat_to_mat() -> Result<()> {
let umat = mat.get_umat(ACCESS_READ, UMatUsageFlags::USAGE_DEFAULT)?;
assert_eq!(3, umat.rows());
assert_eq!(1, umat.cols());
- assert_eq!(i32::typ(), umat.typ());
+ assert_eq!(i32::opencv_type(), umat.typ());
let mat = umat.get_mat(ACCESS_READ)?;
assert_eq!(1, *mat.at_2d::<i32>(0, 0)?);
assert_eq!(2, *mat.at_2d::<i32>(1, 0)?);
@@ -64,10 +64,10 @@ fn umat_to_mat() -> Result<()> {
#[test]
fn umat_for_rows_and_cols() -> Result<()> {
- let mat = unsafe { UMat::new_rows_cols(400, 300, Vec3d::typ(), UMatUsageFlags::USAGE_DEFAULT) }?;
- assert_eq!(Vec3d::typ(), mat.typ());
- assert_eq!(Vec3d::depth(), mat.depth());
- assert_eq!(Vec3d::channels(), mat.channels());
+ let mat = unsafe { UMat::new_rows_cols(400, 300, Vec3d::opencv_type(), UMatUsageFlags::USAGE_DEFAULT) }?;
+ assert_eq!(Vec3d::opencv_type(), mat.typ());
+ assert_eq!(Vec3d::opencv_depth(), mat.depth());
+ assert_eq!(Vec3d::opencv_channels(), mat.channels());
assert!(mat.is_continuous());
assert!(!mat.is_submatrix());
assert_eq!(Size::new(300, 400), mat.size()?);

MODIFY
tests/vector.rs
tests/vector.rs
@@ -14,26 +14,26 @@ use opencv::{
fn boxed() -> Result<()> {
{
let mut vec = VectorOfMat::new();
- vec.push(Mat::new_rows_cols_with_default(1, 3, u8::typ(), Scalar::all(1.))?);
- vec.push(Mat::new_rows_cols_with_default(1, 3, u16::typ(), Scalar::all(2.))?);
- vec.push(Mat::new_rows_cols_with_default(1, 3, i32::typ(), Scalar::all(3.))?);
+ vec.push(Mat::new_rows_cols_with_default(1, 3, u8::opencv_type(), Scalar::all(1.))?);
+ vec.push(Mat::new_rows_cols_with_default(1, 3, u16::opencv_type(), Scalar::all(2.))?);
+ vec.push(Mat::new_rows_cols_with_default(1, 3, i32::opencv_type(), Scalar::all(3.))?);
assert_eq!(3, vec.len());
- assert_eq!(u8::typ(), vec.get(0)?.typ());
+ assert_eq!(u8::opencv_type(), vec.get(0)?.typ());
assert_eq!(1, *vec.get(0)?.at_2d::<u8>(0, 1)?);
- assert_eq!(u16::typ(), vec.get(1)?.typ());
+ assert_eq!(u16::opencv_type(), vec.get(1)?.typ());
assert_eq!(2, *vec.get(1)?.at_2d::<u16>(0, 1)?);
- assert_eq!(i32::typ(), vec.get(2)?.typ());
+ assert_eq!(i32::opencv_type(), vec.get(2)?.typ());
assert_eq!(3, *vec.get(2)?.at_2d::<i32>(0, 1)?);
- vec.set(0, Mat::new_rows_cols_with_default(1, 3, f32::typ(), Scalar::all(3.))?)?;
+ vec.set(0, Mat::new_rows_cols_with_default(1, 3, f32::opencv_type(), Scalar::all(3.))?)?;
unsafe {
- vec.set_unchecked(1, Mat::new_rows_cols_with_default(1, 3, f64::typ(), Scalar::all(4.))?);
+ vec.set_unchecked(1, Mat::new_rows_cols_with_default(1, 3, f64::opencv_type(), Scalar::all(4.))?);
}
- vec.set(2, Mat::new_rows_cols_with_default(1, 3, i16::typ(), Scalar::all(5.))?)?;
- assert_eq!(f32::typ(), unsafe { vec.get_unchecked(0) }.typ());
+ vec.set(2, Mat::new_rows_cols_with_default(1, 3, i16::opencv_type(), Scalar::all(5.))?)?;
+ assert_eq!(f32::opencv_type(), unsafe { vec.get_unchecked(0) }.typ());
assert_eq!(3., *unsafe { vec.get_unchecked(0) }.at_2d::<f32>(0, 1)?);
- assert_eq!(f64::typ(), unsafe { vec.get_unchecked(1) }.typ());
+ assert_eq!(f64::opencv_type(), unsafe { vec.get_unchecked(1) }.typ());
assert_eq!(4., *unsafe { vec.get_unchecked(1) }.at_2d::<f64>(0, 1)?);
- assert_eq!(i16::typ(), unsafe { vec.get_unchecked(2) }.typ());
+ assert_eq!(i16::opencv_type(), unsafe { vec.get_unchecked(2) }.typ());
assert_eq!(5, *unsafe { vec.get_unchecked(2) }.at_2d::<i16>(0, 1)?);
}
@@ -44,10 +44,10 @@ fn boxed() -> Result<()> {
imgproc,
};
- let mut m = Mat::new_rows_cols_with_default(10, 10, Vec3b::typ(), Scalar::default())?;
+ let mut m = Mat::new_rows_cols_with_default(10, 10, Vec3b::opencv_type(), Scalar::default())?;
let mut ps = VectorOfMat::new();
assert_eq!(ps.len(), 0);
- let mut p1 = unsafe { Mat::new_rows_cols(3, 2, i32::typ()) }?;
+ let mut p1 = unsafe { Mat::new_rows_cols(3, 2, i32::opencv_type()) }?;
p1.at_row_mut::<i32>(0)?.copy_from_slice(&[0, 0]);
p1.at_row_mut::<i32>(1)?.copy_from_slice(&[0, 9]);
p1.at_row_mut::<i32>(2)?.copy_from_slice(&[9, 9]);
@@ -616,8 +616,8 @@ fn to_vec() -> Result<()> {
}
{
let mut vec = VectorOfMat::new();
- vec.push(Mat::new_rows_cols_with_default(5, 8, u16::typ(), Scalar::all(8.))?);
- vec.push(Mat::new_rows_cols_with_default(3, 3, u8::typ(), Scalar::all(19.))?);
+ vec.push(Mat::new_rows_cols_with_default(5, 8, u16::opencv_type(), Scalar::all(8.))?);
+ vec.push(Mat::new_rows_cols_with_default(3, 3, u8::opencv_type(), Scalar::all(19.))?);
let mat_vec = vec.to_vec();
assert_eq!(vec.get(0)?.total(), mat_vec[0].total());
assert_eq!(vec.get(0)?.typ(), mat_vec[0].typ());
@@ -632,7 +632,7 @@ fn to_vec() -> Result<()> {
#[test]
fn property() -> Result<()> {
- let mut hdr = SparseMat_Hdr::new(&[4, 2], i32::typ())?;
+ let mut hdr = SparseMat_Hdr::new(&[4, 2], i32::opencv_type())?;
#[inline(never)]
fn f(hdr: &mut SparseMat_Hdr, pool: VectorOfu8) {
hdr.set_pool(pool);
@@ -681,8 +681,8 @@ fn clone() -> Result<()> {
}
{
let mut src = vec![
- Mat::new_rows_cols_with_default(10, 20, f64::typ(), Scalar::from(10.))?,
- Mat::new_rows_cols_with_default(5, 8, i32::typ(), Scalar::from(20.))?,
+ Mat::new_rows_cols_with_default(10, 20, f64::opencv_type(), Scalar::from(10.))?,
+ Mat::new_rows_cols_with_default(5, 8, i32::opencv_type(), Scalar::from(20.))?,
];
let src_clone = src.clone();
assert_eq!(20, *src[1].at_2d::<i32>(2, 2)?);
@@ -699,7 +699,10 @@ fn clone() -> Result<()> {
assert_eq!(20, *boxed_clone.get(1)?.at_2d::<i32>(2, 2)?);
boxed.remove(1)?;
assert_eq!(boxed.len() + 1, boxed_clone.len());
- boxed.set(0, Mat::new_rows_cols_with_default(40, 50, f64::typ(), Scalar::from(40.))?)?;
+ boxed.set(
+ 0,
+ Mat::new_rows_cols_with_default(40, 50, f64::opencv_type(), Scalar::from(40.))?,
+ )?;
assert_eq!(40., *boxed.get(0)?.at_2d::<f64>(2, 2)?);
assert_eq!(10., *boxed_clone.get(0)?.at_2d::<f64>(2, 2)?);
drop(boxed);

Rename typ(), channels(), depth() to opencv_type(), opencv_channels(), opencv_depth()