Dynamically create or copy FaceRecognizer model

Hello dear community! I can’t find the way how to dynamically create or copy FaceRecognizer model. I have a function like this:

cv::Mat reconstructFace(const cv::Ptr<cv::face::FaceRecognizer> model, const cv::Mat preprocessedFace, const std::string facerecAlgorithm)
{
       if(facerecAlgorithm=="Eigen")
       cv::Ptr<cv::face::EigenFaceRecognizer> _efmodel = model;

       if(facerecAlgorithm=="Fisher")
       cv::Ptr<cv::face::FisherFaceRecognizer> _ffmodel = model;
}

How to pass and get the model from function parameter? Copy constructor doesn’t work for me and show a compiler error:
|Error|C2665|'std::shared_ptr<T>::shared_ptr': no overloaded function could convert all the argument types

Thank you!!!

with a bit of backlog from your previous questions, i think, it’s safe to assume, that you want to perform something like this:

so we need evecs & mean, and you try to get them from a Ptr<FaceRecognizer> , while it would need Ptr<EigenFaceRecognizer> or similar.

you cannot simply assign pointers of different type (see your error msg above !)
this is an ‘downcast’ and requires a dynamic_cast , or in the case of shared_ptr you even need a dynamic_pointer_cast (see ex. at the end !)

but IF you ever need this, you have a flawed design here – you created an EigenFaceRecognizer, now you need an EigenFaceRecognizer but you don’t have one. why and where did you lose the specific type ?

probably the best solution is, to get evecs & mean, while you have the correct class instance

then, there is no special LDA reconstruction, you can only reproject from eigenspace, means: you don’t even need seperate EigenFace / FisherFace class pointers. use this derived class instead:

https://docs.opencv.org/4.x/dc/dd7/classcv_1_1face_1_1BasicFaceRecognizer.html

1 Like

Dima_Fantasy was an AI spam bot. do not trust anything the AI spam bot posted.

Thank you for a very deep explanation!