Lazarus

Programming => General => Topic started by: jus on June 22, 2021, 06:13:18 pm

Title: using dlib in FPC/Lazarus for face recognition?
Post by: jus on June 22, 2021, 06:13:18 pm
Hi,
  i'm very impressed from the facial recognition library in python. It seems that the python facial recognition library is based on dlib.net (http://dlib.net) library. Does someone know how to use the dlib library in Lazarus?
Title: Re: using dlib in FPC/Lazarus ?
Post by: jamie on June 23, 2021, 01:06:28 am
If you could provide a sample of some feature utilized from that LIB in other languages I am sure it could be duplicated.
Title: Re: using dlib in FPC/Lazarus ?
Post by: jus on June 23, 2021, 01:26:30 pm
Hi Jamie,

  I mean the following methods from python for facial recognition library (https://pypi.org/project/face-recognition/):
Code: Python  [Select][+][-]
  1. import face_recognition
  2. face_recognition.face_encodings
  3. face_recognition.compare_faces
  4. face_recognition.faces_distance
Title: Re: using dlib in FPC/Lazarus ?
Post by: Leledumbo on June 25, 2021, 01:32:24 am
Does someone know how to use the dlib library in Lazarus?
Usually if the library has a C interface, just port the interface and you're done. But, dlib isn't one of them. It has either C++ or Python only, no flat C interface available.
I think you better off with TensorFlow as it has various Pascal/Delphi wrappers already, but choosing which one is an adventure itself ;)

References:
https://github.com/zsoltszakaly/tensorflowforpascal
https://macpgmr.github.io/MacXPlatform/PascalForTensorFlow.html
https://forum.lazarus.freepascal.org/index.php/topic,39049.0.html
Title: Re: using dlib in FPC/Lazarus ?
Post by: devEric69 on June 25, 2021, 10:57:27 am
AFAIK, the Python example imports a part of the library written in C\C++ and named "Dlib" (dlib.net (http://dlib.net/): C++ toolkit for machine learning algorithms), part concerning the "face detection" problem: Cf.
http://dlib.net/face_detection_ex.cpp.html (http://dlib.net/face_detection_ex.cpp.html) .

It should be possible to do the import in Object Pascal of the C header files (Object Pascal can do that) as dlib/image_processing/frontal_face_detector.h, in order to use this library in Lazarus.
Title: Re: using dlib in FPC/Lazarus ?
Post by: jus on June 30, 2021, 01:25:33 am
First of all thanx for your answers. Because the dlib.net library is written in C I downloaded the Visual Studio Community 2019 and made a DLL, which exports the function as a flat function.  ;)

I have attached a sample project with 2 DLLs( for 32bit and 64bit). Furthermore you need to download and decompress the following files in the same directory as the project1.exe:
dlib_face_recognition_resnet_model_v1.dat  ... http://dlib.net/files/dlib_face_recognition_resnet_model_v1.dat.bz2
shape_predictor_5_face_landmarks.dat ... http://dlib.net/files/shape_predictor_5_face_landmarks.dat.bz2
dlibwrapper32bit.dll ... https://github.com/lcynet/facerecognition/raw/master/Lazarus/dlibwrapper32bit.dll
dlibwrapper64bit.dll ... https://github.com/lcynet/facerecognition/raw/master/Lazarus/dlibwrapper64bit.dll
bald_guys.jpg ... https://github.com/lcynet/facerecognition/raw/master/Lazarus/bald_guys.jpg

I have posted a Delphi version in the german Delphipraxis.net (https://www.delphipraxis.net/208174-dlib-python-face_recognition-compare_faces-delphi.html) forum too.
TinyPortal © 2005-2018