# LPR Models

## Overview

`degirum-vehicle` uses two types of AI models for license plate recognition: **license plate detection models** and **license plate OCR models**. Both are optimized and compiled for a wide range of hardware platforms through the DeGirum model registry.

> **Important:** The `degirum_vehicle` library provides code and pipelines for license plate recognition workflows. Model licensing is separate from the `degirum_vehicle` library licensing. Contact DeGirum for licensing information.

## License Plate Detection Models

### Purpose

License plate detection models locate license plates in images and provide bounding boxes for each detected plate.

### License

License plate detection models are trained by DeGirum and can be used commercially when users license the `degirum-vehicle` package. Contact DeGirum for licensing information.

### Model Details

* **Architecture:** YOLOv8 nano (yolov8n\_relu6\_global\_lp\_det)
* **Training:** All license plate detection models are trained by DeGirum
* **Input:** 640×640 images
* **Output:** Bounding boxes + confidence scores per detected license plate
* **Compilation:** Models are compiled and optimized for all [supported hardware platforms](https://docs.degirum.com/vehicle-analytics/getting-started/basic-concepts#what-hardware-is-supported)

### Usage

Detection models are automatically selected from the model registry based on your hardware configuration:

```python
detector_spec = degirum_vehicle.get_license_plate_detection_model_spec(
    device_type="HAILORT/HAILO8",
    inference_host_address="@cloud"
)
```

## License Plate OCR Models

### Purpose

License plate OCR models extract text from detected license plate regions, converting the plate image into recognized characters.

### License

License plate OCR models are trained by DeGirum and can be used commercially when users license the `degirum-vehicle` package. Contact DeGirum for licensing information.

### Model Details

* **Architecture:** YOLOv8 small (yolov8s\_relu6\_lp\_ocr\_7ch)
* **Training:** All license plate OCR models are trained by DeGirum
* **Input:** 256×128 cropped license plate images
* **Output:** Text string with character-level confidence scores
* **Character Set:** 7-character format (alphanumeric)
* **Compilation:** Models are compiled and optimized for all [supported hardware platforms](https://docs.degirum.com/vehicle-analytics/getting-started/basic-concepts#what-hardware-is-supported)

### OCR Process

The OCR models use object detection techniques adapted for character recognition:

* Each character is detected as a separate object
* Characters are assembled into the final plate text
* Character-level confidence scores are aggregated into overall OCR score

### Usage

OCR models are automatically selected from the model registry:

```python
ocr_spec = degirum_vehicle.get_license_plate_ocr_model_spec(
    device_type="HAILORT/HAILO8",
    inference_host_address="@cloud"
)
```

## Model Registry

The DeGirum model registry automatically selects the optimal model for your hardware platform. This eliminates the need to manually choose models or tune parameters.

**Benefits:**

* Pre-optimized models for each hardware platform
* Automatic model selection based on device type
* Consistent performance across different hardware
* Simplified configuration

**Accessing the registry:**

```python
# List all supported hardware platforms
supported_hw = degirum_vehicle.model_registry.get_hardware()

# Get available hardware on cloud or local
available_hw = degirum_vehicle.get_system_hw("@cloud")

# Find compatible hardware you can use now
compatible_hw = degirum_vehicle.get_compatible_hw("@cloud")
```

## Supported Hardware Platforms

The following hardware platforms have optimized LPR models:

| Platform             | Device Type     | Detection Model                        | OCR Model                                   |
| -------------------- | --------------- | -------------------------------------- | ------------------------------------------- |
| **TFLite CPU**       | TFLITE/CPU      | yolov8n\_relu6\_global\_lp\_det (int8) | yolov8s\_relu6\_lp\_ocr\_7ch (float32/int8) |
| **Intel OpenVINO**   | OPENVINO/CPU    | yolov8n\_relu6\_global\_lp\_det (int8) | yolov8s\_relu6\_lp\_ocr\_7ch (int8)         |
| **Hailo-8**          | HAILORT/HAILO8  | yolov8n\_relu6\_global\_lp\_det (int8) | yolov8s\_relu6\_lp\_ocr\_7ch (int8)         |
| **Hailo-8L**         | HAILORT/HAILO8L | yolov8n\_relu6\_global\_lp\_det (int8) | yolov8s\_relu6\_lp\_ocr\_7ch (int8)         |
| **DeepX M1A**        | DEEPX/M1A       | yolov8n\_relu6\_global\_lp\_det (int8) | yolov8s\_relu6\_lp\_ocr\_7ch (int8)         |
| **Google Coral TPU** | TFLITE/EDGETPU  | yolov8n\_relu6\_global\_lp\_det (int8) | yolov8s\_relu6\_lp\_ocr\_7ch (int8)         |
| **DeGirum Orca**     | N2X/ORCA1       | yolov8n\_relu6\_global\_lp\_det (int8) | yolov8s\_relu6\_lp\_ocr\_7ch (int8)         |

## Custom Models

While the model registry provides optimized models for all supported platforms, you can also use custom models by creating `ModelSpec` objects directly. This is useful for:

* Using proprietary license plate detection models
* Testing alternative OCR architectures
* Integrating region-specific models

See [ModelSpec Documentation](https://docs.degirum.com/degirum-tools/model_registry#modelspec) for details on using custom models.

## Model Performance

Performance varies by hardware platform and model complexity. Key factors:

**License Plate Detection:**

* Input resolution: 640×640 pixels
* Typical throughput: 10-100+ FPS depending on hardware
* Detection accuracy optimized for various lighting conditions and angles

**License Plate OCR:**

* Input size: 256×128 pixels per plate
* Extraction time: 1-50ms per plate depending on hardware
* Supports various plate formats and fonts

For production deployments, test with your specific hardware and video resolution to determine optimal settings.

## Pipeline Integration

Both models work together in the LPR pipeline:

1. **Detection Stage:** YOLOv8n detects plate regions in the full frame
2. **Cropping:** Detected regions are cropped and resized to 256×128
3. **OCR Stage:** YOLOv8s extracts text from cropped plate images
4. **Aggregation:** (Tracker only) Bayesian fusion combines results across frames for improved accuracy

This two-stage approach ensures optimal accuracy and performance.
