首页 > 解决方案 > C+11 向量的并行处理

问题描述

当我尝试异步输入平均图像时(例如,concurrency::concurrent_vector<cv::Mat>),如何并行化点或批次(1 行或 1 col 或 3*3 数组)的总和相同的坐标或区域?

如果您能告诉我如何以列或批处理而不是单个单位(例如嵌套)来计算向量中的值,我将不胜感激。

(编辑)

For example 
If I have 3 thread for image processing, and Each result are
thread 1
1 1 1
1 1 1
1 1 1
and thread 2
2 2 2
2 2 2
2 2 2
thread 3
6 6 6
6 6 6
6 6 6

then, just I want is 
3 3 3
3 3 3
3 3 3


I thought two way for calculate average all thread's image.


 1. just sum each thread result derivered to main thread and 
       count how much result derivered.


If thread1&2 result derivered to main thread.
(1) sum
3 3 3
3 3 3 
3 3 3

(2) save count of sum and coordinate
In this example, save value will
1 - count of sum
Rect(0, 0, 2, 2) - coordinate to nested area

(3) If all thread's result coming, do average about nested area
9 9 9
9 9 9
9 9 9
if count of sum value is 2, find nested area and do average.
2(count of sum) / Rect(0, 0, 2, 2)
result will be
3 3 3
3 3 3
3 3 3

2. Just wait all thread's result derivered and do average in batches.
like

1|1 1
1|1 1
1|1 1

2|2 2
2|2 2
2|2 2

6|6 6
6|6 6
6|6 6
|
9
9
9
|
3
3
3
  1. 但是,我不知道如何通过内存引用访问和计算每个线程的图像。如果线程 1 图像地址(在这种情况下,图像中的 0,0 像素数据地址)为 100,线程 2 图像地址开始为 200。那么结果图像中的 (0,0) 像素数据将计算 *100+*200。

当然,在做这个操作之前,我必须检查与坐标匹配的内存是否有正确的值。

  1. 而且,谁告诉我如果我使用 std::reduce,这将很容易实现。但是,我不知道如何以这种方式应用该功能。

标签: c++opencv

解决方案


推荐阅读