Opencv从视频中提取出一帧图像的代码,下面是是从视频文件test.avi中获取10帧的图像,当然可以改变。
代码如下:
// sixth.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
// 该程序实现视频和图片的相互转换.
// Image_to_video()函数将一组图片合成AVI视频文件.
// Video_to_image()函数将AVI视频文件读入,将每一帧存储为jpg文件.
//
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <cv.h>
#include <highgui.h>
#define NUM_FRAME 10 //只处理前10帧,根据视频帧数可修改
#pragma comment(lib,"cv.lib")
#pragma comment(lib,"highgui.lib")
#pragma comment(lib,"cxcore.lib")
void Video_to_image(char* filename)
{
printf("------------- video to image ... ----------------\n");
//初始化一个视频文件捕捉器
//CvCapture* capture = cvCaptureFromAVI(filename);
CvCapture* capture = cvCaptureFromFile(filename);
//获取视频信息
cvQueryFrame(capture);
int frameH = (int) cvGetCaptureProperty(capture, CV_CAP_PROP_FRAME