VS下实现将多张图片合成视频

说明

  • 编译环境:Visual Studio2013
  • OpenCV:opencv3.2.0

读取本地文件夹下的连续命名的图片,博主的图片存储在F:/video capture/View_008下,图片名称为frame_0000.jpg—frame_0600.jpg, 合成的视频在F://video picture下,名称为video.avi

#include
#include

using namespace std;
using namespace cv;

void Image_To_Video ( int m );

char image_name[60];

int main ( )
{
    Image_To_Video ( 794 );            //图像整合成视频

    return 0;
}

void Image_To_Video ( int p_num )
{
    char image_name[800];
    string s_image_name;
    //初始化视频编写器
    cv::VideoWriter writer;
    bool isColor = true;    //true
    int frame_fps = 10;
    int frame_width = 768;
    int frame_height = 576;
    using namespace cv;

    string video_name = "F:/video capture/video.avi";
    writer = VideoWriter ( video_name, CV_FOURCC ( 'X', 'V', 'I', 'D' ), frame_fps, Size ( frame_width, frame_height ), isColor );
    namedWindow ( "image to video", CV_WINDOW_AUTOSIZE );
    int i = 0;
    Mat img;
    while ( i <= p_num )
    {
        sprintf ( image_name, "F:/video capture/View_008/frame_%04d.jpg", i++);
        s_image_name = image_name;
        img = imread ( s_image_name );//读入图片
        if ( !img.data )             //判断图片调入是否成功
        {
            cout << "Could not load image file...\n" << endl;
        }
        if ( !img.empty ( ) )                   //非空判断
            imshow ( "image to video", img );

        //写入
        writer.write ( img );
        if ( waitKey ( 30 ) == 27 || i == 60)       //ESC:ASCⅡ码27
        {
            cout << "按下ESC键" << endl;
            break;
        }
    }
}

你可能感兴趣的:(图像处理,visual,studio,opencv,图片,视频)