When doing experiments, we often get surveillance videos,ProgramThe video sequence or part of the image is used. In this case, you need to use opencv to convert the video into an image sequence.Source codeAs follows, it has been debugged in VC ++ 2008 and opencv2.1.
// Avi2img. cpp: defines the entry point of the console application.
//
# Include "stdafx. H"
Using namespace STD;
Int main (INT argc, _ tchar * argv [])
{
Char * filename = "D: // video // 1.avi ";
Int n = 1;
Int ret = 0;
Char path [256];
Iplimage * pframe = NULL;
Iplimage * IMG = NULL;
Cvcapture * pcapture = cvcapturefromavi (filename );
If (! Pcapture)
{
Printf ("can not read the AVI file./N ");
Return-1;
}
Cvnamedwindow ("avi2img", 1 );
While (pframe = cvqueryframe (pcapture ))
{
Cvshowimage ("avi2img", pframe );
IMG = cvcreateimage (cvsize (pframe-> width, pframe-> height), pframe-> depth, pframe-> nchannels );
Cvcopyimage (pframe, IMG );
Cvflip (IMG, IMG );
Sprintf_s (path, "d: // result // IMG // mongod.jpg", N );
N ++;
Cvsaveimage (path, IMG );
Cvwaitkey (30 );
Cvreleaseimage (& IMG );
}
Cvdestroywindow ("avi2img ");
Cvreleasecapture (& pcapture );
Return 0;
}
This article is original, my personal website cainiao Network: http://www.pphust.cn. I write on behalf of the curriculum design, graduation design, and so on .. If you wish to contact me, QQ: 410812128. If You Are the One.
Advertisement: dolphin Entertainment Network (Anhui Satellite TV fans Network) http://www.iahtv.com Thai entertainment forum: http://bbs.cntvlm.com mobile phone recharge shop: http://iahtv.taobao.com