编程语言
首页 > 编程语言> > 使用UML类图分析程序

使用UML类图分析程序

作者:互联网

搬运自我的CSDN https://blog.csdn.net/u013213111/article/details/107897111

待分析的程序来自OpenCV2 Cookbook,UML画图工具使用PlantUML
参考:PlantUML 之类图

Overview

最近需要使用OpenCV分析一系列文件并形成视频输出,打算参考OpenCV2 Cookbook中这个视频处理的程序来写。
UML类图如下,只列出了涉及不同对象之间交互的成员和方法:
uml

FrameProcessor作为一个接口,给出每帧图像的处理方法,其成员只有void process(cv:: Mat &input, cv:: Mat &output)这个纯虚函数,这个类的定义就很简单了:

// The frame processor interface
class FrameProcessor {
  public:
	// processing method
	virtual void process(cv:: Mat &input, cv:: Mat &output)= 0;
};

FeatureTracker则是具体处理方法的实现,重点就是void process(cv:: Mat &frame, cv:: Mat &output),还有一些其他的成员函数这里不做展开叙述了。

整个程序基本上是由VideoProcessor进行控制,其中有两种setFrameProcessor的方法:
1 使用FrameProcessor,将其frameProcessor指针指向特定的图像处理实例。
2 使用回调函数,将其process函数指针指向进行图像处理的函数。

此外,VideoProcessor类的成员还包含诸如fnumber(记录帧数)、setInput()(可以从视频、Camera或者图像文件传入数据)等控制视频的一些成员。

Some Details

记录一下完成上面UML类图所涉及到的知识点。

首先,对于UML图中的各种符号,UMich eecs381给出了一个不错的简单总结,部分如下:
notation

抽象类、接口和虚函数用斜体表示。
这里,FrameProcessor类只包含了一个纯虚函数,这种类即接口

对于FrameProcessorVideoProcessor的关系,是依赖、关联还是聚合,这里个人认为是聚合,参考的是这里的说法:

What is really important is to say what is the lifetime of the referenced object. So, for a referenced object (has relationship) that dies when the owner is destroyed, you have to use a solid (filled) diamond. This is called composition. So the owner has to manage the life time of the owned object. One such example is human has hands. The hands do not survive when the human object is destroyed.
When the diamond is not filled (aggregation), then the owner is not responsible to manage the life of the object owned. For example you will not expect to see that the owned object being deleted in the destructor. An employer has a TeamLeadRole, but when the employer is "destroyed" (i.e. left the company) then the TeamLeadRole is still available

最后附上PlantUML code:

@startuml
skinparam classAttributeIconSize 0 //避免将类的可访问性用图标表示,采用+ # -的表示方法
interface FrameProcessor {
{abstract}void process(cv:: Mat &input, cv:: Mat &output)
}
class FeatureTracker {
+void process(cv:: Mat &frame, cv:: Mat &output)
}

FrameProcessor <|.. FeatureTracker

class VideoProcessor {
-void (*process)(cv::Mat&, cv::Mat&)
-FrameProcessor *frameProcessor
+void setFrameProcessor(void (*frameProcessingCallback)(cv::Mat&, cv::Mat&))
+void setFrameProcessor(FrameProcessor* frameProcessorPtr)
}

VideoProcessor o- FrameProcessor
@enduml

标签:Mat,process,void,object,分析程序,类图,UML,FrameProcessor,cv
来源: https://www.cnblogs.com/lyrich/p/13585208.html