一、type数据类型
- 常量类型的命名规则为:
CV_(位数)+(数据类型)+(通道数)。
关系如下:
C1 | C2 | C3 | C4 | |
---|---|---|---|---|
CV_8U | 0 | 8 | 16 | 24 |
CV_8S | 1 | 9 | 17 | 25 |
CV_16U | 2 | 10 | 18 | 26 |
CV_16S | 3 | 11 | 19 | 27 |
CV_32S | 4 | 12 | 20 | 28 |
CV_32F | 5 | 13 | 21 | 29 |
CV_64F | 6 | 14 | 22 | 30 |
-
U为无符号整型,S为有符号整型,F为浮点型。
例如:CV_32FC1表示float类型,C1表示1个通道 -
与C++中的基本数据类型对应关系如下:
Mat_<uchar>---------CV_8U
Mat_<char>-----------CV_8S
Nat_<short>---------CV_16S
Mat_<ushort>--------CV_16U
Mat_<int>-----------CV_32S
Mat_<float>----------CV_32F
Mat_<double>--------CV_64F -
CV_8U 8位无符号整数 (0…..255)
CV_8S 8 位符号整数 (-128…..127)
CV_16U 16 位无符号整数 (0……65535)
CV_16S 16 位符号整数 (-32768…..32767)
CV_32S 32 位符号整数 (-2147483648……2147483647)
CV_32F 32 位浮点数 (-FLT_MAX ………FLT_MAX,INF,NAN)
CV_64F 64 位浮点数 (-DBL_MAX ……….DBL_MAX,INF,NAN)
二、Mat的定义和初始化
- 1、默认形式
Mat m=new Mat(); - 2、指定类型和大小(行列)的二维数组
Mat m= new Mat(int rows, int cols, MatType type);
或 Mat m= new Mat(Size size, MatType type);
Size(width, height), 宽高 - 3、有初始化值的指定类型和大小(行列)的二维数组
Mat m= new Mat(int rows, int cols, MatType type, Scalar s); - 4、使用预先存在数据定义的指定类型和大小(行列)的二维数组
Mat m= new Mat(int rows, int cols, MatType type, Array data, long step = 0); - 5、指定大小(size)和类型的二维数组
Mat m= new Mat(Size size, MatType type, Scalar s); - 6、使用预先存在的数据定义的制定大小(size)和类型的二维数组
Mat m= new Mat(IEnumerable<int> sizes, MatType type, Array data, IEnumerable<long> steps = null); - 7、指定类型多维数组
Mat m= new Mat(IEnumerable<int> sizes, MatType type);
三、需要数据拷贝的定义和初始化
- 拷贝构造形式
Mat(Mat m, Rect roi);
Mat(Mat m, params Range[] ranges);
Mat(Mat m, Range rowRange, Range? colRange = null);
四、其他形式
- 使用cv::Vec定义相同类型、大小为n的一维数组
Mat(IntPtr ptr);
Mat(string fileName, ImreadModes flags = ImreadModes.Color);
Mat(int rows, int cols, MatType type, IntPtr data, long step = 0);
五、函数
- CopyTo(Mat m);
- CopyTo(Mat m, Mat mask);
- Zeros(int rows, int cols, MatType type);
- Ones(Size size, MatType type);
- Diag(Mat d);
- Eye(int rows, int cols, MatType type);
六、资料
「半不闲居士」的博客:
https://blog.csdn.net/m0_37874102/article/details/114023446
网友评论