【问题标题】:Error with OpenCV IncludesOpenCV 包含错误
【发布时间】:2013-12-22 20:39:44
【问题描述】:

请参阅下面勾选的答案:) 错误 1 ​​error C2065: 'capture' : undeclared identifier

在 OpenCV 中使用 VS2013 Express 较旧的代码示例可以正常工作,但我无法将其用于:

#include <opencv2\core\core.hpp>
#include <opencv2\highgui\highgui.hpp>
using namespace cv;
int main()
{
    Mat frame = cvQueryFrame(capture);
    imshow("Video", frame);
}

我不得不改变"opencv2/core/core.hpp"#include &lt;opencv2\core\core.hpp&gt;,它得到了那一点。 但我试过包括 highgui 但我不能让"capture" 工作? 有任何想法吗? x64 on Debug,并使用 x64 库...

【问题讨论】:

    标签: c++ opencv capture


    【解决方案1】:

    捕获部分是旧 c-api 的剩余部分。

    试试这个:

    #include "opencv2/highgui/highgui.hpp"
    #include "opencv2/core/core.hpp"
    
    using namespace cv;
    
    int main()
    {
        VideoCapture cap(0);
        while( cap.isOpened() )
        {
            Mat frame;
            if ( ! cap.read(frame) )
                break;
            imshow("lalala",frame);
            int k = waitKey(10);
            if ( k==27 )
                break;
        }
        return 0;
    }
    

    【讨论】:

    • 这行得通,但我只是想知道 capture 是否真的是一个变量/Mat 容器或其他东西,或者一个必须包含的函数。我想我仍然可以看到这种方法背后的流程和逻辑。谢谢
    • 旧版c-api近期不支持,请避免使用。
    • 这是一个object
    • 请问,waitKey 函数是做什么的?它只是在等待用户输入吗?
    • 除此之外,它隐藏了窗口的消息循环/触发更新/blitting。所以 - 没有它就没有 imshow() !
    【解决方案2】:

    当然,当您没有声明变量capture 时它会如何工作?可能你想做这样的事情:

    #include <opencv2\core\core.hpp>
    #include <opencv2\highgui\highgui.hpp>
    using namespace cv;
    int main()
    {
        CvCapture* capture = cvCreateFileCapture("path to video file");
        Mat frame = cvQueryFrame(capture);
        imshow("Video", frame);
        waitKey();
        cvReleaseCapture(&capture);
    }
    

    【讨论】:

      猜你喜欢
      • 2012-07-07
      • 1970-01-01
      • 1970-01-01
      • 2015-05-12
      • 2019-03-12
      • 2016-03-29
      • 2014-07-31
      • 2010-12-28
      • 2015-08-12
      相关资源
      最近更新 更多