Ask Your Question
1

FacemarkLBF Params model_filename error

asked 2018-10-02 04:29:09 -0600

burstasia gravatar image

updated 2018-10-02 04:44:14 -0600

berak gravatar image

Hi there OpenCv community!

I'm brand new to OpenCV and I've been trying to build a real time face tracking app using Landmark (from the OpenCV contrib)

And when I try to create my facemark ptr, I give it a FacemarkLBF::Params variable. The issue is that the model_filename variable in the Params struct has an error of "Error reading characters of string" when I create the params. Therefore if I try to access the model_filename the program crashes with a read access violation error.

Is this a known issue? I am using OpenCV 3.4.3 and the latest version of the OpenCV contrib from Github.

Here is the code:

    //create instance of lbf facemark model
cv::face::FacemarkLBF::Params params{};
params.n_landmarks = 68; // number of landmark points
params.initShape_n = 10; // number of multiplier for make data augmentation
params.stages_n = 5; // amount of refinement stages
params.tree_n = 6; // number of tree in the model for each landmark point
params.tree_depth = 5; //he depth of decision tree
std::string name{ "lbfmodel.yaml" };
params.model_filename = name.c_str(); //path name to saved lbf facemark model
cv::Ptr<cv::face::Facemark> facemark = cv::face::FacemarkLBF::create(params);

facemark->loadModel("lbfmodel.yaml");
edit retag flag offensive close merge delete

Comments

1

Done, replaced the image with text! :)

burstasia gravatar imageburstasia ( 2018-10-02 04:44:46 -0600 )edit

thanks for the edit !

did you really want to train a new model ? (else you don't need the "Params" at all)

berak gravatar imageberak ( 2018-10-02 04:45:03 -0600 )edit
1

Nope, the lbfmodel is trained I believe. So I'm just trying to use the trained model to create the landmarks on the face

burstasia gravatar imageburstasia ( 2018-10-02 04:47:08 -0600 )edit

As far as I understand I need the parameters to create the facemark variable?

burstasia gravatar imageburstasia ( 2018-10-02 04:50:03 -0600 )edit

no, you can use createFacemarkLBF() without params.

berak gravatar imageberak ( 2018-10-02 05:08:43 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
1

answered 2018-10-02 04:58:38 -0600

berak gravatar image

updated 2018-10-02 05:02:51 -0600

then use code like this:

Ptr<face::Facemark> facemark = face::createFacemarkLBF();
facemark->loadModel("C:\\data\\mdl\\lbfmodel.yaml");  // <-- change path !

CascadeClassifier cascade("C:\\data\\mdl\\haarcascade_frontalface_alt2.xml"); // <-- here,too!
Mat image = imread("david2.jpg");  // your image here !

vector<Rect> faces;
cascade.detectMultiScale(image,faces);

vector<vector<Point2f>> fits;
bool ok = facemark->fit(image, faces, fits);
cout << ok << " " << fits.size() << endl;
for (int p=0; p<fits.size(); p++) { // persons
    for (int i=0; i<68; i++) { // points
        circle(image, fits[p][i], 3, Scalar(200,0,0), 2);
    }
}

imshow("F",image);
waitKey();
edit flag offensive delete link more

Comments

Thank you so much for your answer, I'm going to test it out now! I'm somewhat surprised that you need absolute paths?

burstasia gravatar imageburstasia ( 2018-10-02 05:43:47 -0600 )edit

no, probably not nessecary, it's just the way i had it on my disk ..

berak gravatar imageberak ( 2018-10-02 05:45:21 -0600 )edit

Ah okay, is there a way I can DM you? Because I'm running into another issue and I don't think it belongs on this thread

burstasia gravatar imageburstasia ( 2018-10-02 05:52:26 -0600 )edit

To anyone checking this in the future, make sure you're using the same version for opencv and opencv_contrib! That was my main issue

burstasia gravatar imageburstasia ( 2018-10-02 07:41:31 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2018-10-02 04:29:09 -0600

Seen: 889 times

Last updated: Oct 02 '18