opencv读取一张jpg图片并保存为MP4或者avi格式的视频

opencv读取一张jpg图片并保存为MP4或者avi格式的视频

源码

#include <iostream>
#include <stdlib.h> //srand()和rand()函数 
#include<windows.h>
#include <fstream> 


/*opencv相关*/
#include <opencv2/core/core.hpp> 
#include <opencv2/opencv.hpp>
#include "opencv2/highgui/highgui.hpp"
#include <opencv2/imgproc/imgproc.hpp>  
#include <opencv2/objdetect/objdetect.hpp> 
#include <opencv2/ml/ml.hpp>  
#include <opencv2\imgproc\types_c.h>


int main()
{
	Mat frame = imread("tingchechang1.jpg"); //读取畸变图片
	//cv::VideoWriter wrt("./test.avi", cv::VideoWriter::fourcc('M', 'J', 'P', 'G'), 30, cv::Size(1920, 1080));
	cv::VideoWriter wrt("./tingchechang.mp4", cv::VideoWriter::fourcc('D', 'I', 'V', 'X'), 30, cv::Size(1528, 858));
	
	for(int i=0;i<600;i++)
	{
	
		string fps_str = "frame_number: " + to_string(i);
		//Mat frame0 =frame.clone();
		//putText(frame0, fps_str, Point2f(10, 80), FONT_HERSHEY_COMPLEX_SMALL, 3.2, Scalar(50, 255, 0), 3);

		//namedWindow("畸变校正后的图片", 0);//参数为零,则可以*拖动
		//imshow("畸变校正后的图片", frame0);
		//waitKey(33);
		wrt << frame; // where image should be cv::Mat class
	}


	return 0;
}

上一篇:Node.Js爬虫开发抓取网络平台项目班(4期)


下一篇:最新程序员数学(基础+进阶)完整版