Ask Your Question

Revision history [back]

Using the Facemark API Python


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()

# run landmark detector:
ok, landmarks =, 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":