c++ - 实时应用中图像采集和图像处理的设计模式或最佳实践

标签 c++ design-patterns

首先,通过“实时”,在此应用程序中图像的图像处理时间应为 0.1 秒或更短。

在我们的应用程序中,除了主线程外,还有三个线程在运行。一个用于图像采集,第二个用于图像处理,第三个用于机器人。在这两个线程之间,有一个图像队列可以共享,因此当相机对图像进行排队并且机器人对已处理的图像进行出队时,成像处理器对图像进行出队和对已处理的图像进行入队。您可能已经注意到的一个限制是,处理后的图像应该按顺序排列,这意味着保持与图像采集中相同的图像顺序。

是否有任何设计模式或最佳实践可应用于此架构。

最佳答案

pipes and filter模式非常适合这种情况。

  • 采集过滤器需要按顺序串行。
  • 处理过滤器可以并行运行。
  • transport-to-robot 过滤器需要按顺序串行。

为了使用现有技术实现这一点,我看到处理大量数据的实时应用程序使用英特尔的 Threading Building Blocks (待定)。在线程积木Tutorial ,“Working on the Assembly Line: pipeline”部分描述了一个类似的问题:

A simple text processing example will be used to demonstrate the usage of pipeline and filter to perform parallel formatting. The example reads a text file, squares each decimal numeral in the text, and writes the modified text to a new file. [...] Assume that the raw file I/O is sequential. The squaring filter can be done in parallel. That is, if you can serially read n chunks very quickly, you can transform each of the n chunks in parallel, as long as they are written in the proper order to the output file.

以及附带的代码:

void RunPipeline( int ntoken, FILE* input_file, FILE* output_file ) {
  tbb::parallel_pipeline(
    ntoken, 
    tbb::make_filter<void,TextSlice*>( 
      tbb::filter::serial_in_order, MyInputFunc(input_file) )
  & tbb::make_filter<TextSlice*,TextSlice*>( 
      tbb::filter::parallel, MyTransformFunc() )
  & tbb::make_filter<TextSlice*,void>(
      tbb::filter::serial_in_order, MyOutputFunc(output_file) ) );
}

无论是否使用 TBB,它都可以作为管道和过滤器模式的重要实现引用,将模式与算法分离,同时提供控制过滤器数据顺序/线程的能力。

关于c++ - 实时应用中图像采集和图像处理的设计模式或最佳实践,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12019140/

相关文章:

c++ - 抽象工厂模式客户端代码

c++ - 在一个项目C++中加载两个同名的dll

C++0x、编译器钩子(Hook)和硬编码语言特性

c++ - 获取 QLocale::Country 的国家/地区代码

design-patterns - 什么是命令总线?

unit-testing - 如何对状态机进行单元测试?

java - Singleton的2种实现

c++ - 在模板中使用 operator<

c++ - 如何从输入文件中查找未知数量的行和列?

C++设计,如何用对象表示协议(protocol)的不同阶段