【问题标题】:OpenCV 2.4.3 and videoInput into MatOpenCV 2.4.3 和 videoInput 进入 Mat
【发布时间】:2012-11-07 06:16:14
【问题描述】:

我正在尝试使用 videoInput 库、OpenCV 2.4.3 和 VS2010 Express 从两个或多个 MSFT LifeCam HD-3000 将视频捕获为 Mat 类型。

我按照Most efficient way to capture and send images from a webcam in a network 的示例进行操作,效果很好。

现在我想用 c++ Mat 类型替换 IplImage 类型。我尝试按照以下示例进行操作:opencv create mat from camera data

这给了我以下信息:

    VI = new videoInput;
    int CurrentCam = 0;
    VI->setupDevice(CurrentCam,WIDTH,HEIGHT);
    int width = VI->getWidth(CurrentCam);
    int height = VI->getHeight(CurrentCam);
    unsigned char* yourBuffer = new unsigned char[VI->getSize(CurrentCam)];
    cvNamedWindow("test",1);
    while(1)
    {
       VI->getPixels(CurrentCam, yourBuffer, false, true);
       cv::Mat image(width, height, CV_8UC3, yourBuffer, Mat::AUTO_STEP);
       imshow("test", image); 
       if(cvWaitKey(15)==27) break;
    }

输出是一个带线条的图像(即,第一行看起来是正确的,但第二行似乎是关闭的,第三行是正确的,第四行是关闭的,等等)。这表明步骤部分是错误的,或者 IplImage 类型和我没有得到的 Mat 类型之间存在一些差异。我已尝试查看/更改所有参数,但找不到任何东西。

希望答案能帮助那些面临从 videoInput 库加载图像到 Mat 类型的相当常见问题的人。

提前致谢!

【问题讨论】:

    标签: opencv visual-studio-2010


    【解决方案1】:

    试试

    cv::Mat image(height, width, CV_8UC3, yourBuffer, Mat::AUTO_STEP);
    

    【讨论】:

    • 非常感谢!它现在完美无缺。第二个示例使用宽高顺序,但对构造函数使用 Size 结构。这把我扔到了这里。
    • rows-cols 方式确实让习惯了 width-height 的人感到困惑。
    猜你喜欢
    • 2012-11-03
    • 1970-01-01
    • 2013-03-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多