关键代码
#include "opencv2/opencv.hpp"
#include "iostream"
using namespace std;
using namespace cv;
#define WINDOW_NAME "image"
int main()
{
namedWindow(WINDOW_NAME, WINDOW_AUTOSIZE);
Mat image;
//image = imread("E:\\vs2015_opencv\\opencv_获取图像参数\\opencv_获取图像参数\\OpenCV.jpg");
image = Mat(480,640,CV_8UC3,Scalar(135,255,135));
cout << "-------------------- 打印图像参数 ----------------------"<<endl;
cout << "clos:" << image.cols<<endl;//列宽
cout << "rows:" << image.rows << endl;//行高
cout << "channels:" << image.channels() << endl;//通道数
cout << "depth:" << image.depth() << endl;//深度
cout << "dims:" << image.dims << endl;//维度
cout << "size:" << image.size << endl;//图像尺寸
cout << "type:" << image.type() << endl;//图像类型
cout << "diag:" << image.diag() << endl;//矩阵对角元素提取(指的是只保留原矩阵的主对角线的元素,其余的元素以零取代)
imshow(WINDOW_NAME,image);
waitKey(0);
return 0;
}
打印输出
-------------------- 打印图像参数 ----------------------
clos:640
rows:480
channels:3
depth:0
dims:2
size:480 x 640
type:16
diag:[135, 255, 135;
135, 255, 135;
135, 255, 135;
135, 255, 135;
135, 255, 135;
135, 255, 135;
135, 255, 135;
135, 255, 135;
135, 255, 135;
135, 255, 135;
135, 255, 135;
135, 255, 135;
135, 255, 135;
135, 255, 135;
135, 255, 135;
135, 255, 135;
135, 255, 135;
135, 255, 135;
135, 255, 135;
135, 255, 135;
135, 255, 135;
135, 255, 135;
135, 255, 135;
135, 255, 135;
135, 255, 135;
135, 255, 135;
135, 255, 135;
135, 255, 135;
135, 255, 135;
135, 255, 135;
135, 255, 135;
135, 255, 135;
135, 255, 135;
135, 255, 135;
135, 255, 135;
135, 255, 135;
135, 255, 135;
135, 255, 135;
135, 255, 135;
135, 255, 135;
135, 255, 135;
135, 255, 135;
135, 255, 135;
135, 255, 135;
135, 255, 135;
135, 255, 135;
135, 255, 135;
135, 255, 135;
135, 255, 135;
135, 255, 135;
135, 255, 135;
135, 255, 135;
135, 255, 135;
135, 255, 135;
135, 255, 135;
135, 255, 135;
135, 255, 135;
135, 255, 135;
135, 255, 135;
135, 255, 135;
135, 255, 135;
135, 255, 135;
135, 255, 135;
135, 255, 135;
135, 255, 135;
135, 255, 135;
135, 255, 135;
135, 255, 135;
135, 255, 135;
135, 255, 135;
135, 255, 135;
135, 255, 135;
135, 255, 135;
135, 255, 135;
135, 255, 135;
135, 255, 135;
135, 255, 135;
135, 255, 135;
135, 255, 135;
135, 255, 135;
135, 255, 135;
135, 255, 135;
135, 255, 135;
135, 255, 135;
135, 255, 135;
135, 255, 135;
135, 255, 135;
135, 255, 135;
135, 255, 135;
135, 255, 135;
135, 255, 135;
135, 255, 135;
135, 255, 135;
135, 255, 135;
135, 255, 135;
135, 255, 135;
135, 255, 135;
135, 255, 135;
135, 255, 135;
135, 255, 135;
135, 255, 135;
135, 255, 135;
135, 255, 135;
135, 255, 135;
135, 255, 135;
135, 255, 135;