allow using Point as argument to Mat::at()
MODIFY
gen_rust.py
gen_rust.py
@@ -228,6 +228,8 @@ func_rename = {
"cv_Mat_at_int": "at_mut",
"cv_Mat_at_int_int": "at_2d_mut",
"cv_Mat_at_const_int_int": "at_2d",
+ "cv_Mat_at_Point": "at_pt_mut",
+ "cv_Mat_at_const_Point": "at_pt",
"cv_Mat_at_int_int_int": "at_3d_mut",
"cv_Mat_at_const_int_int_int": "at_3d",
"cv_Mat_at_const_int_X": "at_nd_mut",
@@ -763,6 +765,12 @@ func_manual = {
"cv_Mat_at_const_int_int": {
"rust_safe": _forward_const_rust_safe,
},
+ "cv_Mat_at_Point": {
+ "rust_safe": _forward_mut_rust_safe,
+ },
+ "cv_Mat_at_const_Point": {
+ "rust_safe": _forward_const_rust_safe,
+ },
"cv_Mat_at_int_int_int": {
"rust_safe": _forward_mut_rust_safe,
},

MODIFY
src/manual/core/mat.rs
src/manual/core/mat.rs
@@ -17,6 +17,7 @@ use crate::{
MatExpr,
MatSize,
MatStep,
+ Point,
Scalar,
ToInputArray,
ToInputOutputArray,
@@ -287,6 +288,26 @@ impl Mat {
.map(convert_ptr_mut)
}
+ #[inline(always)]
+ pub(crate) fn _at_pt<T: DataType>(&self, pt: Point) -> Result<&T> {
+ self._at_2d(pt.y, pt.x)
+ }
+
+ /// Like `Mat::at_pt()` but performs no bounds or type checks
+ pub unsafe fn at_pt_unchecked<T: DataType>(&self, pt: Point) -> Result<&T> {
+ self.at_2d_unchecked(pt.y, pt.x)
+ }
+
+ #[inline(always)]
+ pub(crate) fn _at_pt_mut<T: DataType>(&mut self, pt: Point) -> Result<&mut T> {
+ self._at_2d_mut(pt.y, pt.x)
+ }
+
+ /// Like `Mat::at_pt_mut()` but performs no bounds or type checks
+ pub unsafe fn at_pt_mut_unchecked<T: DataType>(&mut self, pt: Point) -> Result<&mut T> {
+ self.at_2d_mut_unchecked(pt.y, pt.x)
+ }
+
#[inline(always)]
pub(crate) fn _at_3d<T: DataType>(&self, i0: i32, i1: i32, i2: i32) -> Result<&T> {
self.match_format::<T>()

MODIFY
tests/mat.rs
tests/mat.rs
@@ -251,6 +251,23 @@ fn mat_at_row() -> Result<()> {
Ok(())
}
+#[test]
+fn mat_at_pt() -> Result<()> {
+ let s: Vec<Vec<f32>> = vec![
+ vec![1., 2., 3.],
+ vec![4., 5., 6.],
+ vec![7., 8., 9.],
+ ];
+ let mut m = Mat::from_slice_2d(&s)?;
+ assert_eq!(5., *m.at_pt::<f32>(Point::new(1, 1))?);
+ assert_eq!(4., *m.at_pt_mut::<f32>(Point::new(0, 1))?);
+ assert_eq!(3., unsafe { *m.at_pt_unchecked::<f32>(Point::new(2, 0))? });
+ assert_eq!(9., unsafe { *m.at_pt_mut_unchecked::<f32>(Point::new(2, 2))? });
+ assert_matches!(m.at_pt::<f32>(Point::new(-1, -3)), Err(Error {code: core::StsOutOfRange, ..}));
+ assert_matches!(m.at_pt::<f32>(Point::new(3, -3)), Err(Error {code: core::StsOutOfRange, ..}));
+ Ok(())
+}
+
#[test]
fn mat_vec() -> Result<()> {
{

allow using Point as argument to Mat::at()