LDVision.Net
3.2.0
dotnet add package LDVision.Net --version 3.2.0
NuGet\Install-Package LDVision.Net -Version 3.2.0
<PackageReference Include="LDVision.Net" Version="3.2.0" />
<PackageVersion Include="LDVision.Net" Version="3.2.0" />
<PackageReference Include="LDVision.Net" />
paket add LDVision.Net --version 3.2.0
#r "nuget: LDVision.Net, 3.2.0"
#:package LDVision.Net@3.2.0
#addin nuget:?package=LDVision.Net&version=3.2.0
#tool nuget:?package=LDVision.Net&version=3.2.0
LDVision.Net
LDVision industrial camera .NET SDK — by Xi'an LeadingOE Optoelectronics Technology Co., Ltd.
GigE Vision / USB3 Vision / GenTL (Camera Link, CoaXPress frame grabbers) — three camera classes share one API: discovery, connection, parameter read/write, acquisition, image processing. The package embeds native libraries for every platform; reference and use, no separate runtime installation on the target machine.
Installation
dotnet add package LDVision.Net
API Change History
This table records only official releases with public API changes, ordered from newest to oldest. Official releases not listed and all pre-releases introduced no public API changes requiring migration; consult the CHANGELOG for behavior fixes and other version information.
The complete per-symbol change list (covering every official release) is in API Change Details.
When upgrading across multiple major versions, apply each version's migration guide in sequence; their contents do not supersede one another. For example, when upgrading from 1.x to 3.0, first complete the changes listed in the 2.0 Migration Guide, then apply the 3.0 Migration Guide.
| Version | Public API | Changes | Details |
|---|---|---|---|
| 3.2.0<br>2026-11-19 | ABI upgrade | Adds stream-level flat-field correction, shared compute-thread settings, effective device timestamp frequency, and diagnostic callbacks. ABI 3.1 → 3.2 requires upgrading the native library, CTIs, and wrappers together. | 3.2.0 API Change Details |
| 3.1.1<br>2026-11-06 | Added (compatible) | Added frame metadata validity flags LDV_BUFFER_FLAG_*_UNKNOWN (5 flags); when a flag is set, a zero value in the corresponding field must not be treated as a measured value. The C++ / C# / Python grab results and converted frame info provide 5 validity queries such as HasFrameId.<br>Added LDV_Stream_GetDiagnosticCounter to query optional cumulative diagnostic counters by name.<br>Same ABI version as 3.1.0; drop-in replacement. |
3.1 Migration Guide |
| 3.1.0<br>2026-11-03 | ⚠️ Breaking | ⚠️ The preprocessing configuration LDV_PreprocessConfig_t grew from 40 to 60 bytes (new SwitchingMedian / Bilateral / Guided denoising parameters); the setter rejects the old size. Wrappers and the native library must be upgraded together and rebuilt; the ABI version rose to 3.1, and mixing versions reports "ABI version mismatch" on connect.<br>⚠️ LDV_Device_Enumerate no longer returns third-party GenTL devices; the name and signature are unchanged, so no compile error occurs. Use the new LDV_Gentl_EnumerateDevices for third-party devices.<br>Added 16 exported functions: SDK lifecycle and global configuration (5, including LDV_Sdk_Initialize), GenTL enumeration and Producer directories (4), stream packet backend queries (2), saving a static IP from enumeration info (1), and U3V serial bridge (4); all three wrappers provide them as well. |
3.1 Migration Guide |
| 3.0.0<br>2026-09-14 | ⚠️ Breaking | 10 C ABI export names renamed (timeout / auto exposure-gain switch / UserSet save / frame rate enable / bits per pixel); corresponding members in the C++ / C# / Python wrappers renamed as well (5 items in C#); C++ additionally removed the get_ prefix from 43 parameterless read accessors.<br>⚠️ Two Python members changed return type without a name change, producing no error but incorrect results: Device.pixel_format changed from a string to a PFNC numeric code, and Device.trigger_mode from bool to an enumeration.<br>For frames with line padding / multiple zones, LDV_Buffer_ToImage and LDV_Stream_ConvertLatestInto now return LDV_ERR_NOT_SUPPORTED (previously they converted assuming a tightly packed layout, producing images with misordered rows and no warning). |
3.0 Migration Guide |
| 2.0.0<br>2026-09-04 | ⚠️ Breaking | Streaming was separated from Device into an independent Stream object; Buffer ownership changed to reference counting; all 212 C functions were renamed into nine groups (Sdk/Error/Log/Gentl/Device/Stream/Buffer/PixelFormat/Image).<br>The NuGet package identifier also changed: LDVisionCamera.Net → LDVision.Net. These are different packages (nuget.org does not allow changing the identifier of a published package); the old package ended at 1.2.0 and has been unlisted. When upgrading, change both the package name and the version; changing only the version will not resolve to this package. |
2.0 Migration Guide |
1.x belongs to the old package
LDVisionCamera.Net, which has been unlisted and is no longer maintained. See the 2.0.0 row above for the upgrade path.
Quick Start
Recommended style: examples use fully qualified names for core entries:
LDVision.Device,LDVision.Image,LDVision.PixelFormat,LDVision.Sdk,LDVision.Error,LDVision.Logging,LDVision.GenTL.Device,Image,Errorare common in GUI and image-processing projects; full names avoid ambiguity with same-named types from other namespaces; ordinary parameter types can still be shortened viausing LDVision;.
using LDVision;
// 1. Discover devices (unified GigE / U3V / GenTL list, distinguished by DeviceType)
var devices = LDVision.Device.Enumerate(1000);
if (devices.Count == 0) return;
// 2. Open (or direct via LDVision.Device.Create("192.168.1.10") or serial number)
using var cam = LDVision.Device.Create(devices[0]);
cam.Open();
cam.Disconnected += (s, e) => Console.WriteLine($"Camera disconnected: 0x{e.ExceptionType:X4}");
// 3. Parameters
cam.ExposureTime = 10000.0; // µs (SFNC convenience property)
cam.Gain = 2.0; // dB
cam.SetEnumValueByString("TriggerMode", "Off"); // generic by-name write
// 4. Acquire
cam.Stream.Start();
using (GrabResult frame = cam.Stream.RetrieveResult(2000)) // timeout ms
{
Console.WriteLine($"Frame {frame.FrameId}: {frame.Width}x{frame.Height}");
LDVision.Image.SaveToFile(frame, "shot.png", ImageFormat.Png);
}
cam.Stream.Stop();
Core Objects and Entries
| Entry | Type | Responsibility |
|---|---|---|
Device |
Static members + instances (cam in examples) |
Enumeration, camera creation, and per-camera open/close, parameters, acquisition, events |
Image |
Class (IDisposable) |
Image buffer: conversion results holding native memory, needs using; static members handle conversion, saving, imgproc thread count |
PixelFormat |
Static class | Pixel formats: PFNC code constants + format name / bit depth / source profile |
Sdk |
Static class | SDK version, ABI, build time |
Error |
Static class | Error code descriptions and this thread's most recent failure details |
Logging |
Static class | Process-level logging configuration (not named Log: would collide with Serilog's static Log) |
GenTL |
Static class | Producer registration and queries |
DeviceException |
Exception type | Carries the error code on SDK call failure; asynchronous errors via cam.LastAsyncError() and cam.Disconnected |
Locating Static Members by Responsibility
All members:
| Category | Members | Returns | Description |
|---|---|---|---|
| Version / ABI | LDVision.Sdk.Version / LDVision.Sdk.BuildDateUtc / LDVision.Sdk.EnsureAbiCompatible() |
— | SDK and ABI information |
| Logging | LDVision.Logging.SetLevel(...) / LDVision.Logging.SetCallback(...) |
void |
Process-level logging configuration |
| Error details | LDVision.Error.Describe(code) / LDVision.Error.Last() |
string |
Error code descriptions and this thread's most recent error details |
| Devices | LDVision.Device.Enumerate(...) / LDVision.GenTL.EnumerateDevices(...) / Device.Create(...) |
— | Separate enumeration for direct and third-party, unified device creation |
| Device probing | LDVision.Device.IsAccessible(...) / LDVision.Device.ProbeMulticast(...) / LDVision.Device.ForceIp(...) |
— | Pre-open network operations |
| GenTL | LDVision.GenTL.AddProducer(...) / RemoveProducer(...) / Producers() |
— | Producer management |
// Version and ABI
Console.WriteLine(LDVision.Sdk.Version); // e.g. "1.0.0-rc.27"
Console.WriteLine(LDVision.Sdk.BuildDateUtc); // native SDK build time (UTC)
LDVision.Sdk.EnsureAbiCompatible(); // verify managed/native ABI match (throws on mismatch)
// Logging: route SDK internal logs into the caller's own logging system
LDVision.Logging.SetLevel(2); // level threshold
LDVision.Logging.SetCallback((level, msg) => MyLogger.Write(msg));
// Error code translation
string text = LDVision.Error.Describe(-10); // error code → readable text
string last = LDVision.Error.Last(); // most recent error details
// Device discovery and creation (three creation methods)
IReadOnlyList<DeviceInfo> devs = LDVision.Device.Enumerate(1000); // timeout ms
LDVision.Device cam1 = LDVision.Device.Create(devs[0]); // ① from enumeration info (recommended)
LDVision.Device cam2 = LDVision.Device.Create("192.168.1.10"); // ② direct by IP
LDVision.Device cam3 = LDVision.Device.Create("SN12345678"); // ③ direct by serial number
// Pre-connect reachability probe: connectable or already held by another program
AccessState st = LDVision.Device.IsAccessible("192.168.1.10");
// Force the camera IP when on a different subnet than the local adapter (GigE)
LDVision.Device.ForceIp("00:11:22:33:44:55", "192.168.1.10", "255.255.255.0", "192.168.1.1");
// GenTL: accessing frame grabber vendor cameras (Camera Link / CoaXPress)
LDVision.GenTL.AddProducer(@"C:\vendor\xxx.cti"); // register a vendor Producer manually
LDVision.GenTL.RemoveProducer(@"C:\vendor\xxx.cti");
IReadOnlyList<string> producers = LDVision.GenTL.Producers(); // currently registered Producers
LDVision.GenTL.SetEnvironmentProducerDiscoveryEnabled(false); // enumerate only manually registered CTIs
bool enabled = LDVision.GenTL.GetEnvironmentProducerDiscoveryEnabled();
LDVision.GenTL.RefreshProducerCatalog(); // re-read path directories; does not enumerate cameras
By default, the first GenTL use scans
.ctifiles under the environment variableGENICAM_GENTL64_PATH; subsequent device enumerations reuse the catalog snapshot. CallRefreshProducerCatalog()after environment variable or directory changes.
Parameter Read/Write
All of the following are operations on a Device (cam) instance. Parameters have two access styles; the simpler one first:
Style One: Convenience Properties — Direct Read/Write of Common Parameters
Same usage as ordinary C# properties — assignment writes, reading reads:
cam.ExposureTime = 10000.0; // write: set to 10000 µs
double us = cam.ExposureTime; // read: returns the current value 10000.0
cam.Gain = 2.0; // write gain (dB)
cam.Width = 1920; // write resolution
cam.TriggerMode = TriggerMode.On;
Available convenience properties:
| Category | Property | Type | Description |
|---|---|---|---|
| Exposure/gain | ExposureTime |
double |
Exposure time, µs |
Gain |
double |
Gain, dB | |
ExposureAuto / GainAuto |
AutoMode |
Auto mode three states (Off/Once/Continuous) | |
ExposureAutoEnabled / GainAutoEnabled |
bool |
Switch views of the two above (lossy: cannot express Once) |
|
| Frame rate | FrameRate |
double |
Acquisition frame rate, fps |
FrameRateEnabled |
bool |
Free run when off; limited to FrameRate when on |
|
| Image area | Width / Height |
long |
Resolution, pixels |
OffsetX / OffsetY |
long |
ROI offsets | |
PixelFormat |
uint |
Pixel format code | |
PixelFormatName |
string |
Pixel format name (read-only, e.g. "Mono8") |
|
| Trigger | TriggerMode |
TriggerMode |
Trigger switch |
TriggerSource |
TriggerSource |
Trigger source | |
| Device | Temperature |
float |
Device temperature, °C (read-only) |
TemperatureSource |
TemperatureSource |
Temperature source selection | |
LinkState |
LinkState |
Link state (read-only) | |
IsOpen |
bool |
Whether opened (read-only) | |
| Connection/recovery | AutoReconnectWindowMs |
int |
Automatic reconnection window ms, <=0 disables |
HeartbeatTimeoutMs |
int |
Heartbeat timeout | |
LinkLostThreshold |
int |
Link-loss determination threshold | |
| Acquisition tuning | PacketSize |
int |
Stream packet size (GigE) |
PacketDelay |
uint |
Inter-packet delay | |
FrameProgressTimeoutMs |
uint |
Watchdog for a frame's reassembly making no progress (not the grab-wait timeout) | |
IncompleteFrameDelivery |
bool |
Whether incomplete frames are delivered | |
ReceiveBufferSize |
uint |
Receive buffer | |
| Cooling/correction | TecTemperature |
int |
TEC target temperature °C (write = setpoint, read = measured) |
TecEnabled |
bool |
TEC switch | |
NucCorrectionEnabled |
bool |
Non-uniformity correction | |
DefectPixelCorrectionEnabled |
bool |
Defect pixel correction | |
| Other | PreprocessConfig |
PreprocessConfig |
Preprocessing configuration |
ActivePacketBackend |
PacketBackend |
Current packet backend (read-only) |
When the camera does not support a capability, reading/writing the corresponding property throws
DeviceException.
Style Two: By Name — Any GenICam Parameter
Convenience properties cover only common items. Any parameter in the camera XML can be accessed by name; reads come in three tiers:
| Information needed | Interface |
|---|---|
| Current value only | GetInt / GetFloat / GetBool / GetEnumString |
| Current value + range/step | GetIntParam / GetFloatParam / GetStringParam (with MaxLength) |
| Current value + option list | GetEnumParam |
// ① Current value only
long w = cam.GetIntValue("Width");
double exp = cam.GetFloatValue("ExposureTime");
bool on = cam.GetBoolValue("AcquisitionFrameRateEnable");
string mode = cam.GetEnumValueByString("TriggerMode"); // "Off"
// ② Current value + range / step — for numeric input boxes, sliders
FloatParam e = cam.GetFloatParam("ExposureTime");
Console.WriteLine($"{e.Value} ∈ [{e.Min}, {e.Max}] step {e.Inc}, decimals {e.DisplayPrecision}");
IntParam iw = cam.GetIntParam("Width");
Console.WriteLine($"{iw.Value} ∈ [{iw.Min}, {iw.Max}] step {iw.Inc}, repr {iw.Representation}");
// ③ Current value + all supported entries — for dropdowns
EnumParam p = cam.GetEnumParam("PixelFormat");
foreach (EnumEntry entry in p.Entries)
Console.WriteLine($"{entry.Name} = {entry.Value}"); // Mono8=17301505, ...
Console.WriteLine($"current: {p.CurrentValue}");
Min/Max/Incexist only for integer and float types; enumerations provide option lists, strings provideMaxLength.
Writing
cam.SetIntValue("Width", 1920);
cam.SetFloatValue("ExposureTime", 5000.0);
cam.SetBoolValue("AcquisitionFrameRateEnable", true);
cam.SetEnumValueByString("TriggerMode", "On"); // by symbolic name (recommended)
cam.SetEnumValueByString("TriggerMode", 1u); // or by numeric value
cam.SetStringParam("DeviceUserID", "cam-01");
cam.ExecuteCommand("TriggerSoftware"); // Command node
Querying Which Parameters the Camera Supports
// Flat catalog
foreach (var item in cam.ParameterCatalog)
Console.WriteLine($"[{item.Kind}] {item.Name} ({item.Category})");
// Tree browsing (for building property tree UIs)
var root = cam.RootParameterNode;
foreach (var child in cam.GetParameterChildren(root))
Console.WriteLine(child.Name);
// Full information of a single node (display name, unit, tooltip, visibility…)
ParamFeature f = cam.GetParameterFeature("ExposureTime");
// Currently writable or not (NI=not implemented / NA=not available / RO / RW)
var mode = cam.GetParameterAccessMode("ExposureTime");
GetParameterAccessModeis the authoritative criterion for "writable right now" — the camera's interlocking constraints (e.g.ExposureTimeread-only while auto exposure is on) are all reflected here; UI graying should follow it.
Acquisition
// ① Active grabbing
cam.Stream.Start();
using (GrabResult frame = cam.Stream.RetrieveResult(2000)) { /* ... */ }
// ② Raw callback (fires on frame arrival, zero heap allocation per frame; no heavy work inside)
cam.Stream.RegisterBufferCallback((in GrabResult g) => {
Console.WriteLine($"{g.FrameId} {g.Width}x{g.Height}");
});
cam.Stream.Start();
// ③ Triggered acquisition
cam.SetEnumValueByString("TriggerMode", "On");
cam.SetEnumValueByString("TriggerSource", "Software");
cam.ExecuteCommand("TriggerSoftware");
// Acquisition quality monitoring (loss/drop statistics)
GrabStats st = cam.Stream.Stats;
Console.WriteLine($"complete {st.FramesComplete} / incomplete-dropped {st.FramesIncomplete} / net lost {st.NetLostPackets}");
Getting a Frame's Pixel Data
using (GrabResult f = cam.Stream.RetrieveResult(2000))
{
byte[] data = f.ToArray(); // ① take a copy (simple, safe)
IntPtr ptr = f.DataPointer; // ② use the pointer directly (zero-copy, valid only inside the using block)
int len = f.Length;
if (f.IsIncomplete) // incomplete frame due to packet loss
Console.WriteLine($"{f.LostPackets} packets missing");
} // leaving the using block returns the frame to the SDK buffer pool — DataPointer must not be used outside
Frame metadata: Width / Height / OffsetX / OffsetY / PixelFormat / FrameId /
FrameCounter / DeviceTimestampNs / HostTimestampNs / IsIncomplete / LostPackets /
ExpectedPayloads / ReceivedPayloads, etc.
Always use
using(or manualDispose). Frames use the SDK buffer pool; not releasing exhausts the pool and causes frame drops.
Multicast: Multiple Programs Receiving the Same Image Simultaneously (GigE)
One acquiring, one inspecting the same stream — no forwarding, no added latency: the controller pushes the stream to a multicast group, and other processes join the group in the "receive-only" role.
// —— Controller (open as usual, one extra line) ——
cam.Open();
cam.Stream.SetDestination("239.192.1.1", 1042); // effective at next Start
cam.Stream.Start();
// —— Receive-only side (another process, possibly on another machine) ——
var (group, port) = LDVision.Device.ProbeMulticast("192.168.1.10"); // ask where the camera is sending first
if (group != null)
{
using var viewer = LDVision.Device.Create("192.168.1.10");
viewer.OpenAsListener(group, port); // requests no control, writes no registers
viewer.Stream.Start(); // receiving is exactly like ordinary cameras
using GrabResult f = viewer.Stream.RetrieveResult(2000);
}
The receive-only role reads parameters as usual ("what exposure is the controller using now"), but all writes throw DeviceException (ACCESS_DENIED), and GetParameterAccessMode uniformly reports read-only — gray out the UI accordingly.
Under multicast the SDK forces off packet size negotiation and GVSP resend (the former would temporarily switch the whole stream away from the group address, interrupting all other receivers). Negotiate the packet size before switching to multicast. Passing
nulltoSetDestinationreturns to unicast (default).
Error Handling
All failures throw DeviceException with the native error code:
try
{
cam.Open();
cam.SetFloatValue("ExposureTime", 999999.0); // out of range
}
catch (DeviceException ex)
{
Console.WriteLine($"{ex.Message} (error code {ex.ErrorCode})");
Console.WriteLine(LDVision.Error.Describe(ex.ErrorCode)); // error code to readable text
}
Device Information
foreach (DeviceInfo d in LDVision.Device.Enumerate(1000))
{
Console.WriteLine($"{d.Manufacturer} {d.ModelName} SN={d.SerialNumber}");
Console.WriteLine($" type {d.DeviceType} firmware {d.FirmwareVersion}");
Console.WriteLine($" GigE: {d.Ip} / {d.Mac} / adapter {d.HostNicIp}");
Console.WriteLine($" U3V : {d.UsbPath} VID={d.VendorId:X4} PID={d.ProductId:X4}");
}
Image Processing and Saving — Image and PixelFormat
Image is an image buffer (conversion results holding native memory, needs using); static members handle conversion and saving; pixel format queries and PFNC constants live in PixelFormat.
| Type | Category | Member | Returns | Description |
|---|---|---|---|---|
Image |
Format conversion | Convert(in GrabResult frame, uint dstFormat, ...) |
Image |
Convert to the target pixel format, returning an Image holding native memory (needs using); for a managed array use .ToArray() |
ConvertInto(in GrabResult frame, uint dstFormat, byte[] dst, ...) |
int |
Convert into a caller-provided buffer (reused array, zero allocation, recommended for high frame rates), returning bytes written. This path produces no Image object |
||
| Saving | SaveToFile(in GrabResult frame, string path, ImageFormat fmt, ...) |
void |
Save BMP / PNG / TIFF / RAW, bit-depth aware | |
| Thread count | SetThreads(uint) / GetThreads() |
— | imgproc parallel thread count, 0/1 = off (default). Process level, must be measured on site |
|
PixelFormat |
Format info | Name(uint code) |
string |
Pixel format code → name (e.g. "Mono8") |
BitsPerPixel(uint code) |
uint |
Storage bits per pixel (Mono12→16, RGB8→24; no table lookup, cannot fail) | ||
TryGetSourceProfile(uint code, out bool isColor, out int bits) |
bool |
Get color flag and bit depth in one call | ||
| PFNC constants | Mono8 / Bgr8 / Rgb8 / BayerRg8 … |
uint |
Common format codes, no need to write bare LDV_PIXEL_* |
Convert/ConvertInto/SaveToFileall have overloads acceptingin GrabResultor raw pointers; optional parametersDemosaicQuality demosaic(demosaic quality) andBitAlign bitAlign(bit alignment).
// Format conversion (Mono / Bayer / RGB 8-16bit, packed 10p/12p, YUV422, with demosaicing)
// Convert returns an Image holding native memory — must using
using (var rgb = frame.Convert(LDVision.PixelFormat.Rgb8))
Console.WriteLine($"{rgb.Width}x{rgb.Height} {rgb.Length} bytes");
// Reuse buffers at high frame rates, avoiding per-frame allocation (no Image object produced)
byte[] buf = new byte[frame.Width * frame.Height * 3];
int written = frame.ConvertInto(LDVision.PixelFormat.Rgb8, buf);
// Saving: BMP / PNG / TIFF / RAW (bit-depth aware)
frame.SaveToFile("out.png", ImageFormat.Png);
// Pixel format information
string name = LDVision.PixelFormat.Name(frame.PixelFormat); // "Mono8"
uint bits = LDVision.PixelFormat.BitsPerPixel(frame.PixelFormat);
if (LDVision.PixelFormat.TryGetSourceProfile(frame.PixelFormat, out bool isColor, out int srcBits))
Console.WriteLine($"{(isColor ? "color" : "mono")} {srcBits} bit");
Parameter Archives and Restoration
cam.SaveFeatures("profile.txt"); // save the whole parameter set
FeatureLoadReport r = cam.LoadFeatures("profile.txt"); // batch-write parameters across devices / models
Console.WriteLine($"applied {r.Applied} / skipped {r.Skipped} / failed {r.Failed}");
// When per-node details are needed
foreach (var entry in cam.LoadFeaturesDetailed("profile.txt"))
Console.WriteLine($"{entry.Node}: {entry.Outcome}");
Other Common Camera-Level Operations
bool open = cam.IsOpen; // whether opened
cam.Close(); // close explicitly (or automatically via using / Dispose)
float t = cam.Temperature; // device temperature °C
var link = cam.LinkState; // link state
cam.AutoReconnectWindowMs = 10000; // automatic reconnection window ms after link loss; <=0 disables
cam.Reconnect(); // manual reconnect
cam.InvalidateNodes(); // when camera-side state changed and the parameter cache must be invalidated
Complete Examples
Samples/CSharp/ delivered with the SDK has 12 directly runnable examples:
BasicGrab / CallbackGrab / EventGrab / TriggerGrab / ParameterTree / ParameterConfig /
Preprocess / SaveImage / Reconnect / GrabStatsMonitor / DirectConnect / SdkToolbox.
Two complete documents, the "LDVision .NET Development Guide" and "LDVision .NET API Reference", are also included (Document/).## Supported Frameworks and Platforms
Managed assembly: multi-targeting netstandard2.0 + net8.0.
| Target | Who uses it |
|---|---|
net8.0 |
.NET 8 and above. Marked IsTrimmable / IsAotCompatible, supporting trimming and Native AOT |
netstandard2.0 |
.NET 7 and below, .NET Core 2.0+, .NET Framework 4.6.1+, Mono / Unity |
Native AOT / trimming: this package is marked AOT-compatible on net8.0 and verified on real hardware — all three callback paths (image callback, acquisition statistics callback, log callback) fire normally in AOT artifacts. Applications enabling
PublishAotget noIL2xxx/IL3xxxwarnings from this SDK.
Embedded native libraries (runtimes/<rid>/native/):
| RID | Description |
|---|---|
win-x64 / win-x86 |
Windows 10 and above |
win-arm64 |
Windows 10 and above (ARM64) |
linux-x64 |
glibc 2.31+ |
linux-arm64 |
glibc 2.31+ (AArch64) |
ARM64 tiers have one fewer packet backend: x64/x86 offer both RIO and XDP high-performance backends; ARM64 compiles in only RIO (Windows) / recvmmsg (Linux), falling back to standard sockets on failure. Features and interfaces are identical; only CPU usage at extreme frame rates is higher than the x64 tiers.
With .NET 5+, native libraries resolve automatically by RID via
deps.json— no manual copying..NET Framework projects need an SDK-style csproj +
PackageReferencewith a RID specified, otherwise the native libraries underruntimes/do not reach the output directory.The current package contains no macOS (
osx-*) native libraries.
This package contains no GenTL Producer (
LDVisionTL.cti). The Producer's purpose is letting third-party machine vision software such as HALCON / VisionPro / harvesters discover the camera; it must be installed system-wide with theGENICAM_GENTL64_PATHenvironment variable registered — the job of the LDVision SDK Runtime installer, which NuGet packages cannot do. Programming with this SDK does not need that component. (The reverse GenTL Consumer — loading grabber vendors'.ctifiles to access CL/CXP cameras — is fully supported by this package.)
Windows 7 Support
This package's native libraries require Windows 10 or above (using Win8+ system APIs). For Win7 use the companion package:
dotnet add package LDVision.Net.Win7
LDVision.Net.Win7 has an API fully identical to this package
(same assembly name; switching packages requires no code changes), only the native libraries are Win7-compatible builds. Choose one of the two packages; they cannot be installed together.
Also note the .NET 5+ runtime itself does not support Win7; for that scenario pair with .NET Framework 4.6.1+ or .NET Core 3.1.
Main Capabilities
- Discovery / connection: concurrent multi-adapter broadcast, USB enumeration, GenTL
.ctiscanning; link-loss detection + automatic reconnection + automatic acquisition restart - Parameters: GenICam XML parsing (including SwissKnife formula evaluation); by-name read/write + SFNC convenience properties; parameter tree browsing, enumeration entries, access modes; parameter archives and restoration
- Acquisition: three modes —
Start/RetrieveResult/ callbacks; GVSP frame reassembly (out-of-order / duplicate / loss tolerance + on-demand resend); U3V Bulk assembly - Images: pixel format conversion (Mono / Bayer / RGB 8–16bit, packed
10p/12p, YUV422, with demosaicing); saving BMP / PNG / TIFF / RAW - Diagnostics: acquisition statistics, loss classification, device temperature, log callbacks
Runtime Environment Notes
- GigE / USB3 Vision: zero extra runtime dependencies (native libraries statically link the CRT; no VC++ Redistributable needed).
- GenTL devices: the target machine needs the grabber vendor runtime installed (shipped with the card driver; not distributed by this SDK).
- USB3 Vision: devices must be bound to the WinUSB driver.
License
Proprietary software, copyright © 2016-2026 Xi'an LeadingOE Optoelectronics Technology Co., Ltd. See LICENSE.txt in the package.
- Website: https://www.leadingoe.com
- Technical support: contact us via the website.
LDVision.Net
LDVision 工业相机 .NET SDK —— 西安立鼎光电科技有限公司出品。
GigE Vision / USB3 Vision / GenTL(Camera Link、CoaXPress 采集卡)三类相机走同一套 API: 发现、连接、参数读写、采集、图像处理。包内自带各平台原生库,引用即用,目标机无需另装运行时。
安装
dotnet add package LDVision.Net
API 变更历史
本表仅记录发生公开 API 变化的正式版本,按版本自新至旧排列。未列出的正式版本及所有 预发布版本均未引入需要迁移的公开 API 变化;行为修复与其它版本信息请查阅 CHANGELOG。
逐个符号的完整变更清单(含历代每个正式版)见 API 变更明细。
跨越多个主版本升级时,各版本的迁移说明须依次执行,其内容互不覆盖。 例如自 1.x 升级至 3.0,应先完成 2.0 迁移说明所列变更,再执行 3.0 迁移说明。
| 版本 | 公开 API | 变动 | 详情 |
|---|---|---|---|
| 3.2.0<br>2026-11-19 | ABI 升级 | 新增流级平场校正、共享计算线程设置、有效设备时间戳频率和诊断回调。ABI 3.1 → 3.2,原生库、CTI 和语言封装须成套升级。 | 3.2.0 API 变更明细 |
| 3.1.1<br>2026-11-06 | 新增(兼容) | 新增帧元数据有效性标志 LDV_BUFFER_FLAG_*_UNKNOWN(5 个),标志置位时对应字段的数值零不能视为实测值;C++ / C# / Python 的取流结果与转换帧信息提供 HasFrameId 等 5 个有效性查询。<br>新增 LDV_Stream_GetDiagnosticCounter 按名称查询可选累计诊断计数。<br>与 3.1.0 的 ABI 版本相同,可直接替换。 |
3.1 迁移说明 |
| 3.1.0<br>2026-11-03 | ⚠️ 破坏性 | ⚠️ 预处理配置 LDV_PreprocessConfig_t 由 40 字节扩展为 60 字节(新增 SwitchingMedian / Bilateral / Guided 降噪参数),设置接口拒绝旧尺寸;封装层与原生库须成套升级并重新构建,ABI 版本升为 3.1,混用时连接即报「ABI 版本不匹配」。<br>⚠️ LDV_Device_Enumerate 不再返回第三方 GenTL 设备,名称与签名未变,不会产生编译错误;第三方设备改用新增的 LDV_Gentl_EnumerateDevices。<br>新增 16 个导出函数:SDK 生命周期与全局配置(LDV_Sdk_Initialize 等 5 个)、GenTL 枚举与 Producer 目录(4 个)、数据流收包后端查询(2 个)、按枚举信息保存静态 IP(1 个)、U3V 串口桥接(4 个);三种封装层同步提供。 |
3.1 迁移说明 |
| 3.0.0<br>2026-09-14 | ⚠️ 破坏性 | C ABI 10 个导出名改名(超时 / 自动曝光增益开关 / UserSet 保存 / 帧率使能 / 每像素位数);C++ / C# / Python 封装层的对应成员一并更名(C# 涉及 5 项);C++ 另有 43 个无参数读取访问器移除 get_ 前缀。<br>⚠️ Python 有两处成员名称未变而返回类型变更,不会产生错误提示,但结果不正确:Device.pixel_format 由字符串改为 PFNC 数值码,Device.trigger_mode 由 bool 改为枚举。<br>带行填充 / 多分区的帧,LDV_Buffer_ToImage 与 LDV_Stream_ConvertLatestInto 改为返回 LDV_ERR_NOT_SUPPORTED(此前将按紧排布局转换,输出行序错位的图像且无任何提示)。 |
3.0 迁移说明 |
| 2.0.0<br>2026-09-04 | ⚠️ 破坏性 | 取流从 Device 剥离为独立的 Stream 对象,Buffer 所有权改为引用计数;C 面 212 个函数按九组(Sdk/Error/Log/Gentl/Device/Stream/Buffer/PixelFormat/Image)全量改名。<br>NuGet 包标识一并变更:LDVisionCamera.Net → LDVision.Net。二者为不同的包(nuget.org 不支持修改已发布包的标识),旧包止于 1.2.0 并已下架。升级时须同时修改包名与版本,仅修改版本号将无法解析到该包。 |
2.0 迁移说明 |
1.x 属于旧包
LDVisionCamera.Net,已下架且不再维护。升级路径见上表 2.0.0 一行。
快速上手
**推荐写法:**示例对核心入口使用完整名称
LDVision.Device、LDVision.Image、LDVision.PixelFormat、LDVision.Sdk、LDVision.Error、LDVision.Logging、LDVision.GenTL。Device、Image、Error在 GUI、图像处理等项目中很常见, 完整名称可避免与其它命名空间的同名类型产生歧义;普通参数类型仍可通过using LDVision;简写。
using LDVision;
// 1. 发现设备(GigE / U3V / GenTL 统一列表,DeviceType 区分)
var devices = LDVision.Device.Enumerate(1000);
if (devices.Count == 0) return;
// 2. 打开(也可 LDVision.Device.Create("192.168.1.10") 或序列号直连)
using var cam = LDVision.Device.Create(devices[0]);
cam.Open();
cam.Disconnected += (s, e) => Console.WriteLine($"相机断开: 0x{e.ExceptionType:X4}");
// 3. 参数
cam.ExposureTime = 10000.0; // µs(SFNC 便捷属性)
cam.Gain = 2.0; // dB
cam.SetEnumValueByString("TriggerMode", "Off"); // 按名通用写
// 4. 采集
cam.Stream.Start();
using (GrabResult frame = cam.Stream.RetrieveResult(2000)) // 超时 ms
{
Console.WriteLine($"帧 {frame.FrameId}: {frame.Width}x{frame.Height}");
LDVision.Image.SaveToFile(frame, "shot.png", ImageFormat.Png);
}
cam.Stream.Stop();
核心对象与入口
| 入口 | 类型 | 职责 |
|---|---|---|
Device |
静态成员 + 实例(示例中的 cam) |
枚举、创建相机,以及单台相机的打开关闭、参数、采集与事件 |
Image |
类(IDisposable) |
图像缓冲:转换结果,持有原生内存需 using;静态成员管转换、存图、imgproc 线程数 |
PixelFormat |
静态类 | 像素格式:PFNC 码常量 + 格式名 / 位深 / 源画像 |
Sdk |
静态类 | SDK 版本、ABI 与构建时间 |
Error |
静态类 | 错误码释义与本线程最近一次失败详情 |
Logging |
静态类 | 进程级日志配置(不叫 Log:会撞 Serilog 的静态 Log) |
GenTL |
静态类 | Producer 注册与查询 |
DeviceException |
异常类型 | SDK 调用失败时包含错误码;异步错误见 cam.LastAsyncError() 和 cam.Disconnected |
按职责定位静态成员
全部成员:
| 分类 | 成员 | 返回 | 说明 |
|---|---|---|---|
| 版本 / ABI | LDVision.Sdk.Version / LDVision.Sdk.BuildDateUtc / LDVision.Sdk.EnsureAbiCompatible() |
— | SDK 与 ABI 信息 |
| 日志 | LDVision.Logging.SetLevel(...) / LDVision.Logging.SetCallback(...) |
void |
进程级日志配置 |
| 错误详情 | LDVision.Error.Describe(code) / LDVision.Error.Last() |
string |
错误码说明与本线程最近错误详情 |
| 设备 | LDVision.Device.Enumerate(...) / LDVision.GenTL.EnumerateDevices(...) / Device.Create(...) |
— | 直连与第三方分路枚举,统一创建设备 |
| 设备探测 | LDVision.Device.IsAccessible(...) / LDVision.Device.ProbeMulticast(...) / LDVision.Device.ForceIp(...) |
— | 打开前网络操作 |
| GenTL | LDVision.GenTL.AddProducer(...) / RemoveProducer(...) / Producers() |
— | Producer 管理 |
// 版本与 ABI
Console.WriteLine(LDVision.Sdk.Version); // 如 "1.0.0-rc.27"
Console.WriteLine(LDVision.Sdk.BuildDateUtc); // 原生 SDK 构建时间(UTC)
LDVision.Sdk.EnsureAbiCompatible(); // 校验托管层与原生库 ABI 匹配(不匹配抛异常)
// 日志:将 SDK 内部日志接入调用方自有日志系统
LDVision.Logging.SetLevel(2); // 级别阈值
LDVision.Logging.SetCallback((level, msg) => MyLogger.Write(msg));
// 错误码翻译
string text = LDVision.Error.Describe(-10); // 错误码 → 可读文本
string last = LDVision.Error.Last(); // 最近一次错误详情
// 设备发现与创建(三种创建方式)
IReadOnlyList<DeviceInfo> devs = LDVision.Device.Enumerate(1000); // 超时 ms
LDVision.Device cam1 = LDVision.Device.Create(devs[0]); // ① 由枚举信息创建(推荐)
LDVision.Device cam2 = LDVision.Device.Create("192.168.1.10"); // ② 由 IP 直连
LDVision.Device cam3 = LDVision.Device.Create("SN12345678"); // ③ 由序列号直连
// 连接前可达性探测:是否可连接、是否已被其它程序占用
AccessState st = LDVision.Device.IsAccessible("192.168.1.10");
// 相机 IP 与本机网卡不同网段时,强制改相机 IP(GigE)
LDVision.Device.ForceIp("00:11:22:33:44:55", "192.168.1.10", "255.255.255.0", "192.168.1.1");
// GenTL:接入采集卡厂商的相机(Camera Link / CoaXPress)
LDVision.GenTL.AddProducer(@"C:\vendor\xxx.cti"); // 手动注册厂商 Producer
LDVision.GenTL.RemoveProducer(@"C:\vendor\xxx.cti");
IReadOnlyList<string> producers = LDVision.GenTL.Producers(); // 当前已注册的 Producer
LDVision.GenTL.SetEnvironmentProducerDiscoveryEnabled(false); // 只枚举手动注册的 CTI
bool enabled = LDVision.GenTL.GetEnvironmentProducerDiscoveryEnabled();
LDVision.GenTL.RefreshProducerCatalog(); // 重读路径目录,不枚举相机
默认首次使用 GenTL 时扫描环境变量
GENICAM_GENTL64_PATH下的.cti;后续设备枚举复用目录快照。环境变量或目录变化后需调用RefreshProducerCatalog()。
参数读写
以下均为 Device(cam)实例上的操作。参数有两种访问方式,先介绍较简单的一种:
方式一:便捷属性 —— 常用参数直接读写
与普通 C# 属性用法一致,赋值即写、取值即读:
cam.ExposureTime = 10000.0; // 写:设为 10000 µs
double us = cam.ExposureTime; // 读:返回当前值 10000.0
cam.Gain = 2.0; // 写增益(dB)
cam.Width = 1920; // 写分辨率
cam.TriggerMode = TriggerMode.On;
可用的便捷属性:
| 分类 | 属性 | 类型 | 说明 |
|---|---|---|---|
| 曝光/增益 | ExposureTime |
double |
曝光时间,µs |
Gain |
double |
增益,dB | |
ExposureAuto / GainAuto |
AutoMode |
自动模式三态(Off/Once/Continuous) | |
ExposureAutoEnabled / GainAutoEnabled |
bool |
上面两个的开关视图(有损:表达不了 Once) |
|
| 帧率 | FrameRate |
double |
采集帧率,fps |
FrameRateEnabled |
bool |
关闭时自由运行,开启时按 FrameRate 限速 |
|
| 图像区域 | Width / Height |
long |
分辨率,像素 |
OffsetX / OffsetY |
long |
ROI 偏移 | |
PixelFormat |
uint |
像素格式码 | |
PixelFormatName |
string |
像素格式名(只读,如 "Mono8") |
|
| 触发 | TriggerMode |
TriggerMode |
触发开关 |
TriggerSource |
TriggerSource |
触发源 | |
| 设备 | Temperature |
float |
设备温度,°C(只读) |
TemperatureSource |
TemperatureSource |
温度源选择 | |
LinkState |
LinkState |
链路状态(只读) | |
IsOpen |
bool |
是否已打开(只读) | |
| 连接/恢复 | AutoReconnectWindowMs |
int |
自动重连窗口 ms,<=0 关闭 |
HeartbeatTimeoutMs |
int |
心跳超时 | |
LinkLostThreshold |
int |
判定掉线的阈值 | |
| 采集调优 | PacketSize |
int |
流包大小(GigE) |
PacketDelay |
uint |
包间延迟 | |
FrameProgressTimeoutMs |
uint |
单帧重组卡住不动的看门狗(不是取帧等待超时) | |
IncompleteFrameDelivery |
bool |
是否交付不完整帧 | |
ReceiveBufferSize |
uint |
接收缓冲 | |
| 制冷/校正 | TecTemperature |
int |
TEC 目标温度 °C(写为设定值、读为实测) |
TecEnabled |
bool |
TEC 开关 | |
NucCorrectionEnabled |
bool |
非均匀性校正 | |
DefectPixelCorrectionEnabled |
bool |
坏点校正 | |
| 其它 | PreprocessConfig |
PreprocessConfig |
预处理配置 |
ActivePacketBackend |
PacketBackend |
当前收包后端(只读) |
相机不支持某能力时,读写对应属性会抛
DeviceException。
方式二:按名读写 —— 任意 GenICam 参数
便捷属性只覆盖常用项。相机 XML 里的任意参数都可以按名访问,读取分三档:
| 所需信息 | 使用接口 |
|---|---|
| 只要当前值 | GetInt / GetFloat / GetBool / GetEnumString |
| 当前值 + 范围步进 | GetIntParam / GetFloatParam / GetStringParam(带 MaxLength) |
| 当前值 + 可选项列表 | GetEnumParam |
// ① 只要当前值
long w = cam.GetIntValue("Width");
double exp = cam.GetFloatValue("ExposureTime");
bool on = cam.GetBoolValue("AcquisitionFrameRateEnable");
string mode = cam.GetEnumValueByString("TriggerMode"); // "Off"
// ② 当前值 + 范围 / 步进 —— 用于数值输入框、滑块
FloatParam e = cam.GetFloatParam("ExposureTime");
Console.WriteLine($"{e.Value} ∈ [{e.Min}, {e.Max}] step {e.Inc}, 小数位 {e.DisplayPrecision}");
IntParam iw = cam.GetIntParam("Width");
Console.WriteLine($"{iw.Value} ∈ [{iw.Min}, {iw.Max}] step {iw.Inc}, repr {iw.Representation}");
// ③ 当前值 + 全部支持项 —— 用于下拉框
EnumParam p = cam.GetEnumParam("PixelFormat");
foreach (EnumEntry entry in p.Entries)
Console.WriteLine($"{entry.Name} = {entry.Value}"); // Mono8=17301505, ...
Console.WriteLine($"当前: {p.CurrentValue}");
Min/Max/Inc仅整数和浮点类型具备;枚举提供可选项列表,字符串提供MaxLength。
写入
cam.SetIntValue("Width", 1920);
cam.SetFloatValue("ExposureTime", 5000.0);
cam.SetBoolValue("AcquisitionFrameRateEnable", true);
cam.SetEnumValueByString("TriggerMode", "On"); // 按符号名(推荐)
cam.SetEnumValueByString("TriggerMode", 1u); // 或按数值
cam.SetStringParam("DeviceUserID", "cam-01");
cam.ExecuteCommand("TriggerSoftware"); // Command 节点
查询相机支持哪些参数
// 平铺目录
foreach (var item in cam.ParameterCatalog)
Console.WriteLine($"[{item.Kind}] {item.Name} ({item.Category})");
// 树形浏览(用于构建属性树界面)
var root = cam.RootParameterNode;
foreach (var child in cam.GetParameterChildren(root))
Console.WriteLine(child.Name);
// 单个节点的完整信息(显示名、单位、提示、可见性…)
ParamFeature f = cam.GetParameterFeature("ExposureTime");
// 当前是否可写(NI=无此特性 / NA=当前不可用 / RO / RW)
var mode = cam.GetParameterAccessMode("ExposureTime");
GetParameterAccessMode是「此刻能否写」的权威判据——相机的联动约束(如自动曝光开启时ExposureTime只读)都体现在这里,UI 灰显请以它为准。
采集
// ① 主动取帧
cam.Stream.Start();
using (GrabResult frame = cam.Stream.RetrieveResult(2000)) { /* ... */ }
// ② 裸回调(帧到达即触发,每帧零堆分配;请勿在回调中执行耗时操作)
cam.Stream.RegisterBufferCallback((in GrabResult g) => {
Console.WriteLine($"{g.FrameId} {g.Width}x{g.Height}");
});
cam.Stream.Start();
// ③ 触发采集
cam.SetEnumValueByString("TriggerMode", "On");
cam.SetEnumValueByString("TriggerSource", "Software");
cam.ExecuteCommand("TriggerSoftware");
// 采集质量监控(丢包/丢帧统计)
GrabStats st = cam.Stream.Stats;
Console.WriteLine($"完整 {st.FramesComplete} / 缺包丢弃 {st.FramesIncomplete} / 净丢包 {st.NetLostPackets}");
获取帧的像素数据
using (GrabResult f = cam.Stream.RetrieveResult(2000))
{
byte[] data = f.ToArray(); // ① 复制一份(简单、安全)
IntPtr ptr = f.DataPointer; // ② 直接使用指针(零拷贝,仅在 using 块内有效)
int len = f.Length;
if (f.IsIncomplete) // 缺包导致的不完整帧
Console.WriteLine($"缺失 {f.LostPackets} 个包");
} // 离开 using 块后帧归还 SDK 缓冲池——不得在块外继续使用 DataPointer
Frame 的元数据:Width / Height / OffsetX / OffsetY / PixelFormat / FrameId /
FrameCounter / DeviceTimestampNs / HostTimestampNs / IsIncomplete / LostPackets /
ExpectedPayloads / ReceivedPayloads 等。
务必使用
using(或手动Dispose)。帧使用的是 SDK 缓冲池,不释放将耗尽该池并导致丢帧。
组播:让多个程序同时收同一路图像(GigE)
一台采集、一台质检看同一路流,不用转发、不加延迟:控制方把流推到组播组,其余进程以 「只接收」角色加入该组。
// —— 控制方(照常打开,多设一行)——
cam.Open();
cam.Stream.SetDestination("239.192.1.1", 1042); // 下次 Start 生效
cam.Stream.Start();
// —— 只接收方(另一个进程,可能在另一台机器上)——
var (group, port) = LDVision.Device.ProbeMulticast("192.168.1.10"); // 先问相机在往哪儿发
if (group != null)
{
using var viewer = LDVision.Device.Create("192.168.1.10");
viewer.OpenAsListener(group, port); // 不申请控制权、不写任何寄存器
viewer.Stream.Start(); // 收流与普通相机一模一样
using GrabResult f = viewer.Stream.RetrieveResult(2000);
}
只接收角色读参数照常("控制方现在设的什么曝光"),但一切写操作抛 DeviceException
(ACCESS_DENIED),GetParameterAccessMode 也一律报只读——界面据此置灰即可。
组播下 SDK 会强制关闭包大小协商与 GVSP 重传(前者会把整路流量从组地址临时切走、 打断所有其它接收方)。包大小请在切组播之前谈好。 传
null给SetDestination即回到单播(默认)。
错误处理
所有失败都抛 DeviceException,带原生错误码:
try
{
cam.Open();
cam.SetFloatValue("ExposureTime", 999999.0); // 超出范围
}
catch (DeviceException ex)
{
Console.WriteLine($"{ex.Message}(错误码 {ex.ErrorCode})");
Console.WriteLine(LDVision.Error.Describe(ex.ErrorCode)); // 错误码转可读文本
}
设备信息
foreach (DeviceInfo d in LDVision.Device.Enumerate(1000))
{
Console.WriteLine($"{d.Manufacturer} {d.ModelName} SN={d.SerialNumber}");
Console.WriteLine($" 类型 {d.DeviceType} 固件 {d.FirmwareVersion}");
Console.WriteLine($" GigE: {d.Ip} / {d.Mac} / 网卡 {d.HostNicIp}");
Console.WriteLine($" U3V : {d.UsbPath} VID={d.VendorId:X4} PID={d.ProductId:X4}");
}
图像处理与存图 —— Image 与 PixelFormat
Image 是图像缓冲(转换结果,持有原生内存,须 using),静态成员管转换与存图;
像素格式的查询与 PFNC 常量在 PixelFormat。
| 类型 | 分类 | 成员 | 返回 | 说明 |
|---|---|---|---|---|
Image |
格式转换 | Convert(in GrabResult frame, uint dstFormat, ...) |
Image |
转成目标像素格式,返回持有原生内存的 Image(须 using);要托管数组接 .ToArray() |
ConvertInto(in GrabResult frame, uint dstFormat, byte[] dst, ...) |
int |
转换至调用方提供的缓冲(复用数组、零分配,高帧率场景推荐),返回写入字节数。这条路不产生 Image 对象 |
||
| 存图 | SaveToFile(in GrabResult frame, string path, ImageFormat fmt, ...) |
void |
存 BMP / PNG / TIFF / RAW,位深感知 | |
| 线程数 | SetThreads(uint) / GetThreads() |
— | imgproc 并行线程数,0/1 = 关(默认)。进程级,必须现场实测 |
|
PixelFormat |
格式信息 | Name(uint code) |
string |
像素格式码 → 名称(如 "Mono8") |
BitsPerPixel(uint code) |
uint |
每像素存储位数(Mono12→16、RGB8→24;不查表,不会失败) | ||
TryGetSourceProfile(uint code, out bool isColor, out int bits) |
bool |
一次获取是否彩色与位深 | ||
| PFNC 常量 | Mono8 / Bgr8 / Rgb8 / BayerRg8 … |
uint |
常用格式码,不必再写裸 LDV_PIXEL_* |
Convert/ConvertInto/SaveToFile都有接受in GrabResult或裸指针的重载; 可选参数DemosaicQuality demosaic(去马赛克质量)与BitAlign bitAlign(位对齐)。
// 格式转换(Mono / Bayer / RGB 8-16bit、packed 10p/12p、YUV422,含去马赛克)
// Convert 返回持有原生内存的 Image —— 必须 using
using (var rgb = frame.Convert(LDVision.PixelFormat.Rgb8))
Console.WriteLine($"{rgb.Width}x{rgb.Height} {rgb.Length} 字节");
// 高帧率下复用缓冲,避免逐帧分配(不产生 Image 对象)
byte[] buf = new byte[frame.Width * frame.Height * 3];
int written = frame.ConvertInto(LDVision.PixelFormat.Rgb8, buf);
// 存图:BMP / PNG / TIFF / RAW(位深感知)
frame.SaveToFile("out.png", ImageFormat.Png);
// 像素格式信息
string name = LDVision.PixelFormat.Name(frame.PixelFormat); // "Mono8"
uint bits = LDVision.PixelFormat.BitsPerPixel(frame.PixelFormat);
if (LDVision.PixelFormat.TryGetSourceProfile(frame.PixelFormat, out bool isColor, out int srcBits))
Console.WriteLine($"{(isColor ? "彩色" : "黑白")} {srcBits} bit");
参数存档与恢复
cam.SaveFeatures("profile.txt"); // 整套参数落盘
FeatureLoadReport r = cam.LoadFeatures("profile.txt"); // 跨设备 / 跨型号批量写入参数
Console.WriteLine($"成功 {r.Applied} / 跳过 {r.Skipped} / 失败 {r.Failed}");
// 需要逐节点明细时
foreach (var entry in cam.LoadFeaturesDetailed("profile.txt"))
Console.WriteLine($"{entry.Node}: {entry.Outcome}");
相机级其它常用
bool open = cam.IsOpen; // 是否已打开
cam.Close(); // 主动关闭(或由 using / Dispose 自动关闭)
float t = cam.Temperature; // 设备温度 °C
var link = cam.LinkState; // 链路状态
cam.AutoReconnectWindowMs = 10000; // 断线自动重连窗口 ms;<=0 关闭
cam.Reconnect(); // 手动重连
cam.InvalidateNodes(); // 相机侧状态发生变化、需使参数缓存失效时
完整示例
随 SDK 交付的 Samples/CSharp/ 有 12 个可直接运行的示例:
BasicGrab / CallbackGrab / EventGrab / TriggerGrab / ParameterTree / ParameterConfig /
Preprocess / SaveImage / Reconnect / GrabStatsMonitor / DirectConnect / SdkToolbox。
另有《LDVision .NET 开发手册》与《LDVision .NET 接口说明》两份完整文档(Document/)。
支持的框架与平台
托管程序集:多目标 netstandard2.0 + net8.0。
| 目标 | 谁会用到 |
|---|---|
net8.0 |
.NET 8 及以上。标注了 IsTrimmable / IsAotCompatible,支持裁剪与 Native AOT |
netstandard2.0 |
.NET 7 及以下、.NET Core 2.0+、.NET Framework 4.6.1+、Mono / Unity |
Native AOT / 裁剪:本包在 net8.0 上已标注为 AOT 兼容并经真机实测—— 图像回调、采集统计回调、日志回调三条回调路径在 AOT 产物中 均正常触发。应用启用
PublishAot时,不会因本 SDK 产生IL2xxx/IL3xxx告警。
内含原生库(runtimes/<rid>/native/):
| RID | 说明 |
|---|---|
win-x64 / win-x86 |
Windows 10 及以上 |
win-arm64 |
Windows 10 及以上(ARM64) |
linux-x64 |
glibc 2.31+ |
linux-arm64 |
glibc 2.31+(AArch64) |
ARM64 两档的收包后端少一项:x64/x86 上可用 RIO 与 XDP 两种高性能收包后端, ARM64 上只编入 RIO(Windows)/ recvmmsg(Linux),失败回退标准 socket。 功能与接口完全一致,只是极高帧率场景下的 CPU 占用不如 x64 档。
使用 .NET 5+ 时,原生库经
deps.json按 RID 自动解析,无需手动拷贝。.NET Framework 项目需使用 SDK 风格 csproj +
PackageReference并指定 RID, 否则runtimes/下的原生库不会进输出目录。当前包不含 macOS(
osx-*)原生库。
本包不含 GenTL Producer(
LDVisionTL.cti)。Producer 的用途是让 HALCON / VisionPro / harvesters 等第三方机器视觉软件发现本相机,它必须安装到系统并注册GENICAM_GENTL64_PATH环境变量才生效——这是 LDVision SDK Runtime 安装包的职责, NuGet 包无法完成。使用本 SDK 编程不需要该组件。 (反向的 GenTL Consumer——加载采集卡厂商的.cti接入 CL/CXP 相机——本包完整支持。)
Windows 7 支持
本包的原生库要求 Windows 10 及以上(用到了 Win8+ 的系统 API)。Win7 请改用配套包:
dotnet add package LDVision.Net.Win7
LDVision.Net.Win7 的 API 与本包完全一致
(同名程序集,换包无需修改代码),仅原生库改为 Win7 兼容构建。两个包二选一,不能同时安装。
另注意 .NET 5+ 运行时本身不支持 Win7,该场景请配 .NET Framework 4.6.1+ 或 .NET Core 3.1。
主要能力
- 发现 / 连接:多网卡并发广播、USB 枚举、GenTL
.cti扫描;断线检测 + 自动重连 + 自动重启采集 - 参数:GenICam XML 解析(含 SwissKnife 公式求值);按名读写 + SFNC 便捷属性;参数树浏览、枚举项、访问模式;参数存档与恢复
- 采集:
Start/RetrieveResult/ 回调三种模式;GVSP 帧重组(乱序 / 重复 / 丢包容忍 + 按需重传);U3V Bulk 组帧 - 图像:像素格式转换(Mono / Bayer / RGB 8–16bit、packed
10p/12p、YUV422,含去马赛克);存图 BMP / PNG / TIFF / RAW - 诊断:采集统计、丢包分类、设备温度、日志回调
运行环境说明
- GigE / USB3 Vision:零额外运行时依赖(原生库静态链接 CRT,免装 VC++ Redistributable)。
- GenTL 设备:需目标机已装采集卡厂商运行时(随卡驱动自带,本 SDK 不分发)。
- USB3 Vision:设备需绑定 WinUSB 驱动。
许可
专有软件,版权所有 © 2016-2026 西安立鼎光电科技有限公司。详见包内 LICENSE.txt。
- 官网:https://www.leadingoe.com
- 技术支持:请通过官网联系方式与我们取得联系。
| 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 | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
| .NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- System.Memory (>= 4.5.5)
-
net8.0
- No dependencies.
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 |
|---|---|---|
| 3.2.0 | 82 | 11/19/2026 |
| 3.2.0-rc4 | 72 | 11/19/2026 |
| 3.2.0-rc3 | 93 | 11/18/2026 |
| 3.2.0-rc2 | 86 | 11/17/2026 |
| 3.2.0-rc1 | 104 | 11/12/2026 |
| 3.1.1 | 114 | 11/6/2026 |
| 3.1.0 | 109 | 11/3/2026 |
| 3.1.0-rc6 | 126 | 10/27/2026 |
| 3.1.0-rc5 | 118 | 10/26/2026 |
| 3.1.0-rc4 | 127 | 10/23/2026 |
| 3.1.0-rc3 | 122 | 10/22/2026 |
| 3.1.0-rc2 | 122 | 10/15/2026 |
| 3.0.2 | 166 | 9/29/2026 |
| 3.0.2-rc.2 | 117 | 9/28/2026 |
| 3.0.2-rc.1 | 110 | 9/21/2026 |
| 3.0.1 | 148 | 9/20/2026 |
| 3.0.0 | 156 | 9/14/2026 |
| 3.0.0-rc.2 | 142 | 9/7/2026 |
| 3.0.0-rc.1 | 142 | 9/6/2026 |
| 2.0.1 | 174 | 9/4/2026 |