OPENCV3.0打开摄像头或者视频显示画面

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;
}

猜你喜欢

转载自blog.csdn.net/qq_18297675/article/details/72819327