OPENCV3.0開啟攝像頭或者視訊顯示畫面
阿新 • • 發佈:2018-11-01
OPENCV3.0大大的簡化了視訊流的讀取,用了>>流操作符來讀取幀。
獲取攝像頭畫面:
#include <opencv2/opencv.hpp>
using namespace cv;
int main()
{
VideoCapture capture(0);
Mat frame;
while (capture.isOpened())
{
capture >> frame;
imshow("capture", frame);
if (cvWaitKey(40 ) == 27) //cvWaitKey的引數相當於多少ms一幀,現在是40ms一幀,1s25幀
break; //按ESC就退出
}
return 0;
}
獲取視訊畫面:
#include <opencv2/opencv.hpp>
using namespace cv;
int main()
{
VideoCapture capture("test.mp4");
Mat frame;
while (capture.isOpened())
{
capture >> frame;
imshow("capture" , frame);
if (cvWaitKey(40) == 27) //cvWaitKey的引數相當於多少ms一幀,現在是40ms一幀,1s25幀
break; //按ESC就退出
}
return 0;
}