时间: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; } }