读取视频
#include <opencv2\opencv.hpp>
using namespace cv;
int main()
{
VideoCapture capture("1.avi");
while (1)
{
Mat frame;
capture >> frame;
imshow("读取视频", frame);
waitKey(30);
}
return 0;
}
调用摄像头
#include <opencv2\opencv.hpp>
using namespace cv;
int main()
{
//从摄像头读入视频
VideoCapture capture(0);
Mat edges;
//循环显示每一帧
while (1)
{
Mat frame;
capture >> frame; //读取当前帧
cvtColor(frame, edges, CV_BGR2GRAY); //转换为灰度图
blur(edges, edges, Size(7, 7)); //模糊降噪
Canny(edges, edges, 0, 30, 0); //边缘检测并显示
imshow("读取视频", edges);
waitKey(30);
}
return 0;
}
效果如图