【问题标题】:Capture a picture from multiple webcams, using C++使用 C++ 从多个网络摄像头捕获图片
【发布时间】:2009-11-01 20:37:28
【问题描述】:

我需要一个程序来从多个网络摄像头捕获图片并将它们自动保存在 Windows Vista 中。我从this link 获得了基本代码。该代码在 Window XP 中运行,但当我尝试在 Vista 上使用它时,它显示“失败”。每次执行时都会弹出不同的错误。如果我使用SDK平台会有帮助吗?有人有什么建议吗?

【问题讨论】:

    标签: c++ image visual-c++ windows-vista capture


    【解决方案1】:

    我无法在多个网络摄像头上进行测试,因为我只有一个,但我确信 OpenCV2.0 应该能够处理它。下面是一些带有一个网络摄像头的示例代码(我使用 Vista),可以帮助您入门。

    #include <cv.h>
    #include <highgui.h> 
    
    using namespace cv;    
    
    int main()
    {
        // Start capturing on camera 0
        VideoCapture cap(0);
        if(!cap.isOpened()) return -1;
    
        // This matrix will store the edges of the captured frame
        Mat edges;
        namedWindow("edges",1);
    
        for(;;)
        {
        // Acquire the frame from cap into frame
        Mat frame;
        cap >> frame;
    
        // Now, find the edges by converting to grayscale, blurring and then Canny edge detection
        cvtColor(frame, edges, CV_BGR2GRAY);
        GaussianBlur(edges, edges, Size(7,7), 1.5, 1.5);
        Canny(edges, edges, 0, 30, 3);
    
        // Display the edges and the frame
        imshow("edges", edges);
        imshow("frame", frame);
        // Terminate by pressing a key
        if(waitKey(30) >= 0) break; 
        }
    return 0;
    }
    

    注意:

    矩阵边被分配在 第一帧处理,除非 决议会突然改变, 相同的缓冲区将被重用于 每一帧的边缘图。

    如您所见,代码非常简洁易读!我从 OpenCV 2.0 文档 (opencv.pdf) 中提取了这个。

    代码不仅显示来自网络摄像头的图像(在frame 下),而且还进行实时边缘检测!这是我将网络摄像头对准显示器时的屏幕截图:)

    screenshot http://img245.imageshack.us/img245/5014/scrq.png

    如果您希望代码仅显示来自一台相机的帧:

    #include <cv.h>
    #include <highgui.h>
    
    using namespace cv;
    
    int main()
    {
        VideoCapture cap(0);
        if(!cap.isOpened()) return -1;
        for(;;)
        {
        Mat frame;
        cap >> frame;
        imshow("frame", frame);
        if(waitKey(30) >= 0) break;
        }
    return 0;
    }
    

    【讨论】:

      【解决方案2】:

      如果程序在 UAC 关闭或管理员运行时运行,请确保您选择保存结果的位置位于可写位置,例如用户的我的文档文件夹。一般来说,根目录和程序文件目录对普通用户都是只读的。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2013-01-18
        • 1970-01-01
        • 1970-01-01
        • 2013-02-09
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多