chenbeifang 2019-04-29 11:05 采纳率: 0%
浏览 851

Intel OpenVino环境下 调用VideoCapture打开电脑摄像头

Intel OpenVino环境下 调用VideoCapture打开电脑摄像头,抛出异常 已触发一个断点 点击继续 仍可以打开摄像头 如下图 没有分 给大家
图片说明图片说明
图片说明

  • 写回答

1条回答 默认 最新

  • 你知我知皆知 2024-08-09 05:38
    关注

    以下回答参考 皆我百晓生券券喵儿 等免费微信小程序相关内容作答,并由本人整理回复。

    要解决这个问题,首先确保在OpenVINO环境中安装了正确的依赖库和工具,并且正确配置了摄像头设备。以下是一个使用OpenVINO环境中的VideoCapture类来打开电脑摄像头的示例:

    #include <iostream>
    #include <string>
    #include "opencv2/opencv.hpp"
    
    using namespace cv;
    using namespace std;
    
    // Function to open a VideoCapture device
    VideoCapture videoCaptureDevice = VideoCapture(0);
    
    if (!videoCaptureDevice.isOpened()) {
        cout << "Error opening camera." << endl;
    }
    
    // Check if the device was opened successfully
    if (!videoCaptureDevice.isOpened()) {
        throw runtime_error("Camera device could not be opened");
    }
    
    // Capture frames from the video stream
    while (true) {
        Mat frame;
        // Read a new frame from the video capture device
        videoCaptureDevice >> frame;
    
        // Display the captured frame
        namedWindow("Frame", WINDOW_NORMAL);
        imshow("Frame", frame);
        waitKey(1);
    }
    

    在这个例子中,我们首先尝试打开摄像头(通过VideoCapture(0)),如果成功则进入循环读取视频帧并显示它们。

    注意,这个程序没有错误检查或异常处理。例如,它可能不会捕获到非零状态码,或者不处理失败的输入。如果你的应用程序需要这些功能,请添加适当的错误处理逻辑。

    评论

报告相同问题?