我正在尝试使用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);
我完全找不到问题在哪里
答案 0 :(得分:0)
您想使用cv::ml::KNearest
,但在KNearest
时,您尝试将其称为using namespace cv
。
但KNearest
也位于ml
内的cv::
命名空间内。试试这个:
ml::KNearest
(或者从您的代码中删除using namespace …;
,因为它bad practice无论如何都只是cv::ml::KNearest
,而只需将其称为{{1}}。)