OpenCV学习:播放avi视频文件
生活随笔
收集整理的這篇文章主要介紹了
OpenCV学习:播放avi视频文件
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
#if 0
//播放avi視頻文件(IplImage)
#include <opencv2/opencv.hpp>
using namespace std; #pragma comment(linker, "/subsystem:\"windows\" /entry:\"mainCRTStartup\"") int main()
{ const char *pstrAviFileName = ".\\Res\\Microsoft_split.avi"; const char *pstrWindowsTitle = "OpenCV.avi"; // 從文件中讀取圖像CvCapture* pCapture = cvCaptureFromFile(pstrAviFileName);if (!pCapture){cout << "Fail to capture avi file!" << endl;return -1;}IplImage *pImage = NULL; //創建窗口
cvNamedWindow(pstrWindowsTitle, CV_WINDOW_AUTOSIZE); while(1){pImage = cvQueryFrame(pCapture);if (!pImage){cout << "Fail to query avi frame image!" << endl;break;}//在指定窗口中顯示圖像
cvShowImage(pstrWindowsTitle, pImage); if (cvWaitKey(30) >= 0){break;}}cvReleaseCapture(&pCapture);cvDestroyWindow(pstrWindowsTitle); return 0;
}
#endif#if 1
//播放avi視頻文件(Mat)
#include <opencv2/opencv.hpp>
using namespace std;
using namespace cv;#pragma comment(linker, "/subsystem:\"windows\" /entry:\"mainCRTStartup\"") int main()
{ const char *pstrAviFileName = ".\\Res\\AviDemo.avi"; const char *pstrWindowsTitle = "OpenCV.avi"; VideoCapture cap(pstrAviFileName);//檢查是否成功打開 if(!cap.isOpened()) { cerr << "Can not open a camera or file." << endl; return -1; }Mat im; //創建窗口
cvNamedWindow(pstrWindowsTitle, CV_WINDOW_AUTOSIZE); while(1){cap >> im;if (im.empty()){break;}//在指定窗口中顯示圖像
imshow(pstrWindowsTitle, im); if(waitKey(30) >= 0) {break; }}//退出時會自動釋放cap中占用資源return 0;
}
#endif
運行結果:
?
轉載于:https://www.cnblogs.com/MakeView660/p/6508906.html
與50位技術專家面對面20年技術見證,附贈技術全景圖總結
以上是生活随笔為你收集整理的OpenCV学习:播放avi视频文件的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 《剑指offer》— JavaScrip
- 下一篇: 配置toad远程连接oracle