ageitgey / face_recognition

The world's simplest facial recognition api for Python and the command line
MIT License
52.79k stars 13.42k forks source link

How to get the results of landmarks with 68 points as dlib #789

Open zoeleesss opened 5 years ago

zoeleesss commented 5 years ago

Description

How to get the results of landmarks with 68 points as dlib. I don't wanna use import dlib; etc.. . Cause it takes too much time. When i was trying to get landmarks, i used api.face_landmarks(image). But what i got is 72 points. And i tried to manually changed the results to 68 points according to the results used by dlib.

What i did was transforming 72 points to 68 points:


def compatibleToDlib(arr):
    results = []
    # 0 - 54
    for i1 in range(55):
        results.append(arr[i1])

    # 55,56,57,58,59  <-  arr[61-65]
    for i2 in range(61,66):
        results.append(arr[i2])

    # 60 <- arr[59]
    results.append(arr[59])

    # 61,62,63 <- arr[58-56]
    for i3 in range(0,3):
        results.append(arr[-i3+58])

    # 64 <- arr[55]
    results.append(arr[55])

    # 65,66,67 <- arr[70,69,68]
    for i4 in range(0,3):
        results.append(arr[-i4+70])

    # print(len(results))
    return results

But it didnt work tho. Cause the project that i needed to work with is deepfakes and tried the conversion part afterwards, but it says wrong aligened. shapes (2,51) and (55,2) not aligned: 51 (dim 1) != 55 (dim 0) And i tried to replace the landmarks by the landmarks created by dlib. And it works.

So what i want to know is how to get the same aligned results of 68-point landmarks as dlib by only using this repo - face_recognition ?

Thanks so much!!

frederickszk commented 2 years ago

Hello! I also encounter the same problem and resolve it by reading the codes in face_recognition/api.py . In L177~L192, it invokes the Dlib landmark detector and obtains the 68 landmarks at first. Afterward, it processes them into 72 landmarks. Therefore I simply extract 68 landmarks by:

from face_recognition.api import _raw_face_landmarks
...
landmarks = _raw_face_landmarks(img_frame)
face_landmark_list = [[(p.x, p.y) for p in landmark.parts()] for landmark in landmarks]

However, from my evaluation results, I found that it's about 6x slower than directly using Dlib=19.23.1.