實戰深度學習OpenCV(二):讀取並播放本地或者攝像頭的視頻


一.讀取並播放的代碼如下:

#include "pch.h" #include <iostream> #include <opencv2/core/core.hpp> #include <opencv2/highgui/highgui.hpp> #include<opencv2/imgproc/imgproc.hpp>


using namespace cv; int main() { VideoCapture a; a.open("C://Users//lenovo//Desktop//geeksong.mp4"); while (1) { Mat frame; a >> frame; imshow("讀取視頻", frame); waitKey(600); } return 0; }

 二.獲取攝像頭里的視頻,只需要將讀取視頻的路徑改為0就可以了:

#include "pch.h" #include <iostream> #include <opencv2/core/core.hpp> #include <opencv2/highgui/highgui.hpp> #include<opencv2/imgproc/imgproc.hpp>


using namespace cv; int main() { VideoCapture a; a.open(0); while (1) { Mat frame; a >> frame; imshow("讀取視頻", frame); waitKey(600); } return 0; }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM