Getting Started – License Plate Recognition (LPR)

Applies to CapCognition SDK 2.2.x. Use MAUI for Android/iOS and .NET LTS for Windows/Linux/Raspberry Pi. See requirements and licensing.

This page describes how to integrate the CapCognition LPR (License Plate Recognition) module into your .NET or .NET MAUI application.

License notice: The recognition models used by this library may only be used together with a valid CapCognition LPR license. Any other use is strictly prohibited.


Recognition models

The LPR module relies on pre-trained neural-network models to detect and read license plates. These models are not bundled with the NuGet packages and must be made available to the application separately.

There are two ways to provide them:

Mode 1 – Automatic runtime download (default)

On first use, CapCognition downloads the required models automatically and caches them locally. An active internet connection is required the first time the models are needed. After the initial download the cached models are reused on subsequent starts.

This is the quickest way to get started and requires no extra deployment steps.

Mode 2 – Self-deployment (offline / optimised startup)

You can bundle the model files together with your application so that no internet connection is needed at runtime. This is the recommended approach for:

  • production deployments in restricted network environments,
  • reducing cold-start time by skipping the download check.

All models can be downloaded individually or as a ZIP archive from:

https://downloads.capcognition.com/CCML/V2.2/

Keep downloaded .ccml filenames unchanged; renaming an ONNX file does not convert it. The 320n and 640n model choices below map to the exact filenames in the directory examples. Use all three files for CountryLicencePlateThenVehicle.

The subsections below explain where the model files must be placed for each platform.


MAUI – model placement

In a .NET MAUI application the model files must be placed under:

Resources\Raw\

Add each model file to that folder and ensure its Build Action is set to MauiAsset. The library resolves models from this location automatically – no additional path configuration is required.

Example project layout:

MyMauiApp/
└── Resources/
    └── Raw/
        ├── LPR_1.1_320_n.ccml
        ├── Text_1.1_320n.ccml
        └── Vehicle_1.0_320_n.ccml

MAUI – minimal setup

dotnet add package CapCognition.Maui
dotnet add package CapCognition.Maui.LPR
// MauiProgram.cs
using CapCognition.Maui.LPR;
using CapCognition.Maui.Helpers;
using CapCognition.Maui.Common;
using SkiaSharp.Views.Maui.Controls.Hosting;

public static class MauiProgram
{
    public static MauiApp CreateMauiApp()
    {
        var builder = MauiApp.CreateBuilder();

        builder
            .UseMauiApp<App>()
            .UseSkiaSharp()
            .InitializeCapCognition(
            [
                Capture.Use(/*Add your license here*/),
                Recognition.Use(/*Add your license here*/),
                LicensePlateDetection.Use(/*Add your LPR license here*/),
            ]);

        return builder.Build();
    }
}
// Build recognition options (e.g. in your page)
using CapCognition.Maui.LPR;
using CapCognition.Maui.LPR.Shared.Extensions;
using CapCognition.Maui.Core.Shared.Common;

var options = new RecognitionOptionBuilder()
    .AddLicensePlateDetectionRecognitionOption()
        .UseCroppedImageForRecognition()
        .DoAutomaticDetectionOptimization()
        .UseLocalModelsForRecognitionMode(
            LicensePlateDetectionRecognitionOptions.RecognitionModeType.CountryLicencePlateThenVehicle)
            .UseLocalLicensePlateModelFromType(LPModelType.LPModelType320n)
            .UseLocalLicensePlateTextModelFromType(LPTextModelType.LPTextModelType320n)
            .UseLocalVehicleModelFromType(VehicleModelType.VehicleModelType320n)
            .Done()
        .ConfigureOption(option =>
        {
            option.CreateAndPrepareModelsAsync().GetAwaiter().GetResult();
        })
        .Done()
    .Build();

.NET – model placement

In a classic .NET application the model files can reside in any directory of your choosing. The path to that directory must be provided at configuration time via SetLocalModelBasePath.

Example project layout:

MyApp/
├── MyApp.exe
└── Assets/
    ├── LPR_1.1_640_n.ccml
    ├── Text_1.1_640n.ccml
    └── Vehicle_1.0_640_n.ccml

.NET – minimal setup

dotnet add package CapCognition.Net
dotnet add package CapCognition.Net.LicensePlateDetection
using CapCognition.Net;
using CapCognition.Net.LicensePlateDetection.Processor;
using CapCognition.Net.Core.Processing.Common;
using CapCognition.Net.Core.Capture;
using CapCognition.Net.CaptureSources;
using Microsoft.Extensions.Logging;

using var loggerFactory = LoggerFactory.Create(builder => builder.SetMinimumLevel(LogLevel.Information));

// Initialize CapCognition once at program start
CapCognition.Net.Core.CapCognition.Initialize(
    loggerFactory,
    [
        VideoStreamCapturing.Use(/*Add your license here*/),
        LicensePlateDetection.Use(/*Add your LPR license here*/),
    ]);

CaptureControl.Instance.InitializeAsync().GetAwaiter().GetResult();
// Build recognition options
using CapCognition.Net.LicensePlateDetection.Processor;
using CapCognition.Net.Core.Processing.Common;
using CapCognition.Net.LicensePlateDetection.Common;
using CapCognition.Net.LicensePlateDetection.Common.Extensions;
using static CapCognition.Net.LicensePlateDetection.Common.LicensePlateDetectionRecognitionOptions;

var options = new RecognitionOptionBuilder()
    .AddLicensePlateDetectionRecognitionOption()
        .UseCroppedImageForRecognition()
        .DoAutomaticDetectionOptimization()
        .UseLocalModelsForRecognitionMode(RecognitionModeType.CountryLicencePlateThenVehicle)
            .SetLocalModelBasePath("Assets")          // <-- path to your model directory
            .UseLocalLicensePlateModelFromType(LPModelType.LPModelType640n)
            .UseLocalLicensePlateTextModelFromType(LPTextModelType.LPTextModelType640n)
            .UseLocalVehicleModelFromType(VehicleModelType.VehicleModelType640n)
            .Done()
        .Done()
    .Build();

These snippets configure initialization and options; use the linked camera or streaming examples to capture input and consume results. Assets is relative to the working directory: copy model files to the deployed output or supply an absolute path. Offline RTSP use also requires the codec libraries.

With UseLocalModelsForRecognitionMode, the default directory is Assets when SetLocalModelBasePath is omitted. Local-model helpers open the selected files directly: missing files cause an error and do not fall back to a download. To use automatic downloading, configure the standard recognition mode without the UseLocalModelsForRecognitionMode chain.


Next reading