Files
Ayay/SHH.CameraSdk/Core/Services/ImageEnhanceCluster.cs

40 lines
1.4 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using OpenCvSharp;
namespace SHH.CameraSdk.Core.Services
{
/// <summary>
/// [图像增亮服务]
/// 实现:对流水线中的 TargetMat 执行像素级亮度提升
/// </summary>
public class ImageEnhanceCluster : BaseFrameProcessor<EnhanceWorker>
{
public ImageEnhanceCluster(int count) : base(count, "EnhanceCluster") { }
protected override EnhanceWorker CreateWorker(int id) => new EnhanceWorker(this);
}
public class EnhanceWorker : BaseWorker
{
private readonly ImageEnhanceCluster _parent;
public EnhanceWorker(ImageEnhanceCluster parent) => _parent = parent;
protected override void PerformAction(SmartFrame frame, FrameDecision decision)
{
// 业务逻辑:只处理已经过缩放的 TargetMat
if (frame.TargetMat != null && !frame.TargetMat.IsDisposed)
{
Mat brightMat = new Mat();
// 亮度线性提升:原像素 * 1.0 + 30 偏移量
frame.TargetMat.ConvertTo(brightMat, -1, 1.0, 30);
// 替换掉原来的 TargetMat旧的会在 AttachTarget 内部被自动 Dispose
frame.AttachTarget(brightMat, frame.ScaleType);
}
}
protected override void NotifyFinished(long did, SmartFrame frame, FrameDecision dec)
{
_parent.PassToNext(did, frame, dec);
}
}
}