mirror of
https://github.com/opencv/opencv.git
synced 2026-07-31 08:13:04 +04:00
core: add an ability to use cxx11 lambda as a parallel_for_ body
This commit is contained in:
@@ -56,6 +56,10 @@
|
||||
#include "opencv2/core.hpp"
|
||||
#include <ostream>
|
||||
|
||||
#if __cplusplus >= 201103L
|
||||
#include <functional>
|
||||
#endif
|
||||
|
||||
namespace cv
|
||||
{
|
||||
|
||||
@@ -478,6 +482,28 @@ public:
|
||||
*/
|
||||
CV_EXPORTS void parallel_for_(const Range& range, const ParallelLoopBody& body, double nstripes=-1.);
|
||||
|
||||
#if __cplusplus >= 201103L
|
||||
class ParallelLoopBodyLambdaWrapper : public ParallelLoopBody
|
||||
{
|
||||
private:
|
||||
std::function<void(const Range&)> m_functor;
|
||||
public:
|
||||
ParallelLoopBodyLambdaWrapper(std::function<void(const Range&)> functor) :
|
||||
m_functor(functor)
|
||||
{ }
|
||||
|
||||
virtual void operator() (const cv::Range& range) const
|
||||
{
|
||||
m_functor(range);
|
||||
}
|
||||
};
|
||||
|
||||
inline void parallel_for_(const Range& range, std::function<void(const Range&)> functor, double nstripes=-1.)
|
||||
{
|
||||
parallel_for_(range, ParallelLoopBodyLambdaWrapper(functor), nstripes);
|
||||
}
|
||||
#endif
|
||||
|
||||
/////////////////////////////// forEach method of cv::Mat ////////////////////////////
|
||||
template<typename _Tp, typename Functor> inline
|
||||
void Mat::forEach_impl(const Functor& operation) {
|
||||
|
||||
Reference in New Issue
Block a user