Convert Ptr<cv::face::FaceRecognizer> to Ptr<cv::face::BasicFaceRecognizer>

asked 2016-01-17 12:51:49 -0600

Bilityuk gravatar image

Hi to everyone! Is there any way to make a convertion from FaceRecognizer to BasicFaceRecognizer type in OpenCv 3.1?When i am trying to build a project, compiler show me the error: Cannot convert from Ptr<facerecognizer> to Ptr<basicfacerecognizer>.

edit retag flag offensive close merge delete

Comments

Try using dynamicCast.

Tetragramm gravatar imageTetragramm ( 2016-01-17 22:15:23 -0600 )edit
1

why do you need this cast ? can you show us some code ?

berak gravatar imageberak ( 2016-01-17 23:58:37 -0600 )edit

Thank you for reply! Yes sure i will post my code. I need this cast because i am trying to use function that use FaceRecognizer as parameter , and inside of the function i need to cast FaceRecognizer to BasicFaceRecognizer to be able to get the following methods:

_model->getMean();
_model->getEigenVectors();
_model->getProjections();

Here is a function:

void showTrainingDebugData(const Ptr<cv::face::FaceRecognizer> model, const int faceWidth, const int faceHeight)
{

      Ptr<cv::face::FaceRecognizer> _model = model;

      Mat averageFaceRow = _model->getMean();
      Mat eigenvectors = _model->getEigenVectors();
      vector<Mat> projections = _model->getProjections();

}

Intellisence doesn't understroke this cast, but error is shown during the build.

Bilityuk gravatar imageBilityuk ( 2016-01-18 01:43:14 -0600 )edit
1

maybe you should not use a Ptr<cv::face::FaceRecognizer> model in the first place, but a Ptr<cv::face::BasicFaceRecognizer> model (or an EigenFaceRecognizer)

berak gravatar imageberak ( 2016-01-18 01:59:26 -0600 )edit

Sorry, i posted the wrong code. Here is corrected version:

void showTrainingDebugData(const Ptr<cv::face::FaceRecognizer> model, const int faceWidth, const int faceHeight)
{

      Ptr<cv::face::BasicFaceRecognizer> _model = model;

      Mat averageFaceRow = _model->getMean();
      Mat eigenvectors = _model->getEigenVectors();
      vector<Mat> projections = _model->getProjections();

}

Can you explain please what do you mean by first place? I tried different ways, also put BasicFaceRecognition in func parameters. Finally i want to pass trained EigenFaceRecognizer model to this func and i need to be able to use getMean() inside the func body.

Bilityuk gravatar imageBilityuk ( 2016-01-18 02:51:45 -0600 )edit

If you have a Ptr<basicface_>, I would think it would automatically convert to a Ptr<face_> when passed to a function that uses that as the parameter.

But if you're calling getMean() on a Ptr<face_> then you should probably change the type of the parameter, since there is no guarantee that function will exist if, for example, someone passes a LBPHFaceRecognizer.

Tetragramm gravatar imageTetragramm ( 2016-01-18 06:55:59 -0600 )edit

What kind of type should i change? Can you explaine please a litle bit what should i do to make this func work. Thank you for reply.

Bilityuk gravatar imageBilityuk ( 2016-01-18 09:30:01 -0600 )edit

I am going to use different models (Eigen, Fisher, LBPH) within this function. Also tried dynamicCast it doesnt work, it tells there is no dynamic cast for this conversion. Ok i will try to make this function specific to EigenFaceRecognizer and will see what happens! Let you know..

Bilityuk gravatar imageBilityuk ( 2016-01-18 12:01:49 -0600 )edit

I looked into the cv::face and i found that there is no specific EigenFaceRecognizer, FisherFacerecognizer or LBPHRecognizer classes. How to make a specific function for any of this types? Maybe it would be better to ask how to make function in OpenCV 3.1 that uses EigenFaceRecognizer model as a parameter and can use the getMean(), getEigenVectors(), inside the body of the function for this model.. Does anybody can share a code sample? In OpenCV 2.4 model->get<mat>("mean") and model->get<mat>("eigenvalues") worked from FaceRecognizer class, but in OpenCv 3.1 it works only under BasicFaceRecognizer and that is a proplem..

Bilityuk gravatar imageBilityuk ( 2016-01-18 12:38:45 -0600 )edit

If you want to use getMean, you cannot use FaceRecognizer. Period. You must use BasicFaceRecognizer or a class that derives from that.

The createEigenFaceRecognizer function returns a BasicFaceRecognition Pointer.

I suggest making two versions of the function, one that takes a Ptr<basicfacerecognizor> pointer, and one that takes just a Ptr<facerecognizer>. Only the first one can call getMean().

Tetragramm gravatar imageTetragramm ( 2016-01-18 13:49:40 -0600 )edit