or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

face-detection.mdgeometric-operations.mdgui-components.mdimage-processing.mdindex.mdlinear-algebra.mdmachine-learning.mdobject-detection.mdutilities.md
tile.json

tessl/pypi-dlib

A modern C++ toolkit containing machine learning algorithms and tools for creating complex software to solve real world problems

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
pypipkg:pypi/dlib@20.0.x

To install, run

npx @tessl/cli install tessl/pypi-dlib@20.0.0

index.mddocs/

Dlib

A modern C++ toolkit containing machine learning algorithms and tools for creating complex software to solve real world problems. Dlib provides comprehensive functionality for computer vision, machine learning, image processing, and mathematical operations with a focus on real-world applications and high performance.

Package Information

  • Package Name: dlib
  • Language: Python (with C++ implementation)
  • Installation: pip install dlib
  • Documentation: http://dlib.net

Core Imports

import dlib

All functionality is available directly from the dlib module:

# Face detection and recognition
detector = dlib.get_frontal_face_detector()
predictor = dlib.shape_predictor("shape_predictor_68_face_landmarks.dat")
face_rec = dlib.face_recognition_model_v1("dlib_face_recognition_resnet_model_v1.dat")

# Image processing
img = dlib.load_rgb_image("image.jpg")
gray = dlib.as_grayscale(img)

# Machine learning
trainer = dlib.svm_c_trainer_linear()

Basic Usage

import dlib
import cv2

# Load an image
img = cv2.imread("faces.jpg")
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

# Initialize face detector and landmark predictor
detector = dlib.get_frontal_face_detector()
predictor = dlib.shape_predictor("shape_predictor_68_face_landmarks.dat")

# Detect faces
faces = detector(gray)

for face in faces:
    # Get facial landmarks
    landmarks = predictor(gray, face)
    
    # Extract face chip for recognition
    face_chip = dlib.get_face_chip(img, landmarks)
    
    print(f"Found face at: {face}")

Architecture

Dlib's architecture is organized around several core components:

  • Core Data Types: Matrix, vector, point types for mathematical operations
  • Image Processing: Filtering, transformations, and basic computer vision operations
  • Object Detection: Face detection, custom object detection training and inference
  • Machine Learning: SVM trainers, clustering algorithms, optimization functions
  • Geometric Operations: Rectangle manipulation, line operations, projective transforms

The library is designed for performance with optimized C++ implementations exposed through Python bindings, supporting CUDA acceleration, BLAS/LAPACK integration, and CPU instruction optimizations (AVX, NEON).

Capabilities

Linear Algebra and Core Data Types

Essential mathematical data structures and operations including matrices, vectors, points, and linear algebra functions.

class matrix:
    def __init__(self, rows: int, cols: int): ...
    def set_size(self, rows: int, cols: int): ...
    def nr(self) -> int: ...
    def nc(self) -> int: ...

class vector:
    def __init__(self, size: int = 0): ...
    def set_size(self, size: int): ...

class point:
    def __init__(self, x: int, y: int): ...
    x: int
    y: int

class dpoint:
    def __init__(self, x: float, y: float): ...
    x: float
    y: float

def dot(a, b): ...
def length(point) -> float: ...

Linear Algebra

Geometric Operations

Rectangle manipulation, line operations, transformations, and geometric utilities for computer vision applications.

class rectangle:
    def __init__(self, left: int, top: int, right: int, bottom: int): ...
    def left(self) -> int: ...
    def top(self) -> int: ...
    def right(self) -> int: ...
    def bottom(self) -> int: ...
    def width(self) -> int: ...
    def height(self) -> int: ...
    def area(self) -> int: ...

class line:
    def __init__(self, p1: point, p2: point): ...
    p1: point
    p2: point

def translate_rect(rect: rectangle, point: point) -> rectangle: ...
def centered_rect(center: point, width: int, height: int) -> rectangle: ...
def intersect(line_a: line, line_b: line) -> point: ...

Geometric Operations

Image Processing

Image filtering, transformations, morphological operations, and computer vision preprocessing functions.

class rgb_pixel:
    def __init__(self, red: int, green: int, blue: int): ...
    red: int
    green: int  
    blue: int

def threshold_image(img, threshold: float = None): ...
def gaussian_blur(img, sigma: float, max_size: int = 1000): ...
def skeleton(img): ...
def label_connected_blobs(img, zero_pixels_are_background: bool = True): ...
def as_grayscale(img): ...
def jet(img): ...

Image Processing

Face Detection and Recognition

Comprehensive face detection, landmark prediction, and face recognition capabilities using state-of-the-art deep learning models.

def get_frontal_face_detector(): ...

class shape_predictor:
    def __init__(self, predictor_path: str): ...
    def __call__(self, img, detection: rectangle): ...

class face_recognition_model_v1:
    def __init__(self, model_filename: str): ...
    def compute_face_descriptor(self, img, face, num_jitters: int = 0, padding: float = 0.25): ...

class cnn_face_detection_model_v1:
    def __init__(self, model_filename: str): ...
    def __call__(self, img, upsample_num_times: int = 0): ...

def chinese_whispers_clustering(descriptors, threshold: float): ...
def save_face_chip(img, face, filename: str, size: int = 150, padding: float = 0.25): ...

Face Detection and Recognition

Object Detection

Training and inference for custom object detection models, including dataset handling and evaluation metrics.

class simple_object_detector_training_options:
    be_verbose: bool
    add_left_right_image_flips: bool
    detection_window_size: int
    C: float
    epsilon: float
    num_threads: int
    upsample_limit: int

def train_simple_object_detector(dataset_filename: str, detector_output_filename: str, options): ...
def test_simple_object_detector(dataset_filename: str, detector_filename: str, upsampling_amount: int = -1): ...
def find_candidate_object_locations(image, rects, kvals=(50, 200, 3), min_size: int = 20): ...

Object Detection

Machine Learning

Support Vector Machines, clustering algorithms, optimization functions, and other machine learning tools.

class svm_c_trainer_linear:
    def __init__(self): ...
    def set_c(self, c: float): ...
    def train(self, samples, labels): ...

class svm_c_trainer_radial_basis:
    def __init__(self): ...
    def set_gamma(self, gamma: float): ...
    def set_c(self, c: float): ...
    def train(self, samples, labels): ...

class correlation_tracker:
    def __init__(self): ...
    def start_track(self, img, bounding_box: rectangle): ...
    def update(self, img): ...

def find_min_global(func, bounds, num_function_calls: int): ...
def max_cost_assignment(cost_matrix): ...

Machine Learning

Utilities and Data Handling

File I/O, statistical analysis, filtering functions, and various utility operations.

def load_libsvm_formatted_data(filename: str): ...
def save_libsvm_formatted_data(filename: str, samples, labels): ...
def count_steps_without_decrease(time_series, probability: float = 0.51): ...
def hit_enter_to_continue(): ...

class momentum_filter:
    def __init__(self, measurement_noise: float, typical_acceleration: float, max_measurement_deviation: float): ...
    def __call__(self, measurement): ...

Utilities

GUI and Interactive Components

Interactive visualization components for image display, user interaction, and real-time visualization of computer vision results.

class image_window:
    def __init__(self, img=None, title: str = None): ...
    def set_image(self, img): ...
    def set_title(self, title: str): ...
    def add_overlay(self, objects, color): ...
    def add_overlay_circle(self, center: point, radius: int, color): ...
    def clear_overlay(self): ...
    def wait_until_closed(self): ...
    def is_closed(self) -> bool: ...
    def get_next_double_click(self) -> point: ...
    def wait_for_keypress(self, key): ...
    def get_next_keypress(self, get_keyboard_modifiers: bool = False): ...

class non_printable_keyboard_keys:
    KEY_BACKSPACE: int
    KEY_ESC: int
    KEY_F1: int
    KEY_F2: int
    # ... (all special keys)

class keyboard_mod_keys:
    KBD_MOD_NONE: int
    KBD_MOD_SHIFT: int
    KBD_MOD_CONTROL: int
    KBD_MOD_ALT: int

GUI Components

Module Constants

__version__: str  # Dlib version
__time_compiled__: str  # Compilation timestamp
DLIB_USE_CUDA: bool  # CUDA support availability  
DLIB_USE_BLAS: bool  # BLAS support availability
DLIB_USE_LAPACK: bool  # LAPACK support availability
USE_AVX_INSTRUCTIONS: bool  # AVX instruction support
USE_NEON_INSTRUCTIONS: bool  # NEON instruction support