1.图像的尺寸就是高和宽,对于二维数组(矩阵)的行数和列数
#include <opencv2\opencv.hpp>
#include<iostream>
using namespace cv;
using namespace std;
int main() {
Mat src;
src = imread("D:/lena.png");
if (src.empty()) {
printf("could not find the picture!");
return-1;
}
//方法1
int height = src.rows;//row表示行,rows表示行的总数,即图像的高
int width = src.cols;//col表示列,cols表示列的总数,即图像的宽
//方法2
cout<<src.size()<<endl;
//获取通道数
int channels = src.channels();
//打印输出
printf("height=%d width=%d channels=%d", height, width, channels);
//或是
cout << "高=" << height;
cout << "宽=" << width;
waitKey(0);
return 0;
}
2.CV读取视频或调用摄像头:
#include<opencv2/opencv.hpp>
#include<iostream>
usingnamespace cv;
usingnamespace std;
void main()
{
//VideoCapture capture(0);
VideoCapture capture("cat.mp4");
Mat frame;
if (capture.isOpened()) //判断视频是否成功打开
{
//capture.grab() 从视频文件或捕获设备中抓取下一个帧
while (capture.grab()) {
capture >> frame;
imshow("读取视频", frame);//显示当前帧
waitKey(50);
}
}
waitKey();
}
后续继续记录opencv新学习的知识。