# dlib

> A C++ machine learning and computer-vision toolkit, with Python bindings

- Category: Multimodal Generation / Vision & Understanding
- Language: C++
- Licence: BSL-1.0
- Repository: https://github.com/davisking/dlib
- Website: https://dlib.net
- Canonical page: https://ai-tldr.dev/tools/dlib/

## In short

dlib is a C++ toolkit containing machine learning algorithms and tools for building real-world software. It sits in the Vision & Understanding category of the Multimodal Generation tools and is open-source, written in C++ and licensed BSL-1.0. To get started: install the Python API.

## Overview

dlib is a C++ toolkit containing machine learning algorithms and tools for building real-world software. It is a general-purpose library rather than a single model: alongside its well-known vision components it ships classifiers and regressors, clustering, optimisation routines, graph algorithms, a linear algebra layer, threading and networking utilities, and a small cross-platform GUI API. The main documentation and API reference live at dlib.net.

In practice most people meet dlib through its face pipeline. The library provides face detection (both a HOG-based detector and a CNN one built on its max-margin object detection loss), facial landmark prediction, and a deep metric learning model that turns a face into an embedding you can compare — the three pieces that make up a face-recognition system. The same object-detection machinery is used for other targets: the examples directory trains detectors for vehicles and other objects from scratch.

dlib also carries its own deep learning API, written directly in C++ with the network architecture expressed in the type system. Its examples cover ImageNet-scale classification, semantic and instance segmentation, YOLO-style detection training, self-supervised learning, DCGAN training, and ONNX export. It is usable as a C++ library through CMake or vcpkg, or from Python through the `dlib` package on PyPI, and it is distributed under the permissive Boost Software License.

## What it does

- Face detection, facial landmark prediction and deep metric-learning face embeddings
- Object detection with HOG/FHOG features and with the CNN max-margin (MMOD) detector, including training examples
- A C++ deep learning API with examples for classification, semantic and instance segmentation, YOLO training and ONNX export
- Classical machine learning: SVMs and kernel methods, regression, clustering, structured prediction and optimisation
- Supporting infrastructure — linear algebra, image processing, threading, networking, serialisation and a simple GUI API
- Python bindings on PyPI plus CMake and vcpkg integration for C++ projects

## Getting started

dlib can be consumed either as a Python package or as a C++ library. The commands below come from the project README.

1. Install the Python API

   The stable release is on PyPI.

```bash
pip install dlib
```

2. Or build the C++ examples

   Building the examples folder is the quickest way to confirm a working C++ setup. Enable AVX if your CPU supports it — some routines run noticeably faster.

```bash
cd examples
mkdir build; cd build; cmake .. -DUSE_AVX_INSTRUCTIONS=1; cmake --build .
```

3. Add dlib to your own C++ project

   The examples folder contains a CMake tutorial showing how to link dlib into your own build. If you use the vcpkg dependency manager, dlib installs with CMake integration in one command.

```bash
vcpkg install dlib
```

## When to use it

- Detect faces and facial landmarks in images or a webcam feed, on CPU, without a GPU dependency
- Build face recognition by comparing deep metric-learning embeddings of detected faces
- Train a custom object detector for a specific target such as vehicles or products
- Embed machine learning into a C++ application where a Python runtime is not an option
