/************************************************************************************************************************
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;
}
Write Video Based OpenCv3
最新推荐文章于 2024-08-29 08:23:03 发布