Mark more simple functions as infallible
MODIFY
binding-generator/src/settings.rs
binding-generator/src/settings.rs
@@ -813,6 +813,33 @@ pub static FORCE_CONSTANT_METHOD: Lazy<HashSet<&str>> = Lazy::new(|| hashset! {
});
pub static FORCE_INFALLIBLE: Lazy<HashSet<FuncId>> = Lazy::new(|| hashset! {
+ // just returns static/constant data
+ FuncId::new("cv::noArray", []),
+ FuncId::new("cv::getVersionMajor", []),
+ FuncId::new("cv::getVersionMinor", []),
+ FuncId::new("cv::getVersionRevision", []),
+ // not doing anything that can cause an exception
+ FuncId::new("cv::Mat::empty", []),
+ FuncId::new("cv::Mat::total", []),
+ FuncId::new("cv::Mat::isContinuous", []),
+ FuncId::new("cv::Mat::isSubmatrix", []),
+ FuncId::new("cv::Mat::elemSize1", []),
+ FuncId::new("cv::Mat::type", []),
+ FuncId::new("cv::Mat::depth", []),
+ FuncId::new("cv::Mat::channels", []),
+ FuncId::new("cv::UMat::empty", []),
+ FuncId::new("cv::UMat::total", []),
+ FuncId::new("cv::UMat::isContinuous", []),
+ FuncId::new("cv::UMat::isSubmatrix", []),
+ FuncId::new("cv::UMat::elemSize1", []),
+ FuncId::new("cv::UMat::type", []),
+ FuncId::new("cv::UMat::depth", []),
+ FuncId::new("cv::UMat::channels", []),
+ FuncId::new("cv::SparseMat::elemSize", []),
+ FuncId::new("cv::SparseMat::elemSize1", []),
+ FuncId::new("cv::SparseMat::type", []),
+ FuncId::new("cv::SparseMat::depth", []),
+ FuncId::new("cv::SparseMat::channels", []),
// marked CV_NOEXCEPT since OpenCV 4.5.2, propagate those changes to earlier versions
FuncId::new("cv::Mat::Mat", []),
FuncId::new("cv::MatSize::MatSize", ["_p"]),

MODIFY
ci/test-proj-clang-runtime/src/main.rs
ci/test-proj-clang-runtime/src/main.rs
@@ -2,5 +2,5 @@ use opencv::prelude::*;
fn main() {
let m = Mat::default();
- println!("{}", m.typ().unwrap());
+ println!("{}", m.typ());
}

MODIFY
examples/discrete_fourier_transform.rs
examples/discrete_fourier_transform.rs
@@ -13,7 +13,7 @@ fn main() -> opencv::Result<()> {
#![allow(non_snake_case)]
let filename = env::args().skip(1).next().expect("Must supply image filename");
let I = imgcodecs::imread(&filename, imgcodecs::IMREAD_GRAYSCALE)?;
- if I.empty()? {
+ if I.empty() {
panic!("Error opening image: {}", filename);
}
let mut padded = Mat::default();
@@ -35,7 +35,7 @@ fn main() -> opencv::Result<()> {
let mut magI = Mat::default();
core::magnitude(&planes.get(0)?, &planes.get(1)?, &mut magI)?;
let mut magI_tmp = Mat::default();
- core::add(&magI, &Scalar::all(1.), &mut magI_tmp, &core::no_array()?, -1)?;
+ core::add(&magI, &Scalar::all(1.), &mut magI_tmp, &core::no_array(), -1)?;
magI = magI_tmp;
let mut magI_log = Mat::default();
core::log(&magI, &mut magI_log)?;
@@ -54,7 +54,7 @@ fn main() -> opencv::Result<()> {
q2.copy_to(&mut q1)?;
tmp.copy_to(&mut q2)?;
let mut magI_tmp = Mat::default();
- core::normalize(&magI, &mut magI_tmp, 0., 1., core::NORM_MINMAX, -1, &core::no_array()?)?;
+ core::normalize(&magI, &mut magI_tmp, 0., 1., core::NORM_MINMAX, -1, &core::no_array())?;
let magI = magI_tmp;
highgui::imshow("Input Image", &I)?;
highgui::imshow("spectrum magnitude", &magI)?;

MODIFY
src/manual/core/mat.rs
src/manual/core/mat.rs
@@ -69,7 +69,7 @@ fn match_indices(mat: &(impl MatTraitConst + ?Sized), idx: &[i32]) -> Result<()>
#[inline]
fn match_total(mat: &(impl MatTraitConst + ?Sized), idx: i32) -> Result<()> {
- let size = mat.total()?;
+ let size = mat.total();
if 0 <= idx && (idx as usize) < size {
Ok(())
} else {
@@ -79,7 +79,7 @@ fn match_total(mat: &(impl MatTraitConst + ?Sized), idx: i32) -> Result<()> {
#[inline]
fn match_is_continuous(mat: &(impl MatTraitConst + ?Sized)) -> Result<()> {
- if mat.is_continuous()? {
+ if mat.is_continuous() {
Ok(())
} else {
Err(Error::new(core::StsUnmatchedSizes, "Mat is not continuous, operation is not applicable".to_string()))
@@ -88,7 +88,7 @@ fn match_is_continuous(mat: &(impl MatTraitConst + ?Sized)) -> Result<()> {
#[inline(always)]
fn idx_to_row_col(mat: &(impl MatTraitConst + ?Sized), i0: i32) -> Result<(i32, i32)> {
- Ok(if mat.is_continuous()? {
+ Ok(if mat.is_continuous() {
(0, i0)
} else {
let mat_size = mat.size()?;
@@ -148,7 +148,7 @@ pub(crate) mod mat_forward {
#[inline]
pub fn at<T: DataType>(mat: &(impl MatTraitConst + ?Sized), i0: i32) -> Result<&T> {
- match_format::<T>(mat.typ()?)
+ match_format::<T>(mat.typ())
.and_then(|_| match_dims(mat, 2))
.and_then(|_| match_total(mat, i0))
.and_then(|_| unsafe { mat.at_unchecked(i0) })
@@ -156,7 +156,7 @@ pub(crate) mod mat_forward {
#[inline]
pub fn at_mut<T: DataType>(mat: &mut (impl MatTrait + ?Sized), i0: i32) -> Result<&mut T> {
- match_format::<T>(mat.typ()?)
+ match_format::<T>(mat.typ())
.and_then(|_| match_dims(mat, 2))
.and_then(|_| match_total(mat, i0))?;
unsafe { mat.at_unchecked_mut(i0) }
@@ -164,14 +164,14 @@ pub(crate) mod mat_forward {
#[inline]
pub fn at_2d<T: DataType>(mat: &(impl MatTraitConst + ?Sized), row: i32, col: i32) -> Result<&T> {
- match_format::<T>(mat.typ()?)
+ match_format::<T>(mat.typ())
.and_then(|_| match_indices(mat, &[row, col]))
.and_then(|_| unsafe { mat.at_2d_unchecked(row, col) })
}
#[inline]
pub fn at_2d_mut<T: DataType>(mat: &mut (impl MatTrait + ?Sized), row: i32, col: i32) -> Result<&mut T> {
- match_format::<T>(mat.typ()?)
+ match_format::<T>(mat.typ())
.and_then(|_| match_indices(mat, &[row, col]))?;
unsafe { mat.at_2d_unchecked_mut(row, col) }
}
@@ -188,28 +188,28 @@ pub(crate) mod mat_forward {
#[inline]
pub fn at_3d<T: DataType>(mat: &(impl MatTraitConst + ?Sized), i0: i32, i1: i32, i2: i32) -> Result<&T> {
- match_format::<T>(mat.typ()?)
+ match_format::<T>(mat.typ())
.and_then(|_| match_indices(mat, &[i0, i1, i2]))
.and_then(|_| unsafe { mat.at_3d_unchecked(i0, i1, i2) })
}
#[inline]
pub fn at_3d_mut<T: DataType>(mat: &mut (impl MatTrait + ?Sized), i0: i32, i1: i32, i2: i32) -> Result<&mut T> {
- match_format::<T>(mat.typ()?)
+ match_format::<T>(mat.typ())
.and_then(|_| match_indices(mat, &[i0, i1, i2]))?;
unsafe { mat.at_3d_unchecked_mut(i0, i1, i2) }
}
#[inline]
pub fn at_nd<'s, T: core::DataType>(mat: &'s (impl MatTraitConst + ?Sized), idx: &[i32]) -> Result<&'s T> {
- match_format::<T>(mat.typ()?)
+ match_format::<T>(mat.typ())
.and_then(|_| match_indices(mat, idx))
.and_then(|_| unsafe { mat.at_nd_unchecked(idx) })
}
#[inline]
pub fn at_nd_mut<'s, T: core::DataType>(mat: &'s mut (impl MatTrait + ?Sized), idx: &[i32]) -> Result<&'s mut T> {
- match_format::<T>(mat.typ()?)
+ match_format::<T>(mat.typ())
.and_then(|_| match_indices(mat, idx))?;
unsafe { mat.at_nd_unchecked_mut(idx) }
}
@@ -223,7 +223,7 @@ pub trait MatTraitConstManual: MatTraitConst {
#[inline]
unsafe fn at_unchecked<T: DataType>(&self, i0: i32) -> Result<&T> {
let mat_size = self.size()?;
- let (i, j) = if self.is_continuous()? || mat_size.width == 1 {
+ let (i, j) = if self.is_continuous() || mat_size.width == 1 {
(0, i0)
} else if mat_size.height == 1 {
(i0, 0)
@@ -273,7 +273,7 @@ pub trait MatTraitConstManual: MatTraitConst {
/// Return a complete read-only row
#[inline]
fn at_row<T: DataType>(&self, row: i32) -> Result<&[T]> {
- match_format::<T>(self.typ()?)
+ match_format::<T>(self.typ())
.and_then(|_| match_indices(self, &[row, 0]))
.and_then(|_| unsafe { self.at_row_unchecked(row) })
}
@@ -316,14 +316,14 @@ pub trait MatTraitConstManual: MatTraitConst {
if data.is_null() {
Err(Error::new(core::StsNullPtr, "Function returned null pointer".to_string()))
} else {
- Ok(unsafe { slice::from_raw_parts(data, self.total()? * self.elem_size()?) })
+ Ok(unsafe { slice::from_raw_parts(data, self.total() * self.elem_size()?) })
}
})
}
#[inline]
fn data_typed<T: DataType>(&self) -> Result<&[T]> {
- match_format::<T>(self.typ()?)
+ match_format::<T>(self.typ())
.and_then(|_| match_is_continuous(self))
.and_then(|_| unsafe { self.data_typed_unchecked() })
}
@@ -336,17 +336,17 @@ pub trait MatTraitConstManual: MatTraitConst {
if data.is_null() {
Err(Error::new(core::StsNullPtr, "Function returned null pointer".to_string()))
} else {
- Ok(slice::from_raw_parts(data as *const T, self.total()?))
+ Ok(slice::from_raw_parts(data as *const T, self.total()))
}
}
fn to_vec_2d<T: DataType>(&self) -> Result<Vec<Vec<T>>> {
- match_format::<T>(self.typ()?)
+ match_format::<T>(self.typ())
.and_then(|_| match_dims(self, 2))
.and_then(|_| {
let size = Self::size(self)?;
let width = size.width as usize;
- if self.is_continuous()? {
+ if self.is_continuous() {
let data = self.data_typed()?;
Ok((0..size.height)
.map(|row_n| {
@@ -422,7 +422,7 @@ pub trait MatTraitManual: MatTraitConstManual + MatTrait {
/// Return a complete writeable row
#[inline]
fn at_row_mut<T: DataType>(&mut self, row: i32) -> Result<&mut [T]> {
- match_format::<T>(self.typ()?)
+ match_format::<T>(self.typ())
.and_then(|_| match_indices(self, &[row, 0]))?;
unsafe { self.at_row_unchecked_mut(row) }
}
@@ -453,13 +453,13 @@ pub trait MatTraitManual: MatTraitConstManual + MatTrait {
fn data_bytes_mut(&mut self) -> Result<&mut [u8]> {
match_is_continuous(self)
.and_then(|_| {
- Ok(unsafe { slice::from_raw_parts_mut(self.data_mut(), self.total()? * self.elem_size()?) })
+ Ok(unsafe { slice::from_raw_parts_mut(self.data_mut(), self.total() * self.elem_size()?) })
})
}
#[inline]
fn data_typed_mut<T: DataType>(&mut self) -> Result<&mut [T]> {
- match_format::<T>(self.typ()?)
+ match_format::<T>(self.typ())
.and_then(|_| match_is_continuous(self))?;
unsafe { self.data_typed_unchecked_mut() }
}
@@ -468,7 +468,7 @@ pub trait MatTraitManual: MatTraitConstManual + MatTrait {
/// Caller must ensure that the `T` type argument corresponds to the data stored in the `Mat`
#[inline]
unsafe fn data_typed_unchecked_mut<T: DataType>(&mut self) -> Result<&mut [T]> {
- let total = self.total()?;
+ let total = self.total();
Ok(slice::from_raw_parts_mut(self.data_mut() as *mut u8 as *mut T, total))
}
}
@@ -484,23 +484,23 @@ impl fmt::Debug for Mat {
let typ = self.typ();
let depth = self.depth();
#[cfg(not(ocvrs_opencv_branch_32))]
- let typ = typ.and_then(core::type_to_string);
+ let typ = core::type_to_string(typ).map_err(|_| fmt::Error)?;
#[cfg(not(ocvrs_opencv_branch_32))]
- let depth = depth.and_then(core::depth_to_string);
+ let depth = core::depth_to_string(depth).map_err(|_| fmt::Error)?;
f.debug_struct("Mat")
- .field("type", &typ.map_err(|_| fmt::Error)?)
+ .field("type", &typ)
.field("flags", &self.flags())
- .field("channels", &self.channels().map_err(|_| fmt::Error)?)
- .field("depth", &depth.map_err(|_| fmt::Error)?)
+ .field("channels", &self.channels())
+ .field("depth", &depth)
.field("dims", &self.dims())
.field("size", &self.size().map_err(|_| fmt::Error)?)
.field("rows", &self.rows())
.field("cols", &self.cols())
.field("elem_size", &self.elem_size().map_err(|_| fmt::Error)?)
- .field("elem_size1", &self.elem_size1().map_err(|_| fmt::Error)?)
- .field("total", &self.total().map_err(|_| fmt::Error)?)
- .field("is_continuous", &self.is_continuous().map_err(|_| fmt::Error)?)
- .field("is_submatrix", &self.is_submatrix().map_err(|_| fmt::Error)?)
+ .field("elem_size1", &self.elem_size1())
+ .field("total", &self.total())
+ .field("is_continuous", &self.is_continuous())
+ .field("is_submatrix", &self.is_submatrix())
.finish()
}
}

MODIFY
src/manual/core/mat/mat_.rs
src/manual/core/mat/mat_.rs
@@ -29,7 +29,7 @@ impl<T: DataType> TryFrom<Mat> for Mat_<T> {
#[inline]
fn try_from(mat: Mat) -> Result<Self, Self::Error> {
- match_format::<T>(mat.typ()?)
+ match_format::<T>(mat.typ())
.map(|_| Self { inner: mat, _type: PhantomData })
}
}

MODIFY
tests/boxed.rs
tests/boxed.rs
@@ -16,7 +16,7 @@ fn layout() -> Result<()> {
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()?);
- assert_eq!(mat.typ()?, mat_ref.typ()?);
+ assert_eq!(mat.typ(), mat_ref.typ());
assert_eq!(mat.rows(), mat_ref.rows());
assert_eq!(mat.cols(), mat_ref.cols());
assert_eq!(mat.at_2d::<f32>(0, 1)?, mat_ref.at_2d::<f32>(0, 1)?);
@@ -52,7 +52,7 @@ fn into_raw() -> Result<()> {
let a = Mat::new_rows_cols_with_default(10, 10, u16::typ(), Scalar::all(9.))?;
let ptr = into_raw(a);
let b = unsafe { Mat::from_raw(ptr) };
- assert_eq!(100, b.total()?);
+ assert_eq!(100, b.total());
assert_eq!(9, *b.at_2d::<u16>(9, 9)?);
}

MODIFY
tests/core.rs
tests/core.rs
@@ -101,7 +101,7 @@ fn min_max_loc() -> Result<()> {
let mut m = Mat::new_rows_cols_with_default(10, 10, Vec3b::typ(), 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()?)?;
+ core::min_max_loc(&m, Some(&mut min_val), Some(&mut max_val), None, None, &core::no_array())?;
assert_eq!(5., min_val);
assert_eq!(30., max_val);
Ok(())

MODIFY
tests/imgcodecs.rs
tests/imgcodecs.rs
@@ -17,7 +17,7 @@ fn decode() -> Result<()> {
let src = Mat::from_slice::<u8>(PIXEL)?;
let dest = imgcodecs::imdecode(&src, imgcodecs::IMREAD_COLOR)?;
assert_eq!(dest.size()?, Size::new(1, 1));
- assert_eq!(dest.channels()?, 3);
+ assert_eq!(dest.channels(), 3);
assert_eq!(*dest.at_2d::<Vec3b>(0, 0)?, Vec3b::from([56u8, 56, 191]));
}
@@ -27,7 +27,7 @@ fn decode() -> Result<()> {
let mut dest = Mat::default();
imgcodecs::imdecode_to(&src, imgcodecs::IMREAD_COLOR, &mut dest)?;
assert_eq!(dest.size()?, Size::new(1, 1));
- assert_eq!(dest.channels()?, 3);
+ assert_eq!(dest.channels(), 3);
assert_eq!(*dest.at_2d::<Vec3b>(0, 0)?, Vec3b::from([56u8, 56, 191]));
}

MODIFY
tests/input_output_array.rs
tests/input_output_array.rs
@@ -36,7 +36,7 @@ fn input_output_array() -> Result<()> {
let umat = mat.get_umat(ACCESS_READ, UMatUsageFlags::USAGE_DEFAULT)?;
{
let mut trg = VectorOfu8::new();
- core::add(&mat_expr, &umat, &mut trg, &core::no_array()?, -1)?;
+ core::add(&mat_expr, &umat, &mut trg, &core::no_array(), -1)?;
assert_eq!(3, trg.len());
assert_eq!(4, trg.get(0)?);
assert_eq!(4, trg.get(1)?);
@@ -45,7 +45,7 @@ fn input_output_array() -> Result<()> {
{
let mut trg = VectorOfu8::new();
- core::add(&&mat_expr, &&umat, &mut &mut trg, &core::no_array()?, -1)?;
+ core::add(&&mat_expr, &&umat, &mut &mut trg, &core::no_array(), -1)?;
assert_eq!(3, trg.len());
assert_eq!(4, trg.get(0)?);
assert_eq!(4, trg.get(1)?);
@@ -55,7 +55,7 @@ fn input_output_array() -> Result<()> {
{
let mut t = VectorOff64::new();
- core::add(&2.5, &4., &mut t, &core::no_array()?, -1)?;
+ core::add(&2.5, &4., &mut t, &core::no_array(), -1)?;
assert_eq!(6.5, t.get(0)?);
}
@@ -83,11 +83,11 @@ fn input_output_array() -> Result<()> {
fn no_array() -> Result<()> {
use self::core::no_array;
- assert!(no_array()?.empty()?);
+ assert!(no_array().empty()?);
{
let m = Mat::new_rows_cols_with_default(1, 1, u16::typ(), Scalar::all(0.))?;
- assert_matches!(core::mean_std_dev(&m, &mut no_array()?, &mut no_array()?, &no_array()?), Ok(()));
+ assert_matches!(core::mean_std_dev(&m, &mut no_array(), &mut no_array(), &no_array()), Ok(()));
}
Ok(())
}

MODIFY
tests/marshalling.rs
tests/marshalling.rs
@@ -8,7 +8,7 @@ fn simple_struct_arg() -> Result<()> {
use opencv::{imgproc, core::{Point, Size}};
let res = imgproc::get_structuring_element(imgproc::MORPH_CROSS, Size { width: 100, height: 100 }, Point { x: 50, y: 50 })?;
- assert_eq!(res.typ()?, 0);
+ assert_eq!(res.typ(), 0);
let size = res.size()?;
assert_eq!(size.width, 100);
assert_eq!(size.height, 100);

MODIFY
tests/mat.rs
tests/mat.rs
@@ -15,9 +15,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::typ(), mat.typ());
+ assert_eq!(u8::depth(), mat.depth());
+ assert_eq!(u8::channels(), mat.channels());
assert_eq!(Size::new(0, 0), mat.size()?);
assert_eq!(0, mat.dims());
assert!(!mat.is_allocated());
@@ -52,7 +52,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::typ(), 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)?);
@@ -63,7 +63,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::typ(), 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)?);
@@ -74,11 +74,11 @@ 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()?);
- assert!(mat.is_continuous()?);
- assert!(!mat.is_submatrix()?);
+ assert_eq!(Vec3d::typ(), mat.typ());
+ assert_eq!(Vec3d::depth(), mat.depth());
+ assert_eq!(Vec3d::channels(), mat.channels());
+ assert!(mat.is_continuous());
+ assert!(!mat.is_submatrix());
assert_eq!(Size::new(300, 400), mat.size()?);
assert_eq!(400, mat.rows());
assert_eq!(300, mat.cols());
@@ -90,10 +90,10 @@ fn mat_for_rows_and_cols() -> Result<()> {
assert_eq!(7200, mat.mat_step()[0]);
assert_eq!(24, mat.mat_step()[1]);
assert_eq!(24, mat.elem_size()?);
- assert_eq!(8, mat.elem_size1()?);
+ assert_eq!(8, mat.elem_size1());
assert_eq!(900, mat.step1(0)?);
assert_eq!(3, mat.step1(1)?);
- assert_eq!(120000, mat.total()?);
+ assert_eq!(120000, mat.total());
Ok(())
}
@@ -312,11 +312,11 @@ fn mat_continuous() -> Result<()> {
{
let sub_mat_non_cont = Mat::roi(&mat, Rect::new(1, 1, 2, 2))?;
- assert_eq!(mat.typ()?, sub_mat_non_cont.typ()?);
+ assert_eq!(mat.typ(), sub_mat_non_cont.typ());
assert_eq!(2, sub_mat_non_cont.rows());
assert_eq!(2, sub_mat_non_cont.cols());
- assert!(sub_mat_non_cont.is_submatrix()?);
- assert!(!sub_mat_non_cont.is_continuous()?);
+ assert!(sub_mat_non_cont.is_submatrix());
+ assert!(!sub_mat_non_cont.is_continuous());
assert_eq!(5., *sub_mat_non_cont.at_2d::<f32>(0, 0)?);
assert_eq!(6., *sub_mat_non_cont.at_2d::<f32>(0, 1)?);
assert_eq!(8., *sub_mat_non_cont.at_2d::<f32>(1, 0)?);
@@ -329,11 +329,11 @@ fn mat_continuous() -> Result<()> {
assert_eq!(9., vec[1][1]);
let mat_clone = sub_mat_non_cont.try_clone()?;
- assert_eq!(mat.typ()?, mat_clone.typ()?);
+ assert_eq!(mat.typ(), mat_clone.typ());
assert_eq!(2, mat_clone.rows());
assert_eq!(2, mat_clone.cols());
- assert!(!mat_clone.is_submatrix()?);
- assert!(mat_clone.is_continuous()?);
+ assert!(!mat_clone.is_submatrix());
+ assert!(mat_clone.is_continuous());
assert_eq!(5., *mat_clone.at_2d::<f32>(0, 0)?);
assert_eq!(6., *mat_clone.at_2d::<f32>(0, 1)?);
assert_eq!(8., *mat_clone.at_2d::<f32>(1, 0)?);
@@ -342,11 +342,11 @@ fn mat_continuous() -> Result<()> {
{
let sub_mat_cont = Mat::roi(&mat, Rect::new(0, 1, 3, 2))?;
- assert_eq!(mat.typ()?, sub_mat_cont.typ()?);
+ assert_eq!(mat.typ(), sub_mat_cont.typ());
assert_eq!(2, sub_mat_cont.rows());
assert_eq!(3, sub_mat_cont.cols());
- assert!(sub_mat_cont.is_submatrix()?);
- assert!(sub_mat_cont.is_continuous()?);
+ assert!(sub_mat_cont.is_submatrix());
+ assert!(sub_mat_cont.is_continuous());
assert_eq!(4., *sub_mat_cont.at_2d::<f32>(0, 0)?);
assert_eq!(6., *sub_mat_cont.at_2d::<f32>(0, 2)?);
assert_eq!(7., *sub_mat_cont.at_2d::<f32>(1, 0)?);
@@ -361,7 +361,7 @@ fn mat_continuous() -> Result<()> {
{
let mut sub_mat_non_cont = Mat::roi(&mat, Rect::new(1, 1, 1, 2))?;
- assert!(!sub_mat_non_cont.is_continuous()?);
+ assert!(!sub_mat_non_cont.is_continuous());
assert_matches!(sub_mat_non_cont.data_typed::<f32>(), Err(Error { code: core::StsUnmatchedSizes, .. }));
assert_matches!(sub_mat_non_cont.data_typed_mut::<f32>(), Err(Error { code: core::StsUnmatchedSizes, .. }));
}
@@ -376,7 +376,7 @@ fn mat_operations() -> Result<()> {
src.push(Mat::new_rows_cols_with_default(1, 3, u8::typ(), Scalar::from(2.))?);
let mut merged = Mat::default();
core::merge(&src, &mut merged)?;
- assert_eq!(merged.typ()?, Vec2b::typ());
+ assert_eq!(merged.typ(), Vec2b::typ());
assert_eq!(merged.at_2d::<Vec2b>(0, 1)?[0], 1);
assert_eq!(merged.at_2d::<Vec2b>(0, 2)?[1], 2);
@@ -384,12 +384,12 @@ 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!(1, mat.channels()?);
+ assert_eq!(u8::typ(), 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!(1, mat.channels()?);
+ assert_eq!(u8::typ(), mat.typ());
+ assert_eq!(1, mat.channels());
assert_eq!(2, *mat.at_2d::<u8>(0, 0)?);
Ok(())
@@ -411,7 +411,7 @@ fn mat_from_data() -> Result<()> {
)?
};
assert_eq!(Size::new(PIXEL.len() as _, 1), src.size()?);
- assert_eq!(PIXEL.len(), src.total()?);
+ assert_eq!(PIXEL.len(), src.total());
let row = src.at_row::<u8>(0)?;
assert_eq!(0x89, row[0]);
assert_eq!(0x50, row[1]);
@@ -430,7 +430,7 @@ fn mat_from_data() -> Result<()> {
)?
};
assert_eq!(Size::new(5_, 3), src.size()?);
- assert_eq!(PIXEL.len(), src.total()?);
+ assert_eq!(PIXEL.len(), src.total());
assert_eq!(0x89, *src.at_3d::<u8>(0, 0, 0)?);
assert_eq!(0x50, *src.at_3d::<u8>(0, 0, 1)?);
assert_eq!(0x1A, *src.at_3d::<u8>(0, 1, 0)?);
@@ -495,7 +495,7 @@ fn mat_from_matexpr() -> Result<()> {
fn mat_iterator() -> Result<()> {
let mat = Mat::from_slice(&[1, 2, 3, 4])?;
let mut iter = MatConstIterator::over(&mat)?;
- assert_eq!(iter.typ(), mat.typ()?);
+ assert_eq!(iter.typ(), mat.typ());
assert_eq!(1, *iter.current::<i32>()?);
assert_eq!(Point::new(0, 0), iter.pos()?);
assert!(iter.has_elements());
@@ -541,7 +541,7 @@ fn mat_convert() -> Result<()> {
assert_eq!(3, *mat_.at(2)?);
*mat_.at_mut(3)? = 8;
assert_eq!(8, *mat_.at(3)?);
- assert_eq!(mat.typ()?, mat_.typ()?);
+ assert_eq!(mat.typ(), mat_.typ());
assert_eq!(mat.size()?, mat_.size()?);
let mat_back = mat_.into_untyped();
assert_eq!(mat.size()?, mat_back.size()?);
@@ -553,27 +553,27 @@ fn mat_mul() -> Result<()> {
{
let expr = Mat::ones(1, 5, f64::typ())?;
let res = core::mul_matexpr_f64(&expr, 4.)?.to_mat()?;
- assert_eq!(res.typ()?, f64::typ());
+ assert_eq!(res.typ(), f64::typ());
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 res = core::sub_mat_scalar(&expr, Scalar::from(5.))?.to_mat()?;
- assert_eq!(res.typ()?, i32::typ());
+ assert_eq!(res.typ(), i32::typ());
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::typ());
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::typ());
assert_eq!(res.data_typed::<u8>()?, &[0, 1, 2, 2, 2, 3]);
}
Ok(())

MODIFY
tests/objdetect.rs
tests/objdetect.rs
@@ -22,7 +22,7 @@ fn qr_code() -> Result<()> {
let res = detector.detect_and_decode(&src, &mut pts, &mut straight)?;
assert_eq!(res, "https://crates.io/crates/opencv");
assert_eq!(4, pts.len());
- assert!(!straight.empty()?);
+ assert!(!straight.empty());
}
{
@@ -35,7 +35,7 @@ fn qr_code() -> Result<()> {
let mut straight = Mat::default();
let res = detector.decode(&src, &pts, &mut straight)?;
assert_eq!(res, "https://crates.io/crates/opencv");
- assert!(!straight.empty()?);
+ assert!(!straight.empty());
}
#[cfg(ocvrs_opencv_branch_34)] {
@@ -49,7 +49,7 @@ fn qr_code() -> Result<()> {
let res = objdetect::decode_qr_code(&src, &pts, &mut out, &mut straight)?;
assert!(res);
assert_eq!(out, "https://crates.io/crates/opencv");
- assert!(!straight.empty()?);
+ assert!(!straight.empty());
}
Ok(())
}

MODIFY
tests/umat.rs
tests/umat.rs
@@ -12,9 +12,9 @@ use opencv::core::ACCESS_READ;
#[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::typ(), mat.typ());
+ assert_eq!(u8::depth(), mat.depth());
+ assert_eq!(u8::channels(), mat.channels());
assert_eq!(Size::new(0, 0), mat.size()?);
assert_eq!(0, 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::typ(), 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::typ(), 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)?);
@@ -65,11 +65,11 @@ 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()?);
- assert!(mat.is_continuous()?);
- assert!(!mat.is_submatrix()?);
+ assert_eq!(Vec3d::typ(), mat.typ());
+ assert_eq!(Vec3d::depth(), mat.depth());
+ assert_eq!(Vec3d::channels(), mat.channels());
+ assert!(mat.is_continuous());
+ assert!(!mat.is_submatrix());
assert_eq!(Size::new(300, 400), mat.size()?);
assert_eq!(400, mat.rows());
assert_eq!(300, mat.cols());
@@ -81,10 +81,10 @@ fn umat_for_rows_and_cols() -> Result<()> {
assert_eq!(7200, mat.mat_step()[0]);
assert_eq!(24, mat.mat_step()[1]);
assert_eq!(24, mat.elem_size()?);
- assert_eq!(8, mat.elem_size1()?);
+ assert_eq!(8, mat.elem_size1());
assert_eq!(900, mat.step1(0)?);
assert_eq!(3, mat.step1(1)?);
- assert_eq!(120000, mat.total()?);
+ assert_eq!(120000, mat.total());
Ok(())
}
@@ -101,27 +101,27 @@ fn umat_continuous() -> Result<()> {
{
let sub_umat_non_cont = UMat::roi(&umat, Rect::new(1, 1, 2, 2))?;
- assert_eq!(umat.typ()?, sub_umat_non_cont.typ()?);
+ assert_eq!(umat.typ(), sub_umat_non_cont.typ());
assert_eq!(2, sub_umat_non_cont.rows());
assert_eq!(2, sub_umat_non_cont.cols());
- assert!(sub_umat_non_cont.is_submatrix()?);
- assert!(!sub_umat_non_cont.is_continuous()?);
+ assert!(sub_umat_non_cont.is_submatrix());
+ assert!(!sub_umat_non_cont.is_continuous());
let umat_clone = sub_umat_non_cont.try_clone()?;
- assert_eq!(umat.typ()?, umat_clone.typ()?);
+ assert_eq!(umat.typ(), umat_clone.typ());
assert_eq!(2, umat_clone.rows());
assert_eq!(2, umat_clone.cols());
- assert!(!umat_clone.is_submatrix()?);
- assert!(umat_clone.is_continuous()?);
+ assert!(!umat_clone.is_submatrix());
+ assert!(umat_clone.is_continuous());
}
{
let sub_umat_cont = UMat::roi(&umat, Rect::new(0, 1, 3, 2))?;
- assert_eq!(umat.typ()?, sub_umat_cont.typ()?);
+ assert_eq!(umat.typ(), sub_umat_cont.typ());
assert_eq!(2, sub_umat_cont.rows());
assert_eq!(3, sub_umat_cont.cols());
- assert!(sub_umat_cont.is_submatrix()?);
- assert!(sub_umat_cont.is_continuous()?);
+ assert!(sub_umat_cont.is_submatrix());
+ assert!(sub_umat_cont.is_continuous());
}
Ok(())

MODIFY
tests/vector.rs
tests/vector.rs
@@ -37,20 +37,20 @@ fn boxed() -> Result<()> {
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.))?);
assert_eq!(3, vec.len());
- assert_eq!(u8::typ(), vec.get(0)?.typ()?);
+ assert_eq!(u8::typ(), 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::typ(), 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::typ(), 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.))?)?;
unsafe { vec.set_unchecked(1, Mat::new_rows_cols_with_default(1, 3, f64::typ(), 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()?);
+ assert_eq!(f32::typ(), 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::typ(), 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::typ(), unsafe { vec.get_unchecked(2) }.typ());
assert_eq!(5, *unsafe { vec.get_unchecked(2) }.at_2d::<i16>(0, 1)?);
}
@@ -529,11 +529,11 @@ fn to_vec() -> Result<()> {
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.))?);
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()?);
+ assert_eq!(vec.get(0)?.total(), mat_vec[0].total());
+ assert_eq!(vec.get(0)?.typ(), mat_vec[0].typ());
assert_eq!(vec.get(0)?.at_2d::<u16>(2, 2)?, mat_vec[0].at_2d::<u16>(2, 2)?);
- assert_eq!(vec.get(1)?.total()?, mat_vec[1].total()?);
- assert_eq!(vec.get(1)?.typ()?, mat_vec[1].typ()?);
+ assert_eq!(vec.get(1)?.total(), mat_vec[1].total());
+ assert_eq!(vec.get(1)?.typ(), mat_vec[1].typ());
assert_eq!(vec.get(1)?.at_2d::<u8>(2, 2)?, mat_vec[1].at_2d::<u8>(2, 2)?);
}

Mark more simple functions as infallible