C++ 中的 OpenCV:“未知类型名称”

Posted

技术标签:

【中文标题】C++ 中的 OpenCV:“未知类型名称”【英文标题】:OpenCV in C++: "Unknown Type Name" 【发布时间】:2015-09-28 03:05:59 【问题描述】:

我正在尝试遵循 OpenCV 教程,发现 here。本教程的一部分是创建一个 SURF 特征检测器。

与教程不同,我的代码在头文件中,如下所示:

class Img 
    Mat mat;
    int minHessian = 400;
    SurfFeatureDetector detector(minHessian);

    public:
        ...

我得到的错误发生在线路上

SurfFeatureDetector detector(minHessian);

错误是:

Unknown type name 'minHessian'

当我不把它放在一个单独的类中时,编译器不会抱怨。我也检查过并导入了所需的库。

谁能告诉我错误是什么,以及如何解决它?

【问题讨论】:

【参考方案1】:

我看了opencv教程代码:

Mat img1 = imread(argv[1], CV_LOAD_IMAGE_GRAYSCALE);
Mat img2 = imread(argv[2], CV_LOAD_IMAGE_GRAYSCALE);
if(img1.empty() || img2.empty())

    printf("Can't read one of the images\n");
    return -1;


// detecting keypoints
SurfFeatureDetector detector(400);
vector<KeyPoint> keypoints1, keypoints2;
detector.detect(img1, keypoints1);
detector.detect(img2, keypoints2);
....

据我了解,在此代码中,SurfFeatureDetector detector(minHessian); 不是您可以像以前那样在头文件中编写的函数的签名;但它实际上是在代码中调用SurfFeatureDetector 函数。 所以,我认为如果你从你的头文件代码中删除它,并将它放在你想要调用它的函数中,它可能会起作用。

【讨论】:

以上是关于C++ 中的 OpenCV:“未知类型名称”的主要内容,如果未能解决你的问题,请参考以下文章