How to get points coordinate position in the face landmark detection program of dlib?

前端 未结 1 1486
遥遥无期
遥遥无期 2021-02-06 14:14

There is one example python program in dlib to detect the face landmark position. face_landmark_detection.py

This program detect the face feature and denote the landmark

1条回答
  •  北荒
    北荒 (楼主)
    2021-02-06 14:31

    I slightly modified the code.

    import dlib
    import numpy as np
    from skimage import io
    
    predictor_path = "shape_predictor_68_face_landmarks.dat"
    
    detector = dlib.get_frontal_face_detector()
    predictor = dlib.shape_predictor(predictor_path)
    
    img = io.imread("FDT.jpg")
    
    dets = detector(img)
    
    #output face landmark points inside retangle
    #shape is points datatype
    #http://dlib.net/python/#dlib.point
    for k, d in enumerate(dets):
        shape = predictor(img, d)
    
    vec = np.empty([68, 2], dtype = int)
    for b in range(68):
        vec[b][0] = shape.part(b).x
        vec[b][1] = shape.part(b).y
    
    print(vec)
    

    Here is the output

    [[1003  575]
     [1005  593]
     [1009  611]
     [1014  627]
     [1021  642]
     [1030  655]
     [1041  667]
     [1054  675]
     [1069  677]
     [1083  673]
     [1095  664]
     [1105  651]
     [1113  636]
     [1120  621]
     [1123  604]
     [1124  585]
     [1124  567]
     [1010  574]
     [1020  570]
     [1031  571]
     [1042  574]
     [1053  578]
     [1070  577]
     [1081  572]
     [1092  568]
     [1104  566]
     [1114  569]
     [1063  589]
     [1063  601]
     [1063  613]
     [1063  624]
     [1050  628]
     [1056  630]
     [1064  632]
     [1071  630]
     [1077  627]
     [1024  587]
     [1032  587]
     [1040  586]
     [1048  588]
     [1040  590]
     [1031  590]
     [1078  587]
     [1085  585]
     [1093  584]
     [1101  584]
     [1094  588]
     [1086  588]
     [1045  644]
     [1052  641]
     [1058  640]
     [1064  641]
     [1070  639]
     [1078  640]
     [1086  641]
     [1080  651]
     [1073  655]
     [1066  656]
     [1059  656]
     [1052  652]
     [1048  645]
     [1059  645]
     [1065  646]
     [1071  644]
     [1083  642]
     [1072  645]
     [1065  647]
     [1059  646]]
    

    And there is another open source project OpenFace, which is based on dlib and describes each point's correlating part in face.

    The url of describing image

    0 讨论(0)
提交回复
热议问题