CvInspect.Imaging
0.22.0
dotnet add package CvInspect.Imaging --version 0.22.0
NuGet\Install-Package CvInspect.Imaging -Version 0.22.0
<PackageReference Include="CvInspect.Imaging" Version="0.22.0" />
<PackageVersion Include="CvInspect.Imaging" Version="0.22.0" />
<PackageReference Include="CvInspect.Imaging" />
paket add CvInspect.Imaging --version 0.22.0
#r "nuget: CvInspect.Imaging, 0.22.0"
#:package CvInspect.Imaging@0.22.0
#addin nuget:?package=CvInspect.Imaging&version=0.22.0
#tool nuget:?package=CvInspect.Imaging&version=0.22.0
CvInspect.Imaging
Camera acquisition contract and tame frame sources for the CvInspect machine-vision toolkit, based on OpenCvSharp.
ICam— the acquisition contract: open/close, single grab, continuous grab, connection/grabbing events, best-effort exposure control. Frames are GC-ownedCamFramebuffers (byte[]+ width/height/stride/format/timestamps) with no lifetime contract —frame.AsMat()gives a zero-copyMatview for inspection, and the type implements the coreICvPixelSourcecontract, soCvDispCtrl(CvInspect.Wpf) displays it by reference without copying. A frame carries two clocks:TimestampUtcis when it arrived, andDeviceTimestampis when the camera captured it (null if the device does not report one). The device clock has its own epoch, so compare frames to each other rather than reading it as wall time — the change in the gap between the two is time the frame spent waiting.VirtualCam— no-hardware source: a shifting-gradient test pattern, or name-ordered cyclic replay of an image folder (CamOpt.VirtualImageDir), re-enumerated on folder change. Ideal for development, demos and CI regression runs. Note: color→gray decoding follows OpenCV's decoder coefficients, so pixel values may differ slightly from images converted by other stacks (e.g. GDI luma) — build regression baselines through the same path.VideoCaptureCam— webcam (device index), video file (paced byFrameRate, loops at end) or stream URL (RTSP, …) through OpenCVVideoCapture(CamOpt.VideoSource).CamFactory—ComTypestring → implementation, withRegisteras the injection point for vendor SDK adapters (GigE etc.) so this package never references heavy SDKs.
Quick start
using CvInspect.Imaging;
var cam = CamFactory.Create(new CamOpt
{
ComType = "Virtual", // or "VideoCapture", or a registered vendor ComType
VirtualImageDir = @"D:\samples", // empty → test pattern
FrameRate = 10,
});
cam.FrameAcquired += (_, frame) =>
{
using var mat = frame.AsMat(); // zero-copy view into frame.Pixels
// ... run CvInspect tools, update display ...
// frame itself is GC-owned — keep it or hand it to another thread freely.
};
cam.Open();
cam.StartContinuous();
Frame lifetime
CamFrame is a GC-owned byte[] holder — there is no lifetime contract: keep it,
queue it, or post it to a UI dispatcher as-is. AsMat() wraps the pixel buffer without
copying (disposing the view only unpins; the pixels stay valid), so running CvInspect
tools costs no conversion. Sources materialize one buffer per frame; frames already have
CamOpt.Flip / Rotation applied.
Two more contract points implementers must honor: only complete frames are published
(corrupt / partially received frames are dropped with a CvLog warning, never delivered),
and Stride may exceed width × bytes-per-pixel on devices that pad rows — consumers
must always walk rows by Stride (AsMat() handles this automatically).
USB webcams — a stable identity
OpenCV opens webcams by index, and the index is whatever order the OS enumerated the devices in
this time. Re-plug a hub, reboot, add a capture card, and camera 0 and camera 1 swap without a
warning. VideoCaptureCam therefore accepts an identity in CamOpt.SerialNumber:
new CamOpt { ComType = "VideoCapture", SerialNumber = "VID_046D&PID_082D" }
Accepted keys: VID_046D&PID_082D, 046D:082D, a full Windows instance id
(USB\VID_046D&PID_082D\5&2C1F7A8&0&0001) or a Linux /dev/v4l/by-id name. When the key is not
found, the exception lists every enumerated device so you can copy the right one into the
settings; when two identical models match a VID/PID, it refuses to guess and lists their instance
ids. UsbCamId.Enumerate() gives you the same list programmatically. UserSettings may carry
backend=dshow|msmf|v4l2|any to pin the OpenCV backend.
| OS | How | Verified |
|---|---|---|
| Windows | SetupAPI enumeration of KSCATEGORY_VIDEO; the enumeration position is the OpenCV index |
Verified on a Windows 11 PC with two cameras of different models (built-in + external): the enumeration position matched the OpenCV index for the ANY, DSHOW and MSMF backends alike, and opening by VID/PID returned the right camera. The code it was ported from also ran on a two-webcam production line. Not yet exercised: identical models (instance-id path), hot re-plug |
| Linux | /sys/class/video4linux + device/modalias for VID/PID, /dev/v4l/by-id for the instance; opens by /dev/videoN path, so ordering never matters |
Not run on hardware — only a synthetic-sysfs regression. net8.0 asset only (symlink resolution) |
| macOS | — | Unsupported: Enumerate() throws; use VideoSource with an index |
Vendor adapters
Implement ICam in your application (or an adapter package) against the vendor SDK —
materialize SDK buffers into CamFrame directly (or via CamFrame.FromMat) — and
register it once at startup:
CamFactory.Register("MyGigE", opt => new MyGigECam(opt));
Proprietary SDK assemblies stay out of this package by design.
Targets
netstandard2.1 and net8.0. Depends on CvInspect (managed OpenCvSharp4 flows
transitively); the native OpenCV runtime is chosen by the consuming application —
VideoCaptureCam additionally needs the videoio backend for your source type
(the Windows runtime bundles it).
License
Apache-2.0. Not affiliated with OpenCV or OpenCvSharp.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. 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 was computed. 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. |
| .NET Core | netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.1 is compatible. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
NuGet packages (1)
Showing the top 1 NuGet packages that depend on CvInspect.Imaging:
| Package | Downloads |
|---|---|
|
CvInspect.Imaging.Gev
GigE camera acquisition for the CvInspect toolkit - an ICam backend that speaks the protocol directly, with no vendor SDK and no proprietary DLLs. Serial-number binding with actionable discovery diagnostics, user-set load, exposure control across SFNC generations, and PFNC pixel conversion including Bayer demosaic with phase diagnostics. Run against real hardware with no vendor SDK installed - a monochrome pair on a bench and a colour pair acquiring on an inspection line - but hours of run time, not months. Only a few models have been exercised, so treat other cameras as unproven. |
GitHub repositories
This package is not used by any popular GitHub repositories.