From b485aab7e71c1625cfc27e0f92c9509f42378458 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 5 May 2024 13:19:16 +0200 Subject: Adding upstream version 1.45.3+dfsg. Signed-off-by: Daniel Baumann --- ml/dlib/tools/python/src/face_recognition.cpp | 245 -------------------------- 1 file changed, 245 deletions(-) delete mode 100644 ml/dlib/tools/python/src/face_recognition.cpp (limited to 'ml/dlib/tools/python/src/face_recognition.cpp') diff --git a/ml/dlib/tools/python/src/face_recognition.cpp b/ml/dlib/tools/python/src/face_recognition.cpp deleted file mode 100644 index 8d5dee678..000000000 --- a/ml/dlib/tools/python/src/face_recognition.cpp +++ /dev/null @@ -1,245 +0,0 @@ -// Copyright (C) 2017 Davis E. King (davis@dlib.net) -// License: Boost Software License See LICENSE.txt for the full license. - -#include "opaque_types.h" -#include -#include -#include -#include -#include -#include "indexing.h" -#include -#include -#include - - -using namespace dlib; -using namespace std; - -namespace py = pybind11; - - -typedef matrix cv; - -class face_recognition_model_v1 -{ - -public: - - face_recognition_model_v1(const std::string& model_filename) - { - deserialize(model_filename) >> net; - } - - matrix compute_face_descriptor ( - py::object img, - const full_object_detection& face, - const int num_jitters - ) - { - std::vector faces(1, face); - return compute_face_descriptors(img, faces, num_jitters)[0]; - } - - std::vector> compute_face_descriptors ( - py::object img, - const std::vector& faces, - const int num_jitters - ) - { - if (!is_rgb_python_image(img)) - throw dlib::error("Unsupported image type, must be RGB image."); - - for (auto& f : faces) - { - if (f.num_parts() != 68 && f.num_parts() != 5) - throw dlib::error("The full_object_detection must use the iBUG 300W 68 point face landmark style or dlib's 5 point style."); - } - - - std::vector dets; - for (auto& f : faces) - dets.push_back(get_face_chip_details(f, 150, 0.25)); - dlib::array> face_chips; - extract_image_chips(numpy_rgb_image(img), dets, face_chips); - - std::vector> face_descriptors; - face_descriptors.reserve(face_chips.size()); - - if (num_jitters <= 1) - { - // extract descriptors and convert from float vectors to double vectors - for (auto& d : net(face_chips,16)) - face_descriptors.push_back(matrix_cast(d)); - } - else - { - for (auto& fimg : face_chips) - face_descriptors.push_back(matrix_cast(mean(mat(net(jitter_image(fimg,num_jitters),16))))); - } - - return face_descriptors; - } - -private: - - dlib::rand rnd; - - std::vector> jitter_image( - const matrix& img, - const int num_jitters - ) - { - std::vector> crops; - for (int i = 0; i < num_jitters; ++i) - crops.push_back(dlib::jitter_image(img,rnd)); - return crops; - } - - - template