已合并 PR 90: 探测器直方图和优化合并至开发分支
1、重构探测器Hardware.Detector模块,统一设备调用接口,支持多探测器兼容,优化设备连接状态判断逻辑,新增校正帧数可配置功能。 2、优化Varex探测器校正流程,修复内存缓冲区对齐问题,增加指针、分辨率有效性校验,校正期间屏蔽帧回调、自动启停采集,规避SDK冲突与程序崩溃问题。 3、开发通用图像灰度直方图控件,优化资源释放逻辑。
This commit is contained in:
@@ -386,6 +386,44 @@ namespace XP.Hardware.Detector.Abstractions
|
||||
/// </summary>
|
||||
public abstract DetectorInfo GetInfo();
|
||||
|
||||
/// <summary>
|
||||
/// 应用探测器参数 | Apply detector parameters
|
||||
/// </summary>
|
||||
public async Task<DetectorResult> ApplyParametersAsync(int binningIndex, int pga, decimal frameRate, CancellationToken cancellationToken = default)
|
||||
{
|
||||
if (Status != DetectorStatus.Ready)
|
||||
{
|
||||
return DetectorResult.Failure($"探测器状态不正确,当前状态:{Status} | Detector status incorrect, current status: {Status}");
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
return await ApplyParametersInternalAsync(binningIndex, pga, frameRate, cancellationToken);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
var errorResult = DetectorResult.Failure($"应用参数异常 | Apply parameters exception: {ex.Message}", ex);
|
||||
PublishError(errorResult);
|
||||
return errorResult;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取校正能力描述(子类可重写)| Get correction capabilities (subclass can override)
|
||||
/// </summary>
|
||||
public virtual CorrectionCapabilities GetCorrectionCapabilities()
|
||||
{
|
||||
return new CorrectionCapabilities();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 显式失效校正数据(子类可重写)| Explicitly invalidate correction data (subclass can override)
|
||||
/// </summary>
|
||||
public virtual void InvalidateCorrectionData()
|
||||
{
|
||||
// 默认空实现,子类按需重写 | Default empty implementation, subclass overrides as needed
|
||||
}
|
||||
|
||||
// 模板方法,由子类实现 | Template methods, implemented by derived classes
|
||||
protected abstract Task<DetectorResult> InitializeInternalAsync(CancellationToken cancellationToken);
|
||||
protected abstract Task<DetectorResult> StartAcquisitionInternalAsync(CancellationToken cancellationToken);
|
||||
@@ -395,6 +433,7 @@ namespace XP.Hardware.Detector.Abstractions
|
||||
protected abstract Task<DetectorResult> GainCorrectionInternalAsync(int frameCount, CancellationToken cancellationToken);
|
||||
protected abstract Task<DetectorResult> AutoCorrectionInternalAsync(int frameCount, CancellationToken cancellationToken);
|
||||
protected abstract Task<DetectorResult> BadPixelCorrectionInternalAsync(CancellationToken cancellationToken);
|
||||
protected abstract Task<DetectorResult> ApplyParametersInternalAsync(int binningIndex, int pga, decimal frameRate, CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// 更新状态并发布事件 | Update status and publish event
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
namespace XP.Hardware.Detector.Abstractions
|
||||
{
|
||||
/// <summary>
|
||||
/// 校正能力描述 | Correction capabilities description
|
||||
/// 描述探测器支持的校正行为和参数范围,不同探测器可返回不同配置
|
||||
/// </summary>
|
||||
public class CorrectionCapabilities
|
||||
{
|
||||
/// <summary>
|
||||
/// 是否需要在校正前停止采集 | Whether to stop acquisition before correction
|
||||
/// </summary>
|
||||
public bool RequiresStopBeforeCorrection { get; set; } = true;
|
||||
|
||||
/// <summary>
|
||||
/// 是否需要在暗场校正前应用参数 | Whether to apply parameters before dark correction
|
||||
/// </summary>
|
||||
public bool RequiresParameterApplyBeforeDark { get; set; } = true;
|
||||
|
||||
/// <summary>
|
||||
/// 亮场校正后是否自动执行坏像素校正 | Auto bad pixel correction after gain correction
|
||||
/// </summary>
|
||||
public bool AutoBadPixelAfterGain { get; set; } = true;
|
||||
|
||||
/// <summary>
|
||||
/// 停止采集后等待时间(ms)| Post-stop delay (ms)
|
||||
/// </summary>
|
||||
public int PostStopDelayMs { get; set; } = 500;
|
||||
|
||||
/// <summary>
|
||||
/// 暗场校正帧数(从配置文件加载)| Dark correction frame count (loaded from config)
|
||||
/// </summary>
|
||||
public int DarkFrameCount { get; set; } = 64;
|
||||
|
||||
/// <summary>
|
||||
/// 亮场校正帧数(从配置文件加载)| Gain correction frame count (loaded from config)
|
||||
/// </summary>
|
||||
public int GainFrameCount { get; set; } = 64;
|
||||
|
||||
/// <summary>
|
||||
/// 校正帧数最小值 | Correction frame count minimum
|
||||
/// </summary>
|
||||
public int FrameCountMin { get; set; } = 1;
|
||||
|
||||
/// <summary>
|
||||
/// 校正帧数最大值 | Correction frame count maximum
|
||||
/// </summary>
|
||||
public int FrameCountMax { get; set; } = 128;
|
||||
}
|
||||
}
|
||||
@@ -85,5 +85,26 @@ namespace XP.Hardware.Detector.Abstractions
|
||||
/// </summary>
|
||||
/// <returns>探测器信息 | Detector information</returns>
|
||||
DetectorInfo GetInfo();
|
||||
|
||||
/// <summary>
|
||||
/// 应用探测器参数(Binning/PGA/帧率)| Apply detector parameters (Binning/PGA/FrameRate)
|
||||
/// </summary>
|
||||
/// <param name="binningIndex">Binning 索引 | Binning index</param>
|
||||
/// <param name="pga">PGA 灵敏度值 | PGA sensitivity value</param>
|
||||
/// <param name="frameRate">帧率 | Frame rate</param>
|
||||
/// <param name="cancellationToken">取消令牌 | Cancellation token</param>
|
||||
/// <returns>操作结果 | Operation result</returns>
|
||||
Task<DetectorResult> ApplyParametersAsync(int binningIndex, int pga, decimal frameRate, CancellationToken cancellationToken = default);
|
||||
|
||||
/// <summary>
|
||||
/// 获取校正能力描述 | Get correction capabilities
|
||||
/// </summary>
|
||||
/// <returns>校正能力描述 | Correction capabilities</returns>
|
||||
CorrectionCapabilities GetCorrectionCapabilities();
|
||||
|
||||
/// <summary>
|
||||
/// 显式失效校正数据(参数变更后调用)| Explicitly invalidate correction data (called after parameter change)
|
||||
/// </summary>
|
||||
void InvalidateCorrectionData();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user