opencv是利用ffmpeg来对视频进行解码出每一帧,然后来显示的。这里直接给出两个函数,大家调用2个函数就可以实现对视频的帧率的读取和 摄像头帧的获取。
读取视频:
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25void readVideo(String path) { VideoCapture capture(path); while (true) { Mat frame; capture >> frame; if (frame.empty()) { break; } int h = frame.rows; int w = frame.cols; const char *name = "video"; // 这里定义为0,则窗口图像会随着窗口压缩,为1则不会,若窗口小于图像没,则图像显示不全 cvNamedWindow(name,0); cvResizeWindow(name, w/2, h/2); imshow(name, frame); //等30ms显示下一帧 waitKey(30); } }
读取摄像头数据:
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25void readCameraData() { VideoCapture capture(0); while (true) { Mat frame; capture >> frame; if (frame.empty()) { break; } int h = frame.rows; int w = frame.cols; const char *name = "video"; cvNamedWindow(name, 0); cvResizeWindow(name, w / 1, h / 1); imshow(name, frame); //等30ms显示下一帧 waitKey(30); } }
其实摄像头还是视频,主要在于初始化videocampture的时候,传入的参数,若为字符串视频路径,则是读入视频,传入 整数 0 则表示摄像头。
最后
以上就是清秀大炮最近收集整理的关于opencv VideoCapture读取视频帧率、获取摄像头数据的全部内容,更多相关opencv内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复