记录一个基于C++实现的将视频流帧转换为图片
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
|
/* avi2jpg 函数,将摄像头当前帧保存为jpg格式照片 */ void Video_to_image(CvCapture* capture) { //初始化一个视频文件捕捉器 //CvCapture* capture = cvCaptureFromAVI(filename); //获取视频信息 cvQueryFrame(capture); /* int frameH = (int) cvGetCaptureProperty(capture, CV_CAP_PROP_FRAME_HEIGHT); int frameW = (int) cvGetCaptureProperty(capture, CV_CAP_PROP_FRAME_WIDTH); int fps = (int) cvGetCaptureProperty(capture, CV_CAP_PROP_FPS); int numFrames = (int) cvGetCaptureProperty(capture, CV_CAP_PROP_FRAME_COUNT); //printf("tvideo height : %dntvideo width : %dntfps : %dntframe numbers : %dn", frameH, frameW, fps, numFrames); */ //定义和初始化变量 int i = 0; IplImage* img = 0; char image_name[13] = "1" ; //读取和显示 while (1) { img = cvQueryFrame(capture); //获取一帧图片 char key = cvWaitKey(20); sprintf (image_name, "%s%d%s" , "image" , ++i, ".jpg" ); //保存的图片名 cvSaveImage( image_name, img); //保存一帧图片 if (i == NUM_FRAME) break ; } } |
以上这篇C++实现视频流转换为图片方式就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持服务器之家。
原文链接:https://blog.csdn.net/llp1992/article/details/43086139