日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

OpenCV:OpenCV中的 parallel_for 和opencv parallel_for_

發(fā)布時間:2023/12/31 编程问答 37 豆豆
生活随笔 收集整理的這篇文章主要介紹了 OpenCV:OpenCV中的 parallel_for 和opencv parallel_for_ 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

??????? OpenCV使用OMP完成并行運算,在使用AdaBoost檢測的時候,在cascadedetect.cpp 里面,大量使用

parallel_for_(Range(0, stripCount), CascadeClassifierInvoker( *this, processingRectSize, stripSize, yStep, factor,candidatesVector, rejectLevels, levelWeights, false, currentMask, &mtx) );

語句。

???? ?? 策略對應的機制:

????? ? CascadeClassifierInvoker繼承自于 ParallelLoopBody ,實現(xiàn)parallel_for_( )語句。

???????????????? class CascadeClassifierInvoker : public ParallelLoopBody?

??


?????? CV2.4.3中自帶的calcOpticalFlowPyrLK函數(shù)也用parallel_for重寫過了,之前我一直認為parallel_for就是用來并行計算的,之前也自己寫了一些用parallel_for實現(xiàn)的算法。

????? 直到今天在opencv官網中看到別人的提問,才發(fā)現(xiàn)parallel_for實際上是serial loop (普通循環(huán)結構),而parallel_for_才是parallel loop(OpenCV官網answer),用以實現(xiàn)TBB或者OpenCL并行。

?????? 參考文章:OpenCV中parallel_for 和 parallel_for_學習筆記?

?


??????? 函數(shù)定義在parallel.cpp里面,定義為:

/* ================================ parallel_for_ ================================ */void cv::parallel_for_(const cv::Range& range, const cv::ParallelLoopBody& body, double nstripes) { #ifdef CV_PARALLEL_FRAMEWORKif(numThreads != 0){ProxyLoopBody pbody(body, range, nstripes);cv::Range stripeRange = pbody.stripeRange();#if defined HAVE_TBBtbb::parallel_for(tbb::blocked_range<int>(stripeRange.start, stripeRange.end), pbody); #elif defined HAVE_CSTRIPESparallel(MAX(0, numThreads)){int offset = stripeRange.start;int len = stripeRange.end - offset;Range r(offset + CPX_RANGE_START(len), offset + CPX_RANGE_END(len));pbody(r);barrier();}#elif defined HAVE_OPENMP#pragma omp parallel for schedule(dynamic)for (int i = stripeRange.start; i < stripeRange.end; ++i)pbody(Range(i, i + 1));#elif defined HAVE_GCDdispatch_queue_t concurrent_queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);dispatch_apply_f(stripeRange.end - stripeRange.start, concurrent_queue, &pbody, block_function);#elif defined HAVE_CONCURRENCYif(!pplScheduler || pplScheduler->Id() == Concurrency::CurrentScheduler::Id()){Concurrency::parallel_for(stripeRange.start, stripeRange.end, pbody);}else{pplScheduler->Attach();Concurrency::parallel_for(stripeRange.start, stripeRange.end, pbody);Concurrency::CurrentScheduler::Detach();}#else#error You have hacked and compiling with unsupported parallel framework#endif}else#endif // CV_PARALLEL_FRAMEWORK{(void)nstripes;body(range);} }

其中使用的:

tbb::parallel_for(tbb::blocked_range<int>(stripeRange.start, stripeRange.end), pbody);使用TBB重寫 parallel_for 完成使用TBB并行加速。



???????

總結

以上是生活随笔為你收集整理的OpenCV:OpenCV中的 parallel_for 和opencv parallel_for_的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。