Zhai.HikCamera
1.0.2
dotnet add package Zhai.HikCamera --version 1.0.2
NuGet\Install-Package Zhai.HikCamera -Version 1.0.2
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="Zhai.HikCamera" Version="1.0.2" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Zhai.HikCamera" Version="1.0.2" />
<PackageReference Include="Zhai.HikCamera" />
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 Zhai.HikCamera --version 1.0.2
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Zhai.HikCamera, 1.0.2"
#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 Zhai.HikCamera@1.0.2
#: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=Zhai.HikCamera&version=1.0.2
#tool nuget:?package=Zhai.HikCamera&version=1.0.2
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Vision.HikCamera
海康 GigE / USB 工业相机核心库,提供设备枚举、参数读写、回调取图和 SDK 生命周期管理,支持 Windows 与 Linux。
环境要求
- .NET 10
- 目标机器安装 HIKROBOT MVS 运行库,并确保
MvCameraControl原生库可搜索到。 - Windows 默认搜索 MVS
Runtime目录。 - Linux 支持
MVCAM_SDK_PATH、MVCAM_COMMON_RUNENV和/opt/MVS/lib。
本包只包含托管代码,不分发海康原生运行库。
快速使用
using Vision.HikCamera;
var devices = await HikCamera.EnumerateDevicesAsync();
if (devices.Count == 0)
{
Console.WriteLine("未发现相机");
return;
}
using var camera = new HikCamera();
camera.FrameReady += frame =>
{
Console.WriteLine($"{frame.Width} × {frame.Height}, {frame.PixelFormat}, {frame.Data.Length} bytes");
};
camera.AcquisitionError += error => Console.WriteLine(error.Message);
await camera.OpenAsync(devices[0]);
await camera.StartGrabbingAsync();
// 使用完成后
await camera.StopGrabbingAsync();
await camera.CloseAsync();
HikCameraFrame.Data 是独立于相机缓冲区的原始字节数组,可在回调返回后继续使用。像素转换由调用方或后续图像适配库完成。
回调和主动取帧不能同时使用。本包只使用回调方式取图。
通用参数读写
可以按 GenICam 节点名读取和设置相机支持的参数,不局限于曝光、增益和触发配置。
var exposure = await camera.GetParameterAsync("ExposureTime", HikCameraParameterType.Float);
Console.WriteLine(exposure.Value);
await camera.SetParameterAsync("ExposureTime", HikCameraParameter.Float(17500));
await camera.SetParameterAsync("TriggerMode", HikCameraParameter.Enumeration("On"));
await camera.SetParameterAsync("AcquisitionStart", HikCameraParameter.Command());
支持的参数类型:Float、Integer、Enumeration、Boolean、String、Command。
批量操作:
var values = await camera.GetParameterBatchAsync(
[
new HikCameraParameterRequest("ExposureTime", HikCameraParameterType.Float),
new HikCameraParameterRequest("Gain", HikCameraParameterType.Float),
new HikCameraParameterRequest("TriggerMode", HikCameraParameterType.Enumeration)
]);
await camera.SetParameterBatchAsync(
[
new HikCameraParameterAssignment("ExposureTime", HikCameraParameter.Float(17500)),
new HikCameraParameterAssignment("Gain", HikCameraParameter.Float(0))
]);
批量设置按顺序执行,不保证事务性;节点不存在或类型不匹配时会返回对应 SDK 错误。
获取全部参数
GetAllParametersAsync() 会读取完整 GenICam XML,返回所有带当前值的可读参数节点,不需要逐项指定名称。
var allParameters = await camera.GetAllParametersAsync();
foreach (var item in allParameters)
{
Console.WriteLine($"{item.Key} = {item.Value.Value} ({item.Value.Type})");
}
命令节点和没有当前值的节点不会包含在结果中。
如需原始 XML,可调用 GetParametersXmlAsync()。
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | 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.
-
net10.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.