针对界面显示的优化
This commit is contained in:
@@ -7,29 +7,67 @@ namespace SHH.CameraSdk
|
||||
/// </summary>
|
||||
public class ImageScaleCluster : BaseFrameProcessor<ScaleWorker>
|
||||
{
|
||||
public ImageScaleCluster(int count) : base(count, "ScaleCluster") { }
|
||||
public ImageScaleCluster(int count, ProcessingConfigManager configManager)
|
||||
: base(count, "ScaleCluster", configManager)
|
||||
{
|
||||
}
|
||||
|
||||
protected override ScaleWorker CreateWorker(int id) => new ScaleWorker(this);
|
||||
protected override ScaleWorker CreateWorker(int id) => new ScaleWorker(this, _configManager);
|
||||
}
|
||||
|
||||
public class ScaleWorker : BaseWorker
|
||||
{
|
||||
private readonly ImageScaleCluster _parent;
|
||||
public ScaleWorker(ImageScaleCluster parent) => _parent = parent;
|
||||
private readonly ProcessingConfigManager _configManager;
|
||||
|
||||
protected override void PerformAction(SmartFrame frame, FrameDecision decision)
|
||||
public ScaleWorker(ImageScaleCluster parent, ProcessingConfigManager configManager)
|
||||
{
|
||||
int targetW = 704;
|
||||
int targetH = 576;
|
||||
_parent = parent;
|
||||
_configManager = configManager;
|
||||
}
|
||||
|
||||
// 算法逻辑:若尺寸符合要求则执行 Resize
|
||||
if (frame.InternalMat.Width > targetW)
|
||||
protected override void PerformAction(long deviceId, SmartFrame frame, FrameDecision decision)
|
||||
{
|
||||
// 1. 获取实时配置 (极快,内存读取)
|
||||
var options = _configManager.GetOptions(deviceId);
|
||||
|
||||
// 2. 原始尺寸
|
||||
int srcW = frame.InternalMat.Width;
|
||||
int srcH = frame.InternalMat.Height;
|
||||
|
||||
// 3. 目标尺寸
|
||||
int targetW = options.TargetWidth;
|
||||
int targetH = options.TargetHeight;
|
||||
|
||||
// 4. 判断是否需要缩放
|
||||
bool needResize = false;
|
||||
|
||||
// 场景 A: 原始图比目标大,且允许缩小
|
||||
if (options.EnableShrink && (srcW > targetW || srcH > targetH))
|
||||
{
|
||||
needResize = true;
|
||||
}
|
||||
// 场景 B: 原始图比目标小,且允许放大 (通常为 False)
|
||||
else if (options.EnableExpand && (srcW < targetW || srcH < targetH))
|
||||
{
|
||||
needResize = true;
|
||||
}
|
||||
|
||||
// 5. 执行动作
|
||||
if (needResize)
|
||||
{
|
||||
Mat targetMat = new Mat();
|
||||
// 线性插值
|
||||
Cv2.Resize(frame.InternalMat, targetMat, new Size(targetW, targetH), 0, 0, InterpolationFlags.Linear);
|
||||
|
||||
// 挂载到衍生属性
|
||||
frame.AttachTarget(targetMat, FrameScaleType.Shrink);
|
||||
// 挂载
|
||||
var scaleType = (srcW > targetW) ? FrameScaleType.Shrink : FrameScaleType.Expand;
|
||||
frame.AttachTarget(targetMat, scaleType);
|
||||
}
|
||||
else
|
||||
{
|
||||
// [透传] 不需要缩放
|
||||
// 此时 frame.TargetMat 为 null,代表“无变化”
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user