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

41 lines
1.3 KiB
C#
Raw Normal View History

2025-12-27 07:05:07 +08:00
using OpenCvSharp;
2025-12-27 07:25:32 +08:00
namespace SHH.CameraSdk
2025-12-27 07:05:07 +08:00
{
2025-12-27 07:25:32 +08:00
/// <summary>
/// [图像缩放服务]
/// 实现:基于基类,专注于将原图缩放并挂载到 TargetMat
/// </summary>
public class ImageScaleCluster : BaseFrameProcessor<ScaleWorker>
2025-12-27 07:05:07 +08:00
{
2025-12-27 07:25:32 +08:00
public ImageScaleCluster(int count) : base(count, "ScaleCluster") { }
2025-12-27 07:05:07 +08:00
2025-12-27 07:25:32 +08:00
protected override ScaleWorker CreateWorker(int id) => new ScaleWorker(this);
2025-12-27 07:05:07 +08:00
}
2025-12-27 07:25:32 +08:00
public class ScaleWorker : BaseWorker
2025-12-27 07:05:07 +08:00
{
2025-12-27 07:25:32 +08:00
private readonly ImageScaleCluster _parent;
public ScaleWorker(ImageScaleCluster parent) => _parent = parent;
2025-12-27 07:05:07 +08:00
2025-12-27 07:25:32 +08:00
protected override void PerformAction(SmartFrame frame, FrameDecision decision)
2025-12-27 07:05:07 +08:00
{
2025-12-27 07:25:32 +08:00
int targetW = 704;
int targetH = 576;
2025-12-27 07:05:07 +08:00
2025-12-27 07:25:32 +08:00
// 算法逻辑:若尺寸符合要求则执行 Resize
if (frame.InternalMat.Width > targetW)
2025-12-27 07:05:07 +08:00
{
2025-12-27 07:25:32 +08:00
Mat targetMat = new Mat();
Cv2.Resize(frame.InternalMat, targetMat, new Size(targetW, targetH), 0, 0, InterpolationFlags.Linear);
2025-12-27 07:05:07 +08:00
2025-12-27 07:25:32 +08:00
// 挂载到衍生属性
frame.AttachTarget(targetMat, FrameScaleType.Shrink);
2025-12-27 07:05:07 +08:00
}
}
2025-12-27 07:25:32 +08:00
protected override void NotifyFinished(long did, SmartFrame frame, FrameDecision dec)
{
_parent.PassToNext(did, frame, dec);
}
2025-12-27 07:05:07 +08:00
}
}