Cannot create FisherFaceRecognizer with OpenCV 4 (C++) - c++

I'm following an older tutorial on face recognition based on OpenCV in C++ and have an error I can't resolve. The relevant code snippet:
#include "opencv2/core/core.hpp"
#include "opencv2/face.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/objdetect/objdetect.hpp"
...
Ptr<face::FaceRecognizer> model = face::createFisherFaceRecognizer();
model->train(images, labels);
...
I have my OpenCV compiled correctly with contrib modules, have them included but it still gives the error:
error: 'createFisherFaceRecognizer()' is not a member of 'cv::face'
I also trief this one:
Ptr<face::FaceRecognizer> model = face::FisherFaceRecognizer_create();
error: 'FisherFaceRecognizer_create()' is not a member of 'cv::face'
I looked up the face.hpp, ad the class has a function 'create', so I tried to use it, but this also failed:
Ptr<face::FaceRecognizer> model = face::FisherFaceRecognizer.create();
error: expected primary-expression before '.' token
which is weird since the function has parameters with default values. All the online solutions I treid failed. What was changed in the newer OpenCV versions and how can I create a face recognizer object correctly?

According to the official document,
Ptr<FaceRecognizer> createFisherFaceRecognizer(int num_components=0, double threshold=DBL_MAX)
is used openCV2. Since you use openCV 4, you have to follow the documentation that works with openCV 4.
Try this:
static Ptr<FisherFaceRecognizer> cv::face::FisherFaceRecognizer::create (int num_components = 0, double threshold = DBL_MAX )
On the top of this page, you can adjust the version of openCV library which you have.

Related

OpenCV C++ Tracking API

I've built OpenCV from source along with the contrib modules. But when I include the tracking module with:
#include <opencv2/tracking.hpp>
or
#include <opencv2/tracking/tracking.hpp>
or
#include <opencv2/video/tracking.hpp>
and then try to use a tracker like this:
cv::Ptr<cv::Tracker> tracker;
I get an error saying that "Tracker is not a member of 'cv'".
What is the proper way to include the tracking API and how can I troubleshoot possible installation errors?

redefinition of class when I use calib3d.hpp in opencv

I am working on ubuntu 16.4 in a C++ project and I'm trying to use a function in opencv2/calib3d.hpp but without any success.
I don't have any problem using cv::Point3d for example, but as soon as I add , I get the following error:
/usr/local/include/opencv2/features2d/features2d.hpp:69: error:
redefinition of ‘class cv::KeyPoint’ class CV_EXPORTS_W_SIMPLE
KeyPoint
Here is my code :
#include <iostream>
#include <opencv2/core.hpp>
#include <opencv2/calib3d.hpp>
int main()
{
std::cout << "cv hello"<< std::endl;
return 0;
}
When I use " pkg-config --modversion opencv " to have the version of opencv used I get "3.1.0"
My idea is that I have several version of opencv installed and conflicting.
I am thinking that because in the proposition of completion, when I am adding
#include , I have several equivalent calib3d.hpp propositions.
How can I know if I have multiple version installed ?
Not sure if this is to much effort, but you could specify the OpenCV version with Cmake.
find_package(OpenCV 3.2 REQUIRED PATHS "/path/to/OCV3.2/install/dir/")
Check this answer from #gabriel-devillers:
https://stackoverflow.com/a/45752688/10889595

OpenCV: ‘AlgorithmInfo’ does not name a type while building opencv_contrib

I am getting the following error while trying to build opencv with the contrib module
/opencv/opencv_contrib/modules/tracking/include/opencv2/tracking/tracker.hpp:577:11: error: ‘AlgorithmInfo’ does not name a type
The code is latest and pulled just now.
After adding a forward declaration class AlgorithmInfo; to the file tracker.hpp that particular error is gone but I am getting other '‘AlgorithmInfo’ does not name a type' errors in other files. Probably AlgorithmInfo is not getting included somehow. Any ideas?
Investigation:
After grepping AlgorithmInfo I found that there is no defination of AlgorithmInfo in the code base.
Comparing to the previous version of code I found AlgorithmInfo is defined at opencv2/core.hpp line 3006. But in the latest code, it is not present there at all!
This is not a permanent solution but I had the same issue and here is how i was able to continue work on the project until someone finds a better way.
I looked at the link that Utkarsh posted How do I use SIFT in OpenCV 3.0 with c++?
To summarize I had to get the opencv_contrib repo and remake opencv.
After doing so I still got the same error and eventually realized that
you must include
#include "opencv2/xfeatures2d.hpp"
#include "opencv2/features2d/features2d.hpp"
but you still get the same unless you also remove/comment out
//#include "opencv2/nonfree/features2d.hpp"
//#include "opencv2/nonfree/nonfree.hpp"
anyway this is how i got around the error for the time being.

error: ‘cv::fisheye’ has not been declared

I wanted to write a camera calibration for a 140 deg fisheye lens.
As the normal calibration of opencv is not working with these lenses I found that there seems to be a cv::fisheye module within the calib3d bundle.
But every time I try to compile my code the g++ states:
error: ‘cv::fisheye’ has not been declared
the problem is that the documentation of opencv 2.4.11 contains the methods and the additional namespace.
I have the following includes in my c++ file:
//OPENCV Stuff
#include "opencv2/opencv.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/calib3d/calib3d.hpp"
#include "opencv2/features2d/features2d.hpp"
the call of the function looks like that:
double rmsL = cv::fisheye::calibrate(objectPoints, imagePointsLeft, imagesize, cameraMatrices[LEFT], distCoeffs[LEFT], rvecs, tvecs);
I am compiling with the include path for pkg-config
OPENCV = `pkg-config opencv --cflags --libs`
In fact the normal calibration stuff is working properly as well as any other opencv related stuff.
Is anyone out there able to help me with tis problem?
It would be quiet nice to use the fisheye calibration because of the wide fov and its improvements for calculating the disparity map.
Cheers hGen
Do you use these compile options?
-I/pathto/opencv/include -L/pathto/library lopencv_core
error: ‘cv::fisheye’ has not been declared is a compilation error. Not a linker error. Which means, your compiler is not able to look for defnitions of cv::fisheye.
Either try to give explicit path.
#include "path/to/opencv2/.....h"
or
Provide the include path in -I switch.
g++ -I<path to opencv2> *.cpp -l <path to opencv2 lib> -o <target-name>

opencv errors while using with windows form applications

I am using opencv with visual studio 2010 windows form application c++. but it wont allow calling inbuilt functions. It gives errors like
Error 1 error C3861: 'cvCvtColor': identifier not found c:\users\ayesha\documents\visual studio 2010\projects\abc\abc\Form1.h 140 1 abc
Error 2 error C3861: 'cvCvtPixToPlane': identifier not found c:\users\ayesha\documents\visual studio 2010\projects\abc\abc\Form1.h 146 1 abc
I have added the following headers
#include "highgui.h"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/core/core.hpp"
#include "opencv2/highgui/highgui.hpp"
Can anyone please tell me what i am doing wrong.
Unfortunately, OP doesn't say what version of OpenCV he uses.
While working with OpenCV 3.0, use cvSplit() instead of cvCvtPixToPlane().
cvCvtColor() shall work with OpenCV 3.0, provided you added the required header files to your projects.
Finally, to make sure you don't miss any required files in your project, just start your code with #include <opencv2\opencv.hpp>.
cvCvtColor is a C API function of OpenCV, but you're intending to use the C++ one. You have 2 ways of fixing the problem:
1) (Recommended) Change your source code to use the C++ API. You should use cv::Mat instead of CvArr, cv::cvtColor instead of cvCvtColor, etc.
2) Since such changes in the source code can be pretty involved, you can still use the C API by including C-headers
#include "opencv2/imgproc/imgproc_c.h"
#include "opencv2/core/core_c.h"
#include "opencv2/highgui/highgui_c.h"
instead of the C++ (*.hpp) ones
The error you've mentioned it is a linker error I suppose.
As you're including two headers highgui.hpp and highgui.h targeting to an identical library which is opencv_highgui23#.
Just include only one header.