一. Mat类
1. 代码示例
#include <iostream>
#include <opencv2/highgui/highgui.hpp>
using namespace cv;
using namespace std;
int main()
{
Mat image = imread("/home/chang/projects/opencv_GPU_example/test.jpg");
cout << "image.data = " << image.data << endl; // .data表示指向Ma矩阵的首地址
cout << "image.dims = " << image.dims << endl; // 矩阵的维度,二位矩阵dims=2,三维矩阵dims=3????????
cout << "image.size = " << image.size << endl; // 行×列(y*x)
cout << "image.size() = " << image.size() << endl; // 列×行(x*y)
cout << "image.rows = " << image.rows << endl; // 行
cout << "image.cols = " << image.cols << endl; // 列
cout << "image.channels = " << image.channels() << endl; // 图像的通道数,彩色图像为3通道
cout << "image.depth() = " << image.depth() << endl; // depth用来度量每个像素中每个通道的精度 //enum{CV_8U=0,CV_8S=1,CV_16U=2,CV_16S=3,CV_32S=4,CV_32F=5,CV_64F=6}
cout << "image.step = " << image.step << endl; // ???????
cout << "image.step(1) = " << image.step1() << endl; // ???????
cout << "image.elemsize = " << image.elemSize() << endl; // 一个像素点的大小, elemSize()=8bit的倍数*通道数
cout << "image.elemsize1 = " << image.elemSize1() << endl; // 单个通道的数据大小 =(elemSize / Channel)
cout << "image.type = " << image.type() << endl; // Mat矩阵的类型,包含有矩阵中元素的类型以及通道数信息
namedWindow("car");
imshow("car", image);
waitKey(0);
return 0;
}
2. 常用矩阵类型总结:C(k)表示有k个通道
基本类型 | C1(或留空) | C2 | C3 | C(n) |
---|---|---|---|---|
CV_8U | 0 | 8 | 16 | 8(n-1) |
CV_8S | 1 | 9 | 17 | 8(n-1)+1 |
CV_16U | 2 | 10 | 18 | 8(n-1)+2 |
CV_16S | 3 | 11 | 19 | 8(n-1)+3 |
CV_32S | 4 | 12 | 20 | 8(n-1)+4 |
CV_32F | 5 | 13 | 21 | 8(n-1)+5 |
CV_64F | 6 | 14 | 22 | 8(n-1)+6 |
二. Point类
typedef Point_<int> Point2i;
typedef Point2i Point;
typedef Point_<float> Point2f;
typedef Point_<double> Point2d;
typedef Point3_<int> Point3i;
typedef Point3_<float> Point3f;
typedef Point3_<double> Point3d;