一.讀取並播放的代碼如下:
#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; }