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