opencv3 knearest对象定义错误

时间:2015-08-23 20:17:12

标签: c++ knn opencv3.0

我正在尝试使用c ++和opencv3实现digi识别程序,当我使用KNearest定义变量时,我得到了这个错误:

main.cpp:19:18: error: variable or field 'RunSelfTest' declared void
 void RunSelfTest(KNearest& knn2);  
                  ^
main.cpp:19:18: error: 'KNearest' was not declared in this scope
main.cpp:19:18: note: suggested alternative:
In file included from c:/OpenCV/build/include/opencv2/ml/ml.hpp:48:0,
                 from main.cpp:1:
c:/OpenCV/build/include/opencv2/ml.hpp:397:20: note:   'cv::ml::KNearest'
 class CV_EXPORTS_W KNearest : public StatModel

这是我的代码:

#include "opencv2/highgui/highgui.hpp"  
#include "opencv2/imgproc/imgproc.hpp" 
#include "opencv2/ml/ml.hpp" 
#include <iostream>  
#include <stdio.h>  

using namespace cv;  
using namespace std;  

void RunSelfTest(KNearest& knn2);
void AnalyseImage(KNearest knearest);

我完全找不到问题在哪里

1 个答案:

答案 0 :(得分:0)

您想使用cv::ml::KNearest,但在KNearest时,您尝试将其称为using namespace cv

KNearest也位于ml内的cv::命名空间内。试试这个:

ml::KNearest

(或者从您的代码中删除using namespace …;,因为它bad practice无论如何都只是cv::ml::KNearest,而只需将其称为{{1}}。)