gpt4 book ai didi

c# - 丑陋的类接口(interface)定义

转载 作者:太空宇宙 更新时间:2023-11-03 20:41:38 24 4
gpt4 key购买 nike

类的功能:

  1. 接收图像帧序列,该序列无限
  2. 检测帧中是否有运动。
  3. 按照一定的算法对运动帧进行分组。

到目前为止的设计是(相当愚蠢):

class MotionDetector
{
//detect motion in the frame, return true if the group is captured.
//frameToDispose is the frame that need be dispose, or for further process.
public bool ProcessFrame(Frame in, out frameToDispose);
}

消费者(片段):

public void Foo()
{
bool groupCaptured = motionDetector.ProcessFrame(nextFrame, out lastFrame);

if (IsStaticFrame(lastFrame)) { lastFrame.Dispose(); }
else { imagesArray.Add(lastFrame); }

if(groupCaptured) { processImageGroup(imagesArray); }
}

我对 MotionDetector 的以下设计感到不舒服:

  1. 图片组的获取方式。
  2. 静止帧的处理方法。
  3. 通知客户组已捕获的方式。

您能否对该类的接口(interface)设计提出一些建议,让客户端更容易、更优雅地使用该类?

最佳答案

消费者类正在做MotionDetector应该做的工作。也许 MotionDetector 构造函数(或类中的某些方法)应该采用帧流,并且这项工作应该在内部完成。该类应在算法运行后仅公开必要的图像数组。

关于c# - 丑陋的类接口(interface)定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2377798/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com