最近实验室需要做个Demo,要把两个视频拼到一个窗口里面进行播放。于是写了个使用ROI来实现两个视频拼接到一起的代码,但是该代码的前提是两个视频的帧数、宽高都一样。
#include "stdafx.h"
#include<cv.h>
#include<highgui.h>
int _tmain(int argc, _TCHAR* argv[])
{
IplImage *newFrame=NULL;
IplImage *frame1=NULL;
IplImage *frame2=NULL;
CvCapture * pCapture1 = cvCaptureFromAVI(argv[1]);
CvCapture * pCapture2 = cvCaptureFromAVI(argv[2]);
CvRect rect;
CvVideoWriter *pWriter=NULL;
//get the frame number of two videos
int frameNo1 = (int) cvGetCaptureProperty(pCapture1, CV_CAP_PROP_FRAME_COUNT);
int frameNo2 = (int) cvGetCaptureProperty(pCapture2, CV_CAP_PROP_FRAME_COUNT);
if(frameNo1!=frameNo2)
printf("video length 1 != video length 2\n");
else
printf("Total frame numbers: %d\n",frameNo1);
//get the frame