openCv,匹配三个图像的功能?

时间:2017-06-29 12:46:06

标签: c++ opencv computer-vision

我有立体声相机设置。我正在使用openCv在图像中找到功能。我需要做的是匹配上一帧和当前(左)帧中的功能,然后找到与当前(右)帧中那些功能匹配的功能,这样我就可以对它们进行三角测量。我需要最终得到三组特征描述符和关键帧,在三个图像中匹配。

到目前为止我的代码是:

    //storage
        cv::Mat descCurrent;
        cv::Mat descCurrentR;
        cv::Mat descPrevious;
        std::vector<cv::KeyPoint> keyPntsCurrent;
        std::vector<cv::KeyPoint> keyPntsCurrentMatch;
        std::vector<cv::KeyPoint> keyPntsCurrentR;
        std::vector<cv::KeyPoint> keyPntsPrevious;

    //On the FIRST frame

        keyPntsPrevious = kaze->DetectKeypoints(imLeft, descPrevious);


    // on the CURRENT frame

    //detect the keypoints on Left and Right Current images
        kaze->DetectKeypointsL(imLeft, descCurrent, keyPntsCurrent);
        kaze->DetectKeypointsR(imRight, descCurrentR, keyPntsCurrentR);

    //match to previous frame
        std::vector<cv::DMatch> match = pntMatch->matchPoints(descPrevious, descCurrent);

    //get current - previous descriptors to use for left - right matching
        if (match.size() > 1)
        {
            for (int m = 0; m < match.size(); m++)
        {
           // feature index OF PREVIOUS FRAME DESC
            float* descVector = descCurrent.ptr<float>(match[m].trainIdx);
            descTmp.push_back(descVector);
            //feature index OF CURRENT FRAME KEY            
            keyPntsCurrentMatch.push_back(keyPntsCurrent[match[m].trainIdx]); 

        }

        }
            //  memcpy(descCurrentMatched.data, descTmp.data(), descTmp.size()*sizeof(float));
                descTmp.clear();

                //match to RIGHT frame
                std::vector<cv::DMatch> matchR = pntMatch->matchPoints(descCurrentMatched, descCurrentR);


//triangulate
PointsTo3d(keyPntsCurrentMatch, keyPntsCurrentR, matchR);

    //at end of loop
        descPrevious = descCurrentMatched;
        keyPntsPrevious = keyPntsCurrent;
        keyPntsCurrentMatch.clear();

这一行: memcpy(descCurrentMatched.data, descTmp.data(), descTmp.size()*sizeof(float));

目前崩溃应用程序,没有错误。所以我的问题是:

这是一种在动态视频流中匹配三个图像的功能的有效方法吗?

如果是这样,为什么memcpy会崩溃?

谢谢。

1 个答案:

答案 0 :(得分:0)

啊哈!发布后几分钟,我想出了一个解决方法。可以检测所有关键点,然后将匹配的先前当前关键点传递到此函数中:

cv::Mat features;
cv::Ptr<cv::DescriptorExtractor> extractor = cv::AKAZE::create();
extractor->compute(imLeft, keyPntsCurrentMatch, features); 

这将从您传入的关键点输出新的描述符。