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;
}
文章来源:https://www.toymoban.com/news/detail-556199.html
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新学习的知识。文章来源地址https://www.toymoban.com/news/detail-556199.html
到了这里,关于OpenCV [C++]-图像大小计算以及获取图像的尺寸和通道数的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!