現(xiàn)有一些圖片按順序放置在一文件夾jogging1/下,如圖:

需要將其合并轉(zhuǎn)換為一個視頻。
示例:
環(huán)境:Win7+OpenCV3+VS2012
#include<opencv2/opencv.hpp>#include <stdio.h>#include <io.h>#include <string>#include <iostream> #include <fstream> using namespace std;using namespace cv;int main(){ _finddata_t FileInfo; //讀取圖片所在的路徑 string inPath = "E://image//yu//jogging1//"; string strfind = inPath + "*"; long Handle = _findfirst(strfind.c_str(), &FileInfo); char filename[300]; Mat src; if (Handle == -1L) { cerr << "can not match the folder path" << endl; exit(-1); } Mat frame; Mat src0 = imread("E:/image/yu/jogging1/0000.jpg"); Size size = src0.size(); VideoWriter writer; writer.open("jogging.avi", CV_FOURCC('M', 'J', 'P', 'G'), 25, size, true); do{ //判斷是否有子目錄 if (FileInfo.attrib & _A_SUBDIR) { if ((strcmp(FileInfo.name, ".") != 0) && (strcmp(FileInfo.name, "..") != 0)) { inPath += FileInfo.name; cout <<inPath<<endl; } } else { cout <<inPath<<FileInfo.name<<endl; //讀取圖片所在的路徑 string path = "E:/image/yu/jogging1/" + (string)FileInfo.name; src = imread(path); imshow("input", src); writer.write(src); waitKey(1); } } while (_findnext(Handle, &FileInfo) == 0); _findclose(Handle); return 0; }
以上這篇opencv3/C++ 將圖片轉(zhuǎn)換為視頻的實例就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持武林網(wǎng)。
新聞熱點
疑難解答