· Simple installation of Dlib face recognition library

Dlib is introduced

Dlib is a modern C ++ toolbox containing machine learning algorithms and tools for creating complex software in C ++ to solve real-world problems. It is widely used in industry and academia, including robotics, embedded devices, mobile phones and large high-performance computing environments. The open source license for Dlib allows you to use it for free in any application. Dlib has a long history and contains many modules. In recent years, the author mainly focuses on the development of modules such as machine learning, deep learning and image processing.

The installation

This post is for Windows10 installation, other platforms can follow this step to install

  • Install Miniconda

Use conda command to install Dlib library, use Miniconda and Anaconda can be used, I used to use Miniconda, simple and small memory. Recommend the use of Tsinghua source, download and install, select the appropriate platform version. Python = = 3.6

  • Install dlib, enter CMD as administrator, and execute
conda install -c conda-forge dlib
Copy the code
  • The test code
# % %
import dlib
from imageio import imread
import glob

detector = dlib.get_frontal_face_detector()
win = dlib.image_window()
paths = glob.glob('faces/*.jpg')

print(paths)

for path in paths:
	img = imread(path)
	dets = detector(img)
	print('%d personal face detected' % len(dets))
	for i, d in enumerate(dets):
		print('- %d: Left %d Top %d Right %d Bottom %d' % (i, d.left(), d.top(), d.right(), d.bottom()))

	win.clear_overlay()
	win.set_image(img)
	win.add_overlay(dets)
	dlib.hit_enter_to_continue()
Copy the code

The photos are in the Faces folder and require the Imageio library, which can be installed using the following command

pip install imageio
Copy the code
  • The output
['faces\\f1.jpg'] 0: Left 270 Top 128 Right 912 Bottom 770Copy the code

The original photo



The output image