I remember my learning notes on opencv (4) -- I talked about the new data structure in the new data structure core. But when I look at this part again, I found that I was so careless. Let me talk about the data structure of the new version.
The point _ class does not need to be repeated. There are two member variables X and Y in it. Point _ <int> is point2i, point _ <float> is point2f, point _ <double> is point2d.
Point3_class is not commonly used. It is not much different from the point _ class. member variables include x, y, and z.
Size _ class member variables width and height. Size _ <int> is size2i, also is size, size _ <float> is size2f, we will not speculate what a size2d let the compiler issue.
The rect _ class has some meanings. The member variables X, Y, width, and height are the coordinates of the points in the upper left corner and the width and height of the rectangle respectively. A commonly used member function returns the size () value as a size, area () returns the area of the rectangle, and contains (point) is used to determine whether the vertex is within the rectangle, inside (rect) the function determines whether the rectangle is within the rectangle. TL () returns the coordinate points in the upper left corner, and BR () returns the coordinate points in the lower right corner. It is worth noting that if you want to calculate the intersection of two rectangles and the Union, you can use the following format
Rect rect = rect1 & rect2;Rect rect = rect1 | rect2;
If you want the rectangular translation operation, scaling operation, or even writing like this
Rect rectShift = rect + point;Rect rectScale = rect + size;
Isn't that good? It can greatly reduce the amount of your code.
Matx is actually a lightweight mat and must be specified before use. For example, a 2*3 float type can be declared as matx23f. I think it's easy to understand.
VEC is a derived class of matx, which is a one-dimensional matx, similar to vector. For example, to declare a float array of 10 data, you can write it as vec2f.
This will easily lead to a frequently used data structure, the scalar _ class, which is actually a variant of vec4x. the commonly used scalar is actually scalar _ <double>. In this case, it is easy for everyone to understand. The input parameters of many functions can be mat or scalar. In fact, the inputmat and outputmat parameter formats defined by opencv can all of the above data structures be used as parameters.
Next we will introduce an interesting class range. We may not be familiar with it much. In fact, it is generated to make opencv use more like Matlab. For example, range: All () is actually the symbol in MATLAB: Or .... Range (A, B) is actually a: B in MATLAB. Interesting. Note that both A and B must be int type.
I am not very afraid to introduce the PTR class. It is a smart pointer and I have never used it. It is similar to shared_ptr in the well-known boost library. I hope I will have the opportunity to share my experience with you later.
The final appearance is the most important mat, which introduces several important member variables flag (that is, the structure information, depth information, and number of channels in the header I mentioned earlier ), dims is the mat dimension and must be greater than or equal to 2. the rows and Cols parameters represent the number of rows and columns in the two-dimensional matrix (for a matrix with higher dimensions, both parameters are-1 ), another commonly used parameter should be uchar *
Data is the Data Pointer of MAT (it can be directly called by violent students but not recommended). There is also a refconst parameter, I understand that when I release the memory, I should judge whether the matrix is used last. This parameter should be used to control the number of items related to the current matrix structure.