0

I'm trying to implement a digi recognition program with c++ and opencv3, when i define a varible using KNearest i get this error:

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

this is my code:

#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);

i totally can't find where is the problem

Vanojx1
  • 5,574
  • 2
  • 23
  • 37

1 Answers1

0

You want to use cv::ml::KNearest but you're trying to refer to it as KNearest while using namespace cv.

But KNearest is also inside the ml namespace inside cv::. Try this:

ml::KNearest

(Or remove using namespace …; from your code, since it's bad practice anyway, and simply refer to it as cv::ml::KNearest.)

Community
  • 1
  • 1
Emil Laine
  • 41,598
  • 9
  • 101
  • 157
  • it worked for the first function but now i get cannot declare parameter 'knearest' to be of abstract type 'cv::ml::KNearest' for the second function – Vanojx1 Aug 23 '15 at 20:47
  • `KNearest` is an abstract class so it cannot be instantiated, and consequently cannot be passed by value. You have to pass it by reference. – Emil Laine Aug 23 '15 at 21:19
  • oh ok... sorry but i'm new using c++ and opencv.... seems to be so hard for me to make working the knearest module of opencv – Vanojx1 Aug 24 '15 at 08:51