OpenCV 2.4.9 Study Notes (4) - pixel type and restrictions on the use of Templates

Limit the use of templates

  Templates in C ++ so that the interface mechanism is very easy to use, efficient and able to guarantee the security of data and algorithms. However, excessive use of templates may increase the computational time and code size, but also sometimes difficult to distinguish between interface and implementation. Excessive use of templates is not a good thing in the OpenCV, refman OpenCV mentioned in many OpenCV algorithms at every turn thousands of lines of code files, and OpenCV need to simplify support for other languages, like JAVA, PYTHON, MATLAB, etc. and no templates, so the use of templates will be limited, there are other reasons. Overall, the current version of OpenCV, is to limit the use of templates.

The basic storage type (pixels)

Primitive data types (pixel level) the OpenCV operation are the following:

Mat_ <uchar> corresponds CV_8U, Mat_ <uchar> corresponds CV_8U, Mat_ <char> corresponds CV_8S, Mat_ <int> corresponds CV_32S, Mat_ <float> corresponds CV_32F, Mat_ <double> corresponding to is CV_64F, depth data corresponding to the following:

8-bit unsigned integer (uchar)
8-bit signed integer (schar)
16-bit unsigned integer (ushort)
16-bit signed integer (short)
32-bit signed integer (int)
32-bit floating-point number (float)
64-bit floating-point number (double)

Code in the enumeration as follows:

1 enum { CV_8U=0, CV_8S=1, CV_16U=2, CV_16S=3, CV_32S=4, CV_32F=5, CV_64F=6 };

For example:

1 Mat mtx(3, 3, CV_32F); // make a 3x3 floating-point matrix
2 Mat cmtx(10, 1, CV_64FC2); // make a 10x1 2-channel floating-point matrix (10-element complex vector)
3 Mat img(Size(1920, 1080), CV_8UC3); // make a 3-channel (color) image of 1920 columns and 1080 rows.
4 Mat grayscale(image.size(), CV_MAKETYPE(image.depth(), 1)); // make a 1-channel image of the same size and same channel type as img

 

Reproduced in: https: //www.cnblogs.com/charleshuang/p/4189445.html

Guess you like

Origin blog.csdn.net/weixin_33713350/article/details/93677539