Using the Facemark API Python [closed]
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-...
yea, it's crashing inside the fit() function, right ?
have a look here, please (situation is still unchanged, sad as it is)
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/')
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)
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?
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)
Ok, thank you @berak.
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/...
actually, to my knowledge, NONE of those are trainable from python (another bug here)
if you want my 2ct: go for the LBF model (it's pretty accurate and fast)