opencv3/C++ 將圖片轉(zhuǎn)換為視頻的實例
更新時間:2019年12月10日 14:56:39 作者:阿卡蒂奧
今天小編就為大家分享一篇opencv3/C++ 將圖片轉(zhuǎn)換為視頻的實例,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
現(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)容了,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
Qt結(jié)合OpenCV部署yolov5的實現(xiàn)
本文主要介紹了Qt結(jié)合OpenCV部署yolov5的實現(xiàn),文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2022-04-04