TURBO-569:更新工程结构;将导航相机标定和校准功能迁移到XP.Camera类

This commit is contained in:
李伟
2026-04-20 16:09:17 +08:00
parent e166eca3d7
commit 9218384e3f
24 changed files with 2429 additions and 124 deletions
+46
View File
@@ -0,0 +1,46 @@
namespace XP.Camera;
/// <summary>所有相机相关错误的基类异常。</summary>
public class CameraException : Exception
{
public CameraException()
{ }
public CameraException(string message) : base(message)
{
}
public CameraException(string message, Exception innerException) : base(message, innerException)
{
}
}
/// <summary>当相机连接意外断开时抛出的异常。</summary>
public class ConnectionLostException : CameraException
{
public ConnectionLostException()
{ }
public ConnectionLostException(string message) : base(message)
{
}
public ConnectionLostException(string message, Exception innerException) : base(message, innerException)
{
}
}
/// <summary>当系统中无可用相机设备时抛出的异常。</summary>
public class DeviceNotFoundException : CameraException
{
public DeviceNotFoundException()
{ }
public DeviceNotFoundException(string message) : base(message)
{
}
public DeviceNotFoundException(string message, Exception innerException) : base(message, innerException)
{
}
}
+18
View File
@@ -0,0 +1,18 @@
namespace XP.Camera;
/// <summary>
/// 统一相机工厂,根据品牌名称创建对应的相机控制器。
/// </summary>
public class CameraFactory : ICameraFactory
{
/// <inheritdoc />
public ICameraController CreateController(string cameraType)
{
return cameraType switch
{
"Basler" => new BaslerCameraController(),
// "Hikvision" => new HikvisionCameraController(),
_ => throw new NotSupportedException($"不支持的相机品牌: {cameraType}")
};
}
}
+39
View File
@@ -0,0 +1,39 @@
namespace XP.Camera;
/// <summary>相机设备信息。</summary>
public record CameraInfo(
string ModelName,
string SerialNumber,
string VendorName,
string DeviceType
);
/// <summary>图像采集成功事件参数。</summary>
public class ImageGrabbedEventArgs : EventArgs
{
public byte[] PixelData { get; }
public int Width { get; }
public int Height { get; }
public string PixelFormat { get; }
public ImageGrabbedEventArgs(byte[] pixelData, int width, int height, string pixelFormat)
{
PixelData = pixelData;
Width = width;
Height = height;
PixelFormat = pixelFormat;
}
}
/// <summary>图像采集失败事件参数。</summary>
public class GrabErrorEventArgs : EventArgs
{
public int ErrorCode { get; }
public string ErrorDescription { get; }
public GrabErrorEventArgs(int errorCode, string errorDescription)
{
ErrorCode = errorCode;
ErrorDescription = errorDescription;
}
}
+64
View File
@@ -0,0 +1,64 @@
namespace XP.Camera;
/// <summary>
/// 相机控制器接口,定义与品牌无关的相机操作契约。
/// </summary>
/// <remarks>
/// <para>所有公共方法(Open/Close/StartGrabbing/StopGrabbing/ExecuteSoftwareTrigger/参数读写)保证线程安全。</para>
/// <para>事件回调在非 UI 线程上触发,调用方如需更新 WPF 界面,应通过 Dispatcher 调度。</para>
/// </remarks>
public interface ICameraController : IDisposable
{
bool IsConnected { get; }
bool IsGrabbing { get; }
/// <summary>打开相机连接并返回设备信息。</summary>
CameraInfo Open();
/// <summary>关闭相机连接并释放资源。</summary>
void Close();
/// <summary>以软件触发模式启动图像采集。</summary>
void StartGrabbing();
/// <summary>发送一次软件触发信号以采集一帧图像。</summary>
void ExecuteSoftwareTrigger();
/// <summary>停止图像采集。</summary>
void StopGrabbing();
double GetExposureTime();
void SetExposureTime(double microseconds);
double GetGain();
void SetGain(double value);
int GetWidth();
void SetWidth(int value);
int GetHeight();
void SetHeight(int value);
string GetPixelFormat();
void SetPixelFormat(string format);
event EventHandler<ImageGrabbedEventArgs> ImageGrabbed;
event EventHandler<GrabErrorEventArgs> GrabError;
event EventHandler ConnectionLost;
}
/// <summary>
/// 相机工厂接口,负责根据品牌创建相机控制器实例。
/// </summary>
public interface ICameraFactory
{
/// <summary>根据相机品牌创建控制器实例。</summary>
ICameraController CreateController(string cameraType);
}