Как я могу получить пиксельные координаты верхней части головы для изображения снимка головы в Python?
Я взглянул на dlib с помощью https:/ /github.com/codeniko/shape_predictor_81_face_landmarks, а также модуль face_recognition, но ни один из них, похоже, не поддерживает
Вот сценарий, который я написал
Как я могу получить пиксельные координаты верхней части головы для изображения снимка головы в Python? Я взглянул на dlib с помощью https:/ /github.com/codeniko/shape_predictor_81_face_landmarks, а также модуль face_recognition, но ни один из них, похоже, не поддерживает Вот сценарий, который я написал [code]# /// script # dependencies = [ # "cmake", # "pillow", # "face_recognition", # "dlib", # ] # ///
def features(image): # face_recognition face_landmarks_list = face_recognition.face_landmarks(image) print("I found {} face(s) in this photograph.".format(len(face_landmarks_list))) pil_image = Image.fromarray(image) d = ImageDraw.Draw(pil_image) for face_landmarks in face_landmarks_list: for facial_feature in face_landmarks.keys(): print("The {} in this face has the following points: {}".format(facial_feature, face_landmarks[facial_feature])) for facial_feature in face_landmarks.keys(): d.line(face_landmarks[facial_feature], width=2) locations = face_recognition.face_locations(image) for top, right, bottom, left in locations: d.line([(left, top), (right, top), (right, bottom), (left, bottom), (left, top)], width=2) # dlib detector = dlib.get_frontal_face_detector() predictor = dlib.shape_predictor(str(Path(__file__).parent / 'shape_predictor_81_face_landmarks.dat')) faces = detector(image) for face in faces: x1 = face.left() y1 = face.top() x2 = face.right() y2 = face.bottom() landmarks = predictor(image, face) for part in landmarks.parts(): d.circle((part.x, part.y), 2, width=0, fill='white') # Show the picture pil_image.show()
if __name__ == "__main__": parser = argparse.ArgumentParser(description="Process an image to create a proportional passport photo.") parser.add_argument("image", help="Path to the image file (jpeg, png, tiff)") args = parser.parse_args() main(args.image) [/code] и его вывод: [img]https://i.sstatic.net/ibZyddj8 .png[/img]
Но меня интересует вот этот момент, где предсказано расположение макушки головы: [img]https://i.sstatic.net/TMr94QuJ.png[/img]