视频合并

// 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;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值