Getting Started (.NET)

Applies to CapCognition SDK 2.2.x, targeting .NET 10 on Windows x64, Linux x64, or Linux ARM64 (Raspberry Pi). See requirements and licensing.

This page shows the simplest end-to-end "recognize" scenario for the CapCognition .NET SDK:

  • initialize the library once at program start
  • configure the Recognizer to run barcode recognition only
  • restrict recognition to QR codes only
  • load an image from a hard-coded file path
  • process the image and print the result

1. Create a console app

dotnet new console -n CapCognitionDotNetSample
cd CapCognitionDotNetSample

2. Install NuGet packages

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

3. Minimal "recognize" program (QR only)

Place an image containing a QR code at qrcode.png in the working directory. Replace Program.cs with the example and run dotnet run. It prints the detection count and result details. This image-only example does not initialize video capture or download RTSP codecs.

Leave BarcodeRecognition.Use() without an argument for trial mode, or pass your production license string.

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();
}

RTSP Streaming – Third-Party Codec Libraries

To enable video streaming and decoding via RTSP, CapCognition relies on third-party codec libraries.

Automatic download vs. self-deployment

These libraries are not bundled with the NuGet packages. They are handled in one of two ways:

  • Automatic download (default): On first use, CapCognition downloads the required libraries at runtime. An active internet connection is required for this.
  • Self-deployment (offline): You can ship the libraries alongside your application so that no internet connection is needed at runtime. This is the recommended approach for production deployments.

Downloading the libraries manually

All libraries are available at:

https://downloads.capcognition.com/CCCodecLibs/

You can download them as a single ZIP archive or as individual files per platform.

Platform directories

Each supported platform has a dedicated subdirectory. Place the corresponding libraries in that subdirectory relative to your application's base directory (AppContext.BaseDirectory):

Platform Directory
ARM 64-bit Arm64
Linux 64-bit Lx64
Windows 64-bit Win64

The base directory is the deployed application directory, which can differ from the current working directory used for relative image/model paths. Deploy the native libraries matching your SDK version; a folder containing a different FFmpeg version is not sufficient.

Important: The directory names are case-sensitive on Linux and ARM platforms. Make sure to use the exact casing shown above.

Fallback behaviour

  • If all libraries are present in the expected directory and pass integrity validation, they are loaded from there.
  • Missing, empty, or incompatible library files trigger an automatic download to the library cache.
  • If the download also fails (e.g. no internet access), CaptureControl.Instance.InitializeAsync() will not be able to initialize and the RTSP streaming functionality will be unavailable.

Next reading