Getting Started

Read a QR code from an image with .NET LTS, or get started with camera recognition in .NET MAUI.

.NET LTS: Read a QR code from an image

1. Create a console application

dotnet new console -n CapCognitionDotNetSample
cd CapCognitionDotNetSample

2. Install the packages

dotnet add package CapCognition.Net
dotnet add package CapCognition.Net.BarcodeScanning
dotnet add package Microsoft.Extensions.Logging.Console

Also install the console logging provider used by the example:

dotnet add package Microsoft.Extensions.Logging.Console

3. Replace Program.cs

Add your license codes at the marked positions and set imagePath to an image containing a QR code.

using CapCognition.Net;
using CapCognition.Net.BarcodeScanning.Common;
using CapCognition.Net.BarcodeScanning.Processor;
using CapCognition.Net.Core.Processing.Common;
using Microsoft.Extensions.Logging;
using SkiaSharp;

// 1) Hard-coded input image path
const string imagePath = "qrcode.png";

// 2) Logging (optional but recommended)
using var loggerFactory = LoggerFactory.Create(builder =>
{
    builder.SetMinimumLevel(LogLevel.Information);
    builder.AddConsole();
});

// 3) Initialize CapCognition once at program start
CapCognition.Net.Core.CapCognition.Initialize(
    loggerFactory,
    [
        BarcodeRecognition.Use(/*Add your license code here*/),
    ]);

// Optional: enables additional image-processing logs
CapCognition.Net.Core.CapCognition.EnableImageProcessingLogs = true;

// 4) Create QR-only recognition options
var optionBuilder = new RecognitionOptionBuilder();
optionBuilder.AddBarcodeRecognitionOption()
    .TryInverted()
    .SetBinarizer(BarcodeRecognitionOptions.BinarizerType.AdaptiveHybridBinarizer)
    .SetBarcodeFormats(new[] { BarcodeRecognitionOptions.BarcodeFormat.QRCode })
    .Done();

var recognitionOptions = optionBuilder.Build();

try
{
    // 5) Load image and recognize
    using var recognizer = new Recognizer();
    using var bitmap = SKBitmap.Decode(imagePath);
    if (bitmap == null)
    {
        Console.WriteLine($"Could not load image: {imagePath}");
        return;
    }

    var prepared = recognizer.PrepareProcessorsAsync(bitmap.Width, bitmap.Height, recognitionOptions)
        .GetAwaiter().GetResult();
    if (!prepared)
    {
        Console.WriteLine("Failed to prepare processors");
        return;
    }

    var result = recognizer.ProcessImageAsync(bitmap, disableBitmapDisposal: true).GetAwaiter().GetResult();
    if (result == null || result.Results.Count == 0)
    {
        Console.WriteLine("No QR code detected");
        return;
    }

    Console.WriteLine($"Detected {result.Results.Count} element(s)");
    Console.WriteLine(result);
}
finally
{
    recognitionOptions.Dispose();
}

4. Run the application

dotnet run

The application prints the number of detected elements, or a message if no QR code was detected.

.NET Quickstart and prerequisites

.NET MAUI: Start with camera recognition

1. Create a MAUI application

dotnet new maui -n CapCognitionMauiSample
cd CapCognitionMauiSample

2. Install the packages

dotnet add package CapCognition.Maui
dotnet add package CapCognition.Maui.BarcodeScanning

3. Initialize the SDK in MauiProgram.cs

Add your license codes at the marked positions.

using CapCognition.Maui.BarcodeScanning;
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*/),
                BarcodeDetection.Use(/*Add your license here*/),
            ],
            enableProcessingLogs: true);

        return builder.Build();
    }
}

4. Add the camera view and recognition events

Continue with the MAUI Quickstart for the complete XAML page, camera permissions, QR-code options and result handling.

Complete MAUI Quickstart