Mayank
Mayank

Reputation: 363

‘FaceRecognizer’ was not declared in this scope

I am trying to compile a program, I am trying to track an object using openCV. Now whenever i compile the code i get the following error.

disguise_gui_1306.cpp:101:5: error: ‘FaceRecognizer’ was not declared in this scope Ptr model, mouthModel; ^

disguise_gui_1306.cpp:101:19: error: template argument 1 is invalid Ptr model, mouthModel; ^

disguise_gui_1306.cpp:101:26: error: invalid type in declaration before ‘,’ token Ptr model, mouthModel; ^

disguise_gui_1306.cpp: In function ‘void snapshotCB(Fl_Widget*, void*)’:

disguise_gui_1306.cpp:232:40: error: base operand of ‘->’ is not a pointer int predictedMouthLabel = mouthModel->predict(testSample); ^

disguise_gui_1306.cpp:242:31: error: base operand of ‘->’ is not a pointer int predictedLabel = model->predict(testSample); ^ disguise_gui_1306.cpp:260:29: error: base operand of ‘->’ is not a pointer int predictedLabel = model->predict(testSample); ^

disguise_gui_1306.cpp: In function ‘void trainFaceRecogniserModel(std::vector, std::vector)’:

disguise_gui_1306.cpp:394:39: error: ‘createEigenFaceRecognizer’ was not declared in this scope model = createEigenFaceRecognizer(); ^

disguise_gui_1306.cpp:395:10: error: base operand of ‘->’ is not a pointer model->train(img, lab); ^

disguise_gui_1306.cpp: In function ‘int main(int, char**)’:

disguise_gui_1306.cpp:416:39: error: ‘createEigenFaceRecognizer’ was not declared in this scope model = createEigenFaceRecognizer(); ^

disguise_gui_1306.cpp:417:10: error: base operand of ‘->’ is not a pointer model->train(images, labels); ^

disguise_gui_1306.cpp:432:15: error: base operand of ‘->’ is not a pointer mouthModel->train(mouthimages, mouthlabels);

While when the run the same on my friends laptop it compiles smoothly. We are same OS(debian),OpenCV 3.0.0-rc1. As per my research this problem should only arise if m using older version of openCV2.3. I have been trying various solutions like adding contrib.hpp and all. But nothing seems to help.

Kindly help.

Upvotes: 0

Views: 2228

Answers (2)

As mentioned above, first check if OpenCV was compiled with contrib modules as described in https://docs.opencv.org/4.x/d7/d9f/tutorial_linux_install.html

then:

  1. Add the inlude directories in your cmake CMakeLists.txt as described in https://docs.opencv.org/4.x/db/df5/tutorial_linux_gcc_cmake.html ; an example:
    cmake_minimum_required(VERSION 2.8)
    project( DisplayImage )
    find_package( OpenCV REQUIRED )
    include_directories( "/home/user/opencv-4.x","/home/user/opencv_contrib-4.x" )
    add_executable( DisplayImage DisplayImage.cpp )
    target_link_libraries( DisplayImage ${OpenCV_LIBS} )
  1. In your program.cpp file include the libraries
    #include <opencv2/opencv.hpp>
    #include <opencv2/face.hpp>
    #include <opencv2/highgui.hpp>
  1. Follow the correct name spaces described per version of OpneCV in https://docs.opencv.org/4.5.5/dd/d7c/classcv_1_1face_1_1EigenFaceRecognizer.html or de FaceRecognizer you use; for example
    Ptr<cv::face::FaceRecognizer> model = cv::face::EigenFaceRecognizer::create();

Upvotes: 2

Phat Doan
Phat Doan

Reputation: 71

Was your opencv3 built with OPENCV_EXTRA_MODULES_PATH option in make?

-D OPENCV_EXTRA_MODULES_PATH=</path/to/opencv_contrib>/modules

Upvotes: 2

Related Questions