1. 程式人生 > >實戰深度學習OpenCV(二):讀取並播放本地或者攝像頭的視訊

實戰深度學習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; }