Opencv 視頻轉(zhuǎn)為圖像序列的實(shí)現(xiàn)
基于OpenCV的視頻轉(zhuǎn)為圖像序列方法:
基于C++版本
#include <iostream> #include "cv.h" #include "opencv2/opencv.hpp" using namespace std; using namespace cv; void main() { VideoCapture cap("C:\\Users\\Leo\\Desktop\\Megamind.avi"); if ( !cap.isOpened() ) { return ; } int imgIndex(0); for ( ; ; ) { Mat frame; cap >> frame; if ( frame.empty() ) { break; } char* imageSaveName = new char[64]; sprintf( imageSaveName, "C:\\Users\\Leo\\Desktop\\new\\%05d.jpg", imgIndex ); imwrite( imageSaveName, frame ); delete[] imageSaveName; imgIndex++; } cout << "total frames: " << imgIndex << endl; }
基于C版本
#include <iostream> #include "cv.h" #include "opencv2/opencv.hpp" using namespace std; using namespace cv; void main() { // video read CvCapture *capture = cvCreateFileCapture("C:\\Users\\Leo\\Desktop\\Megamind.avi"); IplImage *frame; int imgIndex(0); while(1) { frame = cvQueryFrame(capture); if ( !frame ) { break; } char* imageSaveName = new char[64]; sprintf( imageSaveName, "C:\\Users\\Leo\\Desktop\\new\\%05d.jpg", imgIndex ); cvSaveImage( imageSaveName, frame ); delete[] imageSaveName; imgIndex++; } cout << "total frames: " << imgIndex << endl; cvDestroyWindow( "VideoImage" ); cvReleaseCapture( &capture ); cvReleaseImage( &frame ); }
測試數(shù)據(jù)為OpenCV自帶的視頻:Megamind.avi,可以在opencv\sources\samples\cpp\tutorial_code\HighGUI\video-input-psnr-ssim\video路徑下查找,共270幀圖像,運(yùn)行結(jié)果部分截圖如下:
以上這篇Opencv 視頻轉(zhuǎn)為圖像序列的實(shí)現(xiàn)就是小編分享給大家的全部內(nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
C語言深入探究動(dòng)態(tài)規(guī)劃之線性DP
線性動(dòng)態(tài)規(guī)劃,是較常見的一類動(dòng)態(tài)規(guī)劃問題,其是在線性結(jié)構(gòu)上進(jìn)行狀態(tài)轉(zhuǎn)移,這類問題不像背包問題、區(qū)間DP等有固定的模板,線性動(dòng)態(tài)規(guī)劃的目標(biāo)函數(shù)為特定變量的線性函數(shù),約束是這些變量的線性不等式或等式,目的是求目標(biāo)函數(shù)的最大值或最小值2022-04-04C++ 中malloc()和free()函數(shù)的理解
這篇文章主要介紹了C++ 中malloc()和free()函數(shù)的理解的相關(guān)資料,這里提供用法示例幫助大家理解這部分知識(shí),需要的朋友可以參考下2017-08-08matlab模擬退火算法單約束車間流水線調(diào)度解決實(shí)現(xiàn)及示例
這篇文章主要為大家介紹了matlab模擬退火算法求解單約束車間流水線調(diào)度的實(shí)現(xiàn)及示例,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步2022-02-02使用C++實(shí)現(xiàn)給PDF文檔添加文字水印
這篇文章主要為大家詳細(xì)介紹了如何通過第三方國產(chǎn)庫Spire.PDF?for?C++來實(shí)現(xiàn)給PDF文檔添加文字水印,感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下2023-11-11Visual Studio 2019 Professional 激活方法詳解
這篇文章主要介紹了Visual Studio 2019 Professional 激活方法,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-05-05