| 372 | } |
| 373 | |
| 374 | void bind_face_recognition(py::module &m) |
| 375 | { |
| 376 | { |
| 377 | typedef std::vector<full_object_detection> type; |
| 378 | py::bind_vector<type>(m, "full_object_detections", "An array of full_object_detection objects.") |
| 379 | .def("clear", &type::clear) |
| 380 | .def("resize", resize<type>) |
| 381 | .def("extend", extend_vector_with_python_list<full_object_detection>) |
| 382 | .def(py::pickle(&getstate<type>, &setstate<type>)); |
| 383 | } |
| 384 | |
| 385 | { |
| 386 | py::class_<face_recognition_model_v1>(m, "face_recognition_model_v1", "This object maps human faces into 128D vectors where pictures of the same person are mapped near to each other and pictures of different people are mapped far apart. The constructor loads the face recognition model from a file. The model file is available here: http://dlib.net/files/dlib_face_recognition_resnet_model_v1.dat.bz2") |
| 387 | .def(py::init<std::string>()) |
| 388 | .def("compute_face_descriptor", &face_recognition_model_v1::compute_face_descriptor, |
| 389 | py::arg("img"), py::arg("face"), py::arg("num_jitters")=0, py::arg("padding")=0.25, |
| 390 | "Takes an image and a full_object_detection that references a face in that image and converts it into a 128D face descriptor. " |
| 391 | "If num_jitters>1 then each face will be randomly jittered slightly num_jitters times, each run through the 128D projection, and the average used as the face descriptor. " |
| 392 | "Optionally allows to override default padding of 0.25 around the face." |
| 393 | ) |
| 394 | .def("compute_face_descriptor", &face_recognition_model_v1::compute_face_descriptor_from_aligned_image, |
| 395 | py::arg("img"), py::arg("num_jitters")=0, |
| 396 | "Takes an aligned face image of size 150x150 and converts it into a 128D face descriptor." |
| 397 | "Note that the alignment should be done in the same way dlib.get_face_chip does it." |
| 398 | "If num_jitters>1 then image will be randomly jittered slightly num_jitters times, each run through the 128D projection, and the average used as the face descriptor. " |
| 399 | ) |
| 400 | .def("compute_face_descriptor", &face_recognition_model_v1::compute_face_descriptors, |
| 401 | py::arg("img"), py::arg("faces"), py::arg("num_jitters")=0, py::arg("padding")=0.25, |
| 402 | "Takes an image and an array of full_object_detections that reference faces in that image and converts them into 128D face descriptors. " |
| 403 | "If num_jitters>1 then each face will be randomly jittered slightly num_jitters times, each run through the 128D projection, and the average used as the face descriptor. " |
| 404 | "Optionally allows to override default padding of 0.25 around the face." |
| 405 | ) |
| 406 | .def("compute_face_descriptor", &face_recognition_model_v1::batch_compute_face_descriptors, |
| 407 | py::arg("batch_img"), py::arg("batch_faces"), py::arg("num_jitters")=0, py::arg("padding")=0.25, |
| 408 | "Takes an array of images and an array of arrays of full_object_detections. `batch_faces[i]` must be an array of full_object_detections corresponding to the image `batch_img[i]`, " |
| 409 | "referencing faces in that image. Every face will be converted into 128D face descriptors. " |
| 410 | "If num_jitters>1 then each face will be randomly jittered slightly num_jitters times, each run through the 128D projection, and the average used as the face descriptor. " |
| 411 | "Optionally allows to override default padding of 0.25 around the face." |
| 412 | ) |
| 413 | .def("compute_face_descriptor", &face_recognition_model_v1::batch_compute_face_descriptors_from_aligned_images, |
| 414 | py::arg("batch_img"), py::arg("num_jitters")=0, |
| 415 | "Takes an array of aligned images of faces of size 150_x_150." |
| 416 | "Note that the alignment should be done in the same way dlib.get_face_chip does it." |
| 417 | "Every face will be converted into 128D face descriptors. " |
| 418 | "If num_jitters>1 then each face will be randomly jittered slightly num_jitters times, each run through the 128D projection, and the average used as the face descriptor. " |
| 419 | ); |
| 420 | } |
| 421 | |
| 422 | m.def("save_face_chip", &save_face_chip, |
| 423 | "Takes an image and a full_object_detection that references a face in that image and saves the face with the specified file name prefix. The face will be rotated upright and scaled to 150x150 pixels or with the optional specified size and padding.", |
| 424 | py::arg("img"), py::arg("face"), py::arg("chip_filename"), py::arg("size")=150, py::arg("padding")=0.25 |
| 425 | ); |
| 426 | m.def("save_face_chips", &save_face_chips, |
| 427 | "Takes an image and a full_object_detections object that reference faces in that image and saves the faces with the specified file name prefix. The faces will be rotated upright and scaled to 150x150 pixels or with the optional specified size and padding.", |
| 428 | py::arg("img"), py::arg("faces"), py::arg("chip_filename"), py::arg("size")=150, py::arg("padding")=0.25 |
| 429 | ); |
| 430 | m.def("bottom_up_clustering", &bottom_up_clustering, py::arg("descriptors"), py::arg("min_num_clusters")=1, py::arg("max_dist")=0.6, |
| 431 | "Takes a list of descriptors and returns a list that contains a label for each descriptor. Clustering is done using dlib::bottom_up_cluster."); |
no test coverage detected