发现OpenCV中读取视频或者usb camera的方法如此简单,下面是opencv2.31中实现的读取摄像头的代码:

int main()
    {
    //打开视频文件
    //cv::VideoCapture capture("bike.avi");
    //0 open default camera
    cv::VideoCapture capture(0);
    //检查视频是否打开
    if(!capture.isOpened())
        return 1;

    // 得到帧率
    double rate= capture.get(CV_CAP_PROP_FPS);
    bool stop(false);
    cv::Mat frame; // 现在的视频帧
    cv::namedWindow("Extracted Frame");
    
    // 两帧之间的间隔时间
    int delay= 1000/rate;
    // 循环播放所有的帧
    while (!stop) {
        // 读下一帧
        if (!capture.read(frame))
            break;
        //在窗口中显示图像
        cv::imshow("Extracted Frame",frame);
        // 按任意键停止视频播放
        //if (cv::waitKey(delay)>=0)
        //    stop= true;
        cv::waitKey(20);
        }
    // 关闭视频文件
    capture.release();
    return 0;
    }

相关文章:

  • 2021-05-01
  • 2021-09-14
  • 2021-07-06
  • 2022-12-23
  • 2022-12-23
  • 2021-05-29
  • 2022-02-20
猜你喜欢
  • 2021-10-23
  • 2021-12-15
  • 2022-12-23
  • 2021-12-13
  • 2022-12-23
  • 2022-12-23
  • 2021-11-10
相关资源
相似解决方案