【问题标题】:opencv identifier "Mat" is undefined when used in a header file在头文件中使用 opencv 标识符“Mat”时未定义
【发布时间】:2017-05-13 08:43:35
【问题描述】:

我正在使用 Visual Studio Professional 2013。在那里我使用了 opencv。而且我已经正确链接了所有opencv库。

  1. 程序在 main.cpp 中运行(我测试了很多 opencv 程序)
  2. 在类中使用相同的程序,产生未定义的错误(即使是简单的 mat 对象也无法在产生未定义错误的类中创建。)

我该如何解决这个问题?

请在下面找到我使用的代码(main.cpp 中不会出现这个未定义的 Mat 问题)

#pragma once
#include "stdafx.h"
#include <opencv2/highgui/highgui.hpp> // import no include errors
#include <opencv2/imgproc/imgproc.hpp> // import no include errors 
#include <opencv2/core/core.hpp>       // import no include errors
class DepthImage
{

public:
    DepthImage();
    ~DepthImage();
private:
    Mat image; //identifier "Mat" is undefined  
};

【问题讨论】:

  • 不要在标题中包含stdafx.hstdafx.h 应该是每个 cpp 文件中的第一个包含,但从不包含在标头中。
  • @drescherjm 我试过了,但我遇到了同样的问题。请在下面找到s23.postimg.org/ne23bgcaj/Capture.png
  • 尝试 cv::Mat 数据;
  • 同意,您忘记了 cv 命名空间。
  • @Angelica 谢谢我忘记了命名空间。谢谢。

标签: c++ opencv visual-studio-2013


【解决方案1】:
#pragma once
//#include "stdafx.h" never in header file
#include <opencv2/highgui/highgui.hpp> // import no include errors
#include <opencv2/imgproc/imgproc.hpp> // import no include errors 
#include <opencv2/core/core.hpp>       // import no include errors
class DepthImage
{

public:
    DepthImage();
    ~DepthImage();
private:
    cv::Mat image; //no more identifier "Mat" is undefined  
};

希望对你有帮助

【讨论】:

    猜你喜欢
    • 2017-08-07
    • 2015-11-24
    • 2015-01-06
    • 1970-01-01
    • 2014-06-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多