pthread函数来自一个类,无效使用非静态成员函数pthread_create

时间:2017-06-21 14:43:04

标签: c++

这个问题可能会再次重复,我已经阅读了很多答案,但我无法解决我的问题,因为我是一个使用C ++的初学者程序,请帮助我。 我的标题:parallelmatchglobal.h

class parallelmatchglobal
{
    public:
        struct du_lieu{
           std::vector<KeyPoint> keypoints;
           Mat descriptors;
        };

        parallelmatchglobal(Matcher matcher,vector<Point2f> &ppoints_matched,
                            vector<int> &classes_matched);
        void p_matchGlobal( vector<KeyPoint>  &keypoints,  Mat descriptors);
        void *matchAndAddResult(void* thamso);
        static void *matchAndAddResult_wrapper(void* object);
    private:
        Matcher pmatcher;
        pthread_mutex_t mutex1 = PTHREAD_MUTEX_INITIALIZER;
        std::vector<Point2f>  ppoints_matched;
        std::vector<int>  pclasses_matched;
};

我的类实现:parallelmatchglobal.cpp

    #include "parallelmatchglobal.h"
using namespace cv;
using namespace std;
parallelmatchglobal::parallelmatchglobal(Matcher matcher,
                    vector<Point2f> &points_matched,
                    vector<int> &classes_matched)
    {
        this->pmatcher=matcher;
        this->ppoints_matched=points_matched;
        this->pclasses_matched=classes_matched;
    }
    void parallelmatchglobal::p_matchGlobal(vector<KeyPoint>& keypoints, Mat descriptors)
    {
    Mat des[SO_THREAD];
    vector<KeyPoint> keyp[SO_THREAD];
    for (int i=0; i<descriptors.rows;i++){
            des[i%SO_THREAD].push_back(descriptors.row(i));
            keyp[i%SO_THREAD].push_back(keypoints[i]);
    }
    pthread_t threads[SO_THREAD];
    struct du_lieu td[SO_THREAD];
    int rc;
    for(int i=0;i<SO_THREAD;i++){
        td[i].keypoints=keyp[i];
        td[i].descriptors=des[i];
        rc=pthread_create(&threads[i], NULL,matchAndAddResult, (void *)&td[i]);
    }
    if(rc==-1){
        FILE_LOG(logDEBUG) << "thread error";
    }
    }
    void* parallelmatchglobal::matchAndAddResult(void* thamso){
    struct du_lieu *data;
    data = (struct du_lieu *) thamso;
    vector<Point2f> points_matched;
    vector<int> classes_matched;
    pmatcher.matchGlobal(data->keypoints,data->descriptors, points_matched,classes_matched);
    for(size_t j = 0;j < points_matched.size(); j++){
        pthread_mutex_lock(&mutex1);
        ppoints_matched.push_back(points_matched[j]);
        pclasses_matched.push_back(classes_matched[j]);
        pthread_mutex_unlock(&mutex1);
    }
    }
}

当我跑步时,isue错误:

.../parallelmatchglobal.cpp:28: error: invalid use of non-static member function
         rc=pthread_create(&threads[i], NULL,matchAndAddResult, (void *)&td[i]);
                                                                              ^

0 个答案:

没有答案