Video Division with using OpenCv

馬衛飛發表於2018-03-29
/************************************************************************************************************************
File Description:
         [1]The entry point of the console application
         [2]Video Division for Panoramic image stitching
Development Environment:
         VS2012+STL+Win10+OpenCv32
Modification Time:
         2018.3.29
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()
{
	std::string sourceVideoPath  = "4K.avi";                                            //【1】原始視訊
	std::string outputVideoPathL = "leftVideo.avi";                                     //【2】左邊的切分視訊
	std::string outputVideoPathR = "rightVideo.avi";                                    //【3】右邊的切分視訊

	cv::VideoCapture   inputVideoCap(sourceVideoPath);

	cv::Mat            sourceVideoF;
	cv::Mat            outputVideoL(900,1000,CV_8UC3);
	cv::Mat            outputVideoR(900,1000,CV_8UC3);

	inputVideoCap>>sourceVideoF;

	std::cout<<sourceVideoF.size().height<<"=============="<<sourceVideoF.size().width<<std::endl;

	cv::VideoWriter    outVideoWriterL;
	cv::VideoWriter    outVideoWriterR;

	cv::Size           videoResolution = cv::Size(1000,900);
	
	outVideoWriterL.open(outputVideoPathL,-1,25.0,videoResolution,true);
	outVideoWriterR.open(outputVideoPathR,-1,25.0,videoResolution,true);
	int iCount = 0;
	while (iCount<120)
	{
		iCount++;
		inputVideoCap>>sourceVideoF;

		for(int h=0;h<sourceVideoF.size().height;h++)
		{
			for(int w=0;w<sourceVideoF.size().width;w++)
			{
				if(w<1000)
				{
					outputVideoL.at<Vec3b>(h,w)[0] = sourceVideoF.at<Vec3b>(h,w)[0];
					outputVideoL.at<Vec3b>(h,w)[1] = sourceVideoF.at<Vec3b>(h,w)[1];
					outputVideoL.at<Vec3b>(h,w)[2] = sourceVideoF.at<Vec3b>(h,w)[2];
				}
				if(w>600)
				{
					outputVideoR.at<Vec3b>(h,w-600)[0] = sourceVideoF.at<Vec3b>(h,w)[0];
					outputVideoR.at<Vec3b>(h,w-600)[1] = sourceVideoF.at<Vec3b>(h,w)[1];
					outputVideoR.at<Vec3b>(h,w-600)[2] = sourceVideoF.at<Vec3b>(h,w)[2];
				}
			}//for w
			
		}//for h

		cv::imshow("outputVideoPathL",outputVideoL);
		cv::imshow("outputVideoPathR",outputVideoR);
		//cv::imshow("sourceVideoF",sourceVideoF);
		outVideoWriterL<<outputVideoL;
		outVideoWriterR<<outputVideoR;
		cv::waitKey(1);
	}

	
	return 0;
}

	



相關文章