pub struct MatExpr { /* private fields */ }Expand description
Matrix expression representation @anchor MatrixExpressions This is a list of implemented matrix operations that can be combined in arbitrary complex expressions (here A, B stand for matrices ( Mat ), s for a scalar ( Scalar ), alpha for a real-valued scalar ( double )):
- Addition, subtraction, negation:
A+B,A-B,A+s,A-s,s+A,s-A,-A - Scaling:
A*alpha - Per-element multiplication and division:
A.mul(B),A/B,alpha/A - Matrix multiplication:
A*B - Transposition:
A.t()(means AT) - Matrix inversion and pseudo-inversion, solving linear systems and least-squares problems:
A.inv([method]) (~ A<sup>-1</sup>),A.inv([method])*B (~ X: AX=B) - Comparison:
A cmpop B,A cmpop alpha,alpha cmpop A, where cmpop is one of>,>=,==,!=,<=,<. The result of comparison is an 8-bit single channel mask whose elements are set to 255 (if the particular element or pair of elements satisfy the condition) or
- Bitwise logical operations:
A logicop B,A logicop s,s logicop A,~A, where logicop is one of&,|,^. - Element-wise minimum and maximum:
min(A, B),min(A, alpha),max(A, B),max(A, alpha) - Element-wise absolute value:
abs(A) - Cross-product, dot-product:
A.cross(B),A.dot(B) - Any function of matrix or matrices and scalars that returns a matrix or a scalar, such as norm, mean, sum, countNonZero, trace, determinant, repeat, and others.
- Matrix initializers ( Mat::eye(), Mat::zeros(), Mat::ones() ), matrix comma-separated initializers, matrix constructors and operators that extract sub-matrices (see Mat description).
- Mat_<destination_type>() constructors to cast the result to the proper type.
Note: Comma-separated initializers and probably some other operations may require additional
explicit Mat() or Mat_
Here are examples of matrix expressions:
// compute pseudo-inverse of A, equivalent to A.inv(DECOMP_SVD)
SVD svd(A);
Mat pinvA = svd.vt.t()*Mat::diag(1./svd.w)*svd.u.t();
// compute the new vector of parameters in the Levenberg-Marquardt algorithm
x -= (A.t()*A + lambda*Mat::eye(A.cols,A.cols,A.type())).inv(DECOMP_CHOLESKY)*(A.t()*err);
// sharpen image using "unsharp mask" algorithm
Mat blurred; double sigma = 1, threshold = 5, amount = 1;
GaussianBlur(img, blurred, Size(), sigma, sigma);
Mat lowContrastMask = abs(img - blurred) < threshold;
Mat sharpened = img*(1+amount) + blurred*(-amount);
img.copyTo(sharpened, lowContrastMask);Implementations§
Source§impl MatExpr
impl MatExpr
pub fn default() -> Result<MatExpr>
pub fn from_mat(m: &impl MatTraitConst) -> Result<MatExpr>
Sourcepub fn new(
_op: &impl MatOpTraitConst,
_flags: i32,
_a: &impl MatTraitConst,
_b: &impl MatTraitConst,
_c: &impl MatTraitConst,
_alpha: f64,
_beta: f64,
_s: Scalar,
) -> Result<MatExpr>
pub fn new( _op: &impl MatOpTraitConst, _flags: i32, _a: &impl MatTraitConst, _b: &impl MatTraitConst, _c: &impl MatTraitConst, _alpha: f64, _beta: f64, _s: Scalar, ) -> Result<MatExpr>
§C++ default parameters
- _a: Mat()
- _b: Mat()
- _c: Mat()
- _alpha: 1
- _beta: 1
- _s: Scalar()
Trait Implementations§
Source§impl Boxed for MatExpr
impl Boxed for MatExpr
Source§unsafe fn from_raw(ptr: <MatExpr as OpenCVFromExtern>::ExternReceive) -> Self
unsafe fn from_raw(ptr: <MatExpr as OpenCVFromExtern>::ExternReceive) -> Self
Wrap the specified raw pointer Read more
Source§fn into_raw(self) -> <MatExpr as OpenCVTypeExternContainer>::ExternSendMut
fn into_raw(self) -> <MatExpr as OpenCVTypeExternContainer>::ExternSendMut
Return the underlying raw pointer while consuming this wrapper. Read more
Source§fn as_raw(&self) -> <MatExpr as OpenCVTypeExternContainer>::ExternSend
fn as_raw(&self) -> <MatExpr as OpenCVTypeExternContainer>::ExternSend
Return the underlying raw pointer. Read more
Source§fn as_raw_mut(
&mut self,
) -> <MatExpr as OpenCVTypeExternContainer>::ExternSendMut
fn as_raw_mut( &mut self, ) -> <MatExpr as OpenCVTypeExternContainer>::ExternSendMut
Return the underlying mutable raw pointer Read more
Source§impl MatExprTrait for MatExpr
impl MatExprTrait for MatExpr
fn as_raw_mut_MatExpr(&mut self) -> *mut c_void
fn set_flags(&mut self, val: i32)
fn set_a(&mut self, val: Mat)
fn set_b(&mut self, val: Mat)
fn set_c(&mut self, val: Mat)
fn set_alpha(&mut self, val: f64)
fn set_beta(&mut self, val: f64)
fn set_s(&mut self, val: Scalar)
fn swap(&mut self, b: &mut impl MatExprTrait) -> Result<()>
Source§impl MatExprTraitConst for MatExpr
impl MatExprTraitConst for MatExpr
fn as_raw_MatExpr(&self) -> *const c_void
fn flags(&self) -> i32
fn a(&self) -> Mat
fn b(&self) -> Mat
fn c(&self) -> Mat
fn alpha(&self) -> f64
fn beta(&self) -> f64
fn s(&self) -> Scalar
fn to_mat(&self) -> Result<Mat>
fn size(&self) -> Result<Size>
fn typ(&self) -> Result<i32>
fn row(&self, y: i32) -> Result<MatExpr>
fn col(&self, x: i32) -> Result<MatExpr>
fn rowscols( &self, row_range: &impl RangeTraitConst, col_range: &impl RangeTraitConst, ) -> Result<MatExpr>
fn roi(&self, roi: Rect) -> Result<MatExpr>
fn t(&self) -> Result<MatExpr>
Source§fn mul_matexpr(&self, e: &impl MatExprTraitConst, scale: f64) -> Result<MatExpr>
fn mul_matexpr(&self, e: &impl MatExprTraitConst, scale: f64) -> Result<MatExpr>
C++ default parameters Read more
Source§fn mul_matexpr_def(&self, e: &impl MatExprTraitConst) -> Result<MatExpr>
fn mul_matexpr_def(&self, e: &impl MatExprTraitConst) -> Result<MatExpr>
Note Read more
Source§fn mul(&self, m: &impl MatTraitConst, scale: f64) -> Result<MatExpr>
fn mul(&self, m: &impl MatTraitConst, scale: f64) -> Result<MatExpr>
C++ default parameters Read more
fn cross(&self, m: &impl MatTraitConst) -> Result<Mat>
fn dot(&self, m: &impl MatTraitConst) -> Result<f64>
Source§impl ToInputArray for &MatExpr
impl ToInputArray for &MatExpr
fn input_array(&self) -> Result<BoxedRef<'_, _InputArray>>
Source§impl ToInputArray for MatExpr
impl ToInputArray for MatExpr
fn input_array(&self) -> Result<BoxedRef<'_, _InputArray>>
impl Send for MatExpr
Auto Trait Implementations§
impl Freeze for MatExpr
impl RefUnwindSafe for MatExpr
impl !Sync for MatExpr
impl Unpin for MatExpr
impl UnwindSafe for MatExpr
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<Mat> ModifyInplace for Matwhere
Mat: Boxed,
impl<Mat> ModifyInplace for Matwhere
Mat: Boxed,
Source§unsafe fn modify_inplace<Res>(
&mut self,
f: impl FnOnce(&Mat, &mut Mat) -> Res,
) -> Res
unsafe fn modify_inplace<Res>( &mut self, f: impl FnOnce(&Mat, &mut Mat) -> Res, ) -> Res
Helper function to call OpenCV functions that allow in-place modification of a
Mat or another similar object. By passing
a mutable reference to the Mat to this function your closure will get called with the read reference and a write references
to the same Mat. This is unsafe in a general case as it leads to having non-exclusive mutable access to the internal data,
but it can be useful for some performance sensitive operations. One example of an OpenCV function that allows such in-place
modification is imgproc::threshold. Read more