其他分享
首页 > 其他分享> > opencv读取一张jpg图片并保存为MP4或者avi格式的视频

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;
}

标签:frame,jpg,opencv,MP4,avi,include,cv,VideoWriter
来源: https://blog.csdn.net/mao_hui_fei/article/details/116331297