Write Video Based OpenCv3

/************************************************************************************************************************
File Description:
         [1]The entry point of the console application
         [2]Video Image Process----Merge two videos into a large resolution video
Development Environment:
         VS2012+STL+Win10
Modification Time:
         2018.1.16
Author:
         September
************************************************************************************************************************/
#include <iostream>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>

using namespace std;
using namespace cv;
/**************************************************************************************************************************
Model Description:
         The entry point of the console application
***************************************************************************************************************************/
int main()
{
	string sourceVideoPathL = "cross.avi";
	string sourceVideoPathR = "crossed.avi";
	string outputVideoPath  = "QuWu.avi";

	cv::VideoCapture inputVideoL(sourceVideoPathL);
	cv::VideoCapture inputVideoR(sourceVideoPathR);
	
	cv::Mat  inputVideoLImg;
	cv::Mat  inputVideoRImg;
	cv::VideoWriter outputVideo;
	cv::Size videoResolution = cv::Size(640*2,480);
	
	outputVideo.open(outputVideoPath, -1, 25.0,videoResolution, true);
	if (!outputVideo.isOpened())
	{
		cout << "fail to open!" << endl;
		return -1;
	}
	cv::Mat resultImg(480,1280,CV_8UC3);
	while (true)
	{
		inputVideoL>>inputVideoLImg;
		inputVideoR>>inputVideoRImg;
		
		for(int y= 0;y<resultImg.size().height;y++)
		{
			for(int x=0;x<resultImg.size().width;x++)
			{
				if(x<640)
				{
					resultImg.at<Vec3b>(y,x)[0] = inputVideoLImg.at<Vec3b>(y,x)[0];
					resultImg.at<Vec3b>(y,x)[1] = inputVideoLImg.at<Vec3b>(y,x)[1];
					resultImg.at<Vec3b>(y,x)[2] = inputVideoLImg.at<Vec3b>(y,x)[2];
				}
				else
				{
					resultImg.at<Vec3b>(y,x)[0] = inputVideoRImg.at<Vec3b>(y,(x-640))[0];
					resultImg.at<Vec3b>(y,x)[1] = inputVideoRImg.at<Vec3b>(y,(x-640))[1];
					resultImg.at<Vec3b>(y,x)[2] = inputVideoRImg.at<Vec3b>(y,(x-640))[2];
				}
			}
		}
		outputVideo << resultImg;
		cv::waitKey(1);
	}
	return 0;
}

	

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值