Using the Facemark API Python [closed]

asked 2019-01-02 08:27:59 -0600

alfonsofernandezvillar gravatar image

Hi,

So far I have been using dlib landmarks detector (both the 5 face landmarks detector and the 68 face landmarks detector). Now, I would like to use Facemark API, which I think it has been introduced in OpenCV since 3.4.0 version, but I am not able to get this sample running:

# load image: 
image = cv2.imread("my_image.png", 0)

# find faces:
cascade = cv2.CascadeClassifier("haarcascade_frontalface_alt2.xml")
faces = cascade.detectMultiScale(image, 1.3, 5)

# create landmark detector and load lbf model:
facemark = cv2.face.createFacemarkLBF()
facemark.loadModel("lbfmodel.yaml")

# run landmark detector:
ok, landmarks = facemark.fit(image, faces)

# print results:
print ("landmarks LBF",ok, landmarks)

The fit function seems to take a lot of execution time and after a while, an error code is obtained.

Am I doing something wrong?

Thanks in advanced

PS: From this post: "Python support: It appears that there is still no python support yet as of OpenCV 3.4": https://www.learnopencv.com/facemark-...

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by sturkmen
close date 2020-11-18 04:55:28.253400

Comments

yea, it's crashing inside the fit() function, right ?

have a look here, please (situation is still unchanged, sad as it is)

berak gravatar imageberak ( 2019-01-02 08:33:48 -0600 )edit
1

Yes, It's crashing inside the fit() function.

I have seen the link you have provided. I can read de following: "Closing the issue, as I believe it has been resolved. Please let me know if it has to remain open, till there is a sweeter solution!" but I do not see the solution.

I have seen this: https://github.com/berak/tt/blob/mast...

But I do not understand why this path is added: sys.path.append('/home/travis/build/berak/tt/ocv/lib/python2.7/dist-packages/')

alfonsofernandezvillar gravatar imagealfonsofernandezvillar ( 2019-01-02 09:10:01 -0600 )edit

the travis build bot had a weird python setup (it put the cv2 into dist-packages, and then it could not find it), imho you should ignore it.

IF you'd want to patch the cv2 code you'd have to try with this (and rebuild)

berak gravatar imageberak ( 2019-01-02 09:36:57 -0600 )edit

I have installed opencv using pip (Unofficial pre-built OpenCV packages for Python: opencv-python 3.4.5.20).

So as you suggest I have to install OpenCV from source code, modify the function FacemarkLBFImpl::fit and rebuild, right?

alfonsofernandezvillar gravatar imagealfonsofernandezvillar ( 2019-01-02 10:24:41 -0600 )edit

yes, indeed. sad as it is, you'll have to mess with building from src for this ;(

(again, your python code above is all fine, the problem is with the c++ / wrapping code)

berak gravatar imageberak ( 2019-01-02 10:26:08 -0600 )edit
1

Ok, thank you @berak.

alfonsofernandezvillar gravatar imagealfonsofernandezvillar ( 2019-01-02 10:43:44 -0600 )edit
2

I have an additional question related to Facemark API. I think that is too silly to question it in another (separate) question, but if you consider that it is better to create another, I’ll do.

Why “FacemarkKazemi” is not trainable while both “FacemarkLBF” and “FacemarkAAM” are trainable?

https://docs.opencv.org/trunk/dc/de0/...

https://docs.opencv.org/trunk/d5/d7b/...

https://docs.opencv.org/trunk/dc/d63/...

alfonsofernandezvillar gravatar imagealfonsofernandezvillar ( 2019-01-02 11:33:15 -0600 )edit

actually, to my knowledge, NONE of those are trainable from python (another bug here)

berak gravatar imageberak ( 2019-01-02 11:37:10 -0600 )edit
1

if you want my 2ct: go for the LBF model (it's pretty accurate and fast)

berak gravatar imageberak ( 2019-01-02 11:39:27 -0600 )edit