实时捕捉

演示如何使用 cv::VideoCapture 与例如网络摄像头。从网络摄像头捕获帧并显示它。这是示例代码:

#include <iostream> 

#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/core/core.hpp"

using namespace cv;
VideoCapture videoSource;
Mat frame;

int main() 
{
    if(!videoSource.open(0)) //if more cameras available use 1,2,...
        return 1;
 
    while(true)
    {            
        videoSource >> frame;
        if(frame.empty())
            break;
        imshow("Webcam", frame); //or any kinf of precessing
        if(waitKey(1)==27)
            break;//stop capturing is ESC pressed
    }

   return 0;
}