█

AI/TLDR

Buy me a coffee
Buy me a coffee

dlib

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

Vision & UnderstandingOpen source
Language
C++
License
BSL-1.0
$pip install dlib
IN SHORT

What is dlib?

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.

Install the Python API

The stable release is on PyPI.

bashbash
pip install dlib

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.

bashbash
cd examples
mkdir build; cd build; cmake .. -DUSE_AVX_INSTRUCTIONS=1; cmake --build .

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.

bashbash
vcpkg install dlib

Commands and code are distilled from the project's own documentation — always check the official repo for the latest.

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

How dlib compares

dlib alongside other open-source vision & understanding tools AI/TLDR tracks, ranked by GitHub stars.

ToolStarsWhat it does
PaddleOCR★ 93.5kA toolkit for detecting and recognizing text in images across many languages, plus document parsing.
OpenCV★ 91.8kThe long-standing open-source computer-vision library for C++, Python and Java; version 5 rewrote the DNN engine and added ONNX-based LLM and VLM inference in-library.
Ultralytics YOLO★ 63.9kA framework for training and running YOLO models for real-time object detection, segmentation, and tracking.
YOLOv5★ 58.3kUltralytics' PyTorch repo for training, running and exporting YOLOv5 object-detection, instance-segmentation and classification models with plain scripts and PyTorch Hub.
Supervision★ 51.8kA Python toolkit for processing, annotating, and visualizing detections and segmentations from many vision models.
MediaPipe★ 38kGoogle's on-device ML framework: ready-to-run vision, text and audio tasks with one cross-platform API for Android, iOS, web, desktop and edge.
MMDetection★ 33.1kAn OpenMMLab toolbox with many object detection and instance segmentation algorithms for research and production.
dlib★ 14.5kA C++ machine learning and computer-vision toolkit, with Python bindings