c++ - 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 图像地址(在这种情况下,图像中的 0,0 像素数据地址)为 100,线程 2 图像地址开始为 200。那么结果图像中的 (0,0) 像素数据将计算 *100+*200。
当然,在做这个操作之前,我必须检查与坐标匹配的内存是否有正确的值。
- 而且,谁告诉我如果我使用 std::reduce,这将很容易实现。但是,我不知道如何以这种方式应用该功能。
解决方案
推荐阅读
- sql - 如何在查询中为 sys 数据库使用数据库名称?
- r - 如何在 R 中的 ggtern() 中使用 position_jitter_tern()?
- jquery - 如何使用电子邮件地址对数据进行分组并根据日期和时间按升序排列?
- r - 如何在修改r中的名称时有条件地从长到宽争吵df?
- node.js - Why does delaying handling of promise rejections sometimes result in UnhandledPromiseRejectionWarning?
- github - 使用github桌面上传我的1GB文件时报错
- django - DRF simplejwt 刷新存储在 HTTPonly cookie 中的 access_token
- optimization - 如何检测 cvxpy 框架中的问题类型?
- webpack - 在 webpack5 中,使用 externals 时,如何将 callback 转换为 Promise?
- scala - 如何使用 LazyList 和 takeWhile 或 dropWhile 并避免产生永无止境的流?