Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the purpose of cv::MatExpr?

Tags:

opencv

OpenCV arithmetic operations produce a cv::MatExpr, for example:

MatExproperator+(const Mat & a, const Mat &b);

I see that this is used to represent an expression before it is evaluated. What is the purpose of doing this?

like image 691
Owen Avatar asked Oct 10 '16 18:10

Owen


People also ask

What is a CV :: mat?

In OpenCV the main matrix class is called Mat and is contained in the OpenCV-namespace cv. This matrix is not templated but nevertheless can contain different data types. These are indicated by a certain type-number. Additionally, OpenCV provides a templated class called Mat_, which is derived from Mat.

What is use of mat class in OpenCV?

The Mat class of OpenCV library is used to store the values of an image. It represents an n-dimensional array and is used to store image data of grayscale or color images, voxel volumes, vector fields, point clouds, tensors, histograms, etc.


1 Answers

Let's say you have this expression:
Mat A = 3 + B * 5;
where B is also a Mat. If the operators + and * where to return a Mat, B * 5 would have create a temporary Mat and then the + operator would have create another Mat. Instead, B * 5 returns a MatExpr that doesn't actually creates a Mat, it just "remembers" the operation it needs to peform. Then, the + operator creates another MatExpr and only the = operator creates a Mat, thus avoiding the temporary Mat.
See https://en.wikipedia.org/wiki/Lazy_evaluation

like image 129
Pqqwetiqe Avatar answered Sep 21 '22 01:09

Pqqwetiqe