// Recolightcolor.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include <vector>
#include <cv.h>
#include <highgui.h>
#include <afx.h>
#include <string>
using namespace std;
CvCapture * capture;
int fps;
CvSize size;
CvVideoWriter * writer ;
IplImage * frame;
void initalWriterMedia(const char * medianame)
{
capture = cvCreateFileCapture(medianame);
fps = (int)cvGetCaptureProperty(capture,CV_CAP_PROP_FPS);
size = cvSize(
(int)cvGetCaptureProperty(capture,CV_CAP_PROP_FRAME_WIDTH),
(int)cvGetCaptureProperty(capture,CV_CAP_PROP_FRAME_HEIGHT)
);
writer = cvCreateVideoWriter("Meger.avi",CV_FOURCC('M','J','P','G'),fps,size);
}
void MegerMedia(const char * medianame)
{
capture = cvCreateFileCapture(medianame);
frame = cvQueryFrame(capture);
int n = 0;
while(frame){
cvWriteFrame(writer,frame);//写帧
n++;
if(n%25 == 0)
printf("%d ",n/25);//每25帧显示一次
frame = cvQueryFrame(capture);//获得下一帧
}
}
void FindJpgFile(const char *dripath) //找DRIPATH目录下的所有指定格式文件
{
CFileFind findjpg;
CString jpgpath,s;
const char * here;
jpgpath.Format(_T("%s\\*.avi"),dripath); //仅找AVI文件
bool done = findjpg.FindFile(jpgpath); //找到
int recogresult;
int first = 1;
while(done)
{
done = findjpg.FindNextFile(); //其实这个才是真正找到下一个文件
if(findjpg.IsDirectory() || findjpg.IsDots()) //找到的是根目录 . 及下一级目录就丢弃
continue;
s = findjpg.GetFilePath(); //获得路径
here = (LPSTR)(LPCTSTR) s; //转CHAR*
if( 1 == first){ //第一段视频,要对其初始化写指针(余下的视频都用这个,故要求视频属性一致)
initalWriterMedia(here);
first = -1;
}
MegerMedia(here);//合并视频
}
}
void FindDir(const char *picture)
{
CFileFind find;
CString path;
CString s;
const char * dirpath;
path.Format(_T("%s\\*.*"),(LPSTR)(LPCTSTR)picture);
bool done = find.FindFile(path);
while(done)
{
done = find.FindNextFile();
if(!find.IsDirectory()|| find.IsDots()) //找到的不是目录或.就继续往下找,直到找到下一个目录
continue;
s = find.GetFilePath();
dirpath = (LPSTR)(LPCTSTR) s;
FindJpgFile(dirpath); //找到一个目录,则搜索该目录 下的文件
}
}
int _tmain(int argc, _TCHAR* argv[])
{
//FindJpgFile("G:\\360data\\重要数据\\桌面\\信号灯数据库\\red\\yellow");
FindDir("G:\\360data\\重要数据\\桌面\\信号灯数据库\\red");
cvReleaseImage(&frame);
cvReleaseVideoWriter(&writer);
return 0;
}
视频合并
最新推荐文章于 2023-05-29 11:33:06 发布