C++实现视频流转换为图片方式
时间:2020-11-03 13:46:33|栏目:C代码|点击: 次
记录一个基于C++实现的将视频流帧转换为图片
/* 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代码
下一篇:C++中getline()、gets()等函数的用法详解
本文标题:C++实现视频流转换为图片方式
本文地址:http://www.codeinn.net/misctech/18802.html