我是靠谱客的博主 简单小鸭子,这篇文章主要介绍OpenCv利用VideoCapture类读取视频文件和调用摄像头1、读取视频文件,现在分享给大家,希望可以做个参考。

VideoCapture类读取视频文件和调用摄像头,只有参数不同而已

1、读取视频文件

main.cpp

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include <opencv2opencv.hpp> #include <iostream> using namespace std; using namespace cv; int main() { system("color F0"); //更改输出界面颜色 VideoCapture video("D:\bike.avi"); //视频路径 if (video.isOpened()) { cout << "视频中图像的宽度=" << video.get(CAP_PROP_FRAME_WIDTH) << endl; cout << "视频中图像的高度=" << video.get(CAP_PROP_FRAME_HEIGHT) << endl; cout << "视频帧率=" << video.get(CAP_PROP_FPS) << endl; cout << "视频的总帧数=" << video.get(CAP_PROP_FRAME_COUNT); } else { cout << "请确认视频文件名称是否正确" << endl; return -1; } while (1) { Mat frame; video >> frame; if (frame.empty()) { break; } imshow("video", frame); waitKey(1000 / video.get(CAP_PROP_FPS)); } waitKey(); return 0; }

运行结果:

2、调用摄像头

main.cpp

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include <opencv2opencv.hpp> #include <iostream> using namespace std; using namespace cv; int main() { system("color F0"); //更改输出界面颜色 VideoCapture video(0);//参数置为0,即可调用摄像头 if (video.isOpened()) { cout << "视频中图像的宽度=" << video.get(CAP_PROP_FRAME_WIDTH) << endl; cout << "视频中图像的高度=" << video.get(CAP_PROP_FRAME_HEIGHT) << endl; cout << "视频帧率=" << video.get(CAP_PROP_FPS) << endl; cout << "视频的总帧数=" << video.get(CAP_PROP_FRAME_COUNT); } else { cout << "请确认视频文件名称是否正确" << endl; return -1; } while (1) { Mat frame; video >> frame; if (frame.empty()) { break; } imshow("video", frame); waitKey(1000 / video.get(CAP_PROP_FPS)); } waitKey(); return 0; }

运行结果:

呃...我就不放我的丑照了

 

最后

以上就是简单小鸭子最近收集整理的关于OpenCv利用VideoCapture类读取视频文件和调用摄像头1、读取视频文件的全部内容,更多相关OpenCv利用VideoCapture类读取视频文件和调用摄像头1、读取视频文件内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(84)

评论列表共有 0 条评论

立即
投稿
返回
顶部