cv::parallel_for_

#include <iostream>
#include <string>
#include <vector>
#include <opencv2/core/internal.hpp>

class Loop_Invoker : public cv::ParallelLoopBody
{
public:
    Loop_Invoker(const std::vector<std::string> & names) :
        ParallelLoopBody(), m_names(names)
    {}
    virtual void operator()(const cv::Range &r) const
    {
        for (int i = r.start; i != r.end; ++i)
        {
            std::cout << m_names[i] << std::endl;
        }
    }

protected:
    std::vector<std::string> m_names;
};

int main()
{
    std::vector<std::string> name;
    for (int i = 0; i != 20; ++i)
    {
        name.push_back(std::to_string(i));
    }

    cv::parallel_for_(cv::Range(0, 20), Loop_Invoker(name), 2);

    return 0;
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章