Periphery.Camera.OpenCvSharp 5.0.0

dotnet add package Periphery.Camera.OpenCvSharp --version 5.0.0
                    
NuGet\Install-Package Periphery.Camera.OpenCvSharp -Version 5.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Periphery.Camera.OpenCvSharp" Version="5.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Periphery.Camera.OpenCvSharp" Version="5.0.0" />
                    
Directory.Packages.props
<PackageReference Include="Periphery.Camera.OpenCvSharp" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Periphery.Camera.OpenCvSharp --version 5.0.0
                    
#r "nuget: Periphery.Camera.OpenCvSharp, 5.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Periphery.Camera.OpenCvSharp@5.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Periphery.Camera.OpenCvSharp&version=5.0.0
                    
Install as a Cake Addin
#tool nuget:?package=Periphery.Camera.OpenCvSharp&version=5.0.0
                    
Install as a Cake Tool

Periphery.Camera.OpenCvSharp

Hand OpenCV frames from a camera you chose by identity, instead of by VideoCapture(0).

dotnet add package Periphery.Camera.OpenCvSharp --prerelease
dotnet add package OpenCvSharp4.runtime.win    # Linux: OpenCvSharp4.official.runtime.linux-x64

This package does not bring OpenCV's native binaries. Without a runtime package, the first OpenCV call throws DllNotFoundException. Capture supports Windows and Linux.

VideoCapture(0) is a position in the OS enumeration order. It changes when a device is replugged or a virtual camera installs, and it cannot tell two identical cameras apart. Periphery selects the camera by VID/PID, serial number, name, or port.

using OpenCvSharp;
using Periphery;
using Periphery.Camera;
using Periphery.Camera.OpenCvSharp;

var device = await Devices.Enumerate()
    .OfCategory(DeviceCategory.Camera)
    .WithUsbId("046D", "0825")          // or .WithSerialNumber("A1B2C3D4") for one of two identical cameras
    .FirstOrDefaultAsync()
    ?? throw new InvalidOperationException("That camera is not attached.");

await using var session = await CameraSession.For(device)
    .MaxResolution(1280, 720)
    .OpenAsync();

await foreach (var frame in session.CaptureAsync())
{
    using (frame)
    using (var bgr = frame.ToBgr())     // every format except Gray16 -> CV_8UC3 BGR
    {
        Cv2.ImShow("preview", bgr);
        Cv2.WaitKey(1);
    }
}

Converting frames

Call Copies Use it when
frame.AsMat() no You convert or measure inside the capture loop. The Mat borrows the frame's pooled buffer, so do not keep it past the returned scope: the buffer is reused for a later frame.
frame.ToMat() yes You need the raw capture format after the frame is released.
frame.ToBgr() yes You want a BGR image. This is the only one that accepts MJPEG.

Convert inside the using (frame) block, and run slow work such as inference after it. A frame you hold keeps a buffer from the camera's pool.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
5.0.0 92 10/2/2026
4.3.0 118 9/23/2026
4.2.0 104 9/16/2026
4.2.0-alpha.1 82 9/9/2026
4.1.0-alpha.2 82 8/30/2026