Using OpenCV descriptor matches with findFundamentalMat

久未见 提交于 2019-12-02 20:50:38

Your match array are offsets into the descriptor arrays. Since each descriptor has a corresponding keypoint, you can simply iterate and build two arrays of keypoints from the indices. These keypoints can then be fed into findFundamentalMat.

Edit:

I believe your mistake is in generating finalMatches where you are losing information. The vector filteredMatches is overloaded. The indices where matchesMask is 1 show the indices into keypoints1 while the indices stored into finalMatches are the indices into keypoints2. By scrunching down into finalMatches, you are in effect losing the first set of indices.

Try the following:

Have a loop that counts how many actual matches there are:

int num_matches = 0;
for( int idx = 0; idx < matchesMask.size(); idx++ )
{
    if ( matchesMask[idx] == 1 )
        num_matches++;
}

Now declare CvMats of correct size:

matched_points1  = cvCreateMat(2,numPoints,CV_32F);
matched_points2  = cvCreateMat(2,numPoints,CV_32F);

Now iterate over the filteredMatches and insert: (Exact syntax may differ, you get the idea)

offset = 0;
for (int idx = 0; idx < matchesMask.size(); idx++)
{
    if ( matchesMask[idx] == 1 ) {
        matched_points1[2*offset] = keypoints1[idx].pt.x;
        matched_points1[2*offset+1] = keypoints1[idx].pt.y;
        matched_points2[2*offset] = keypoints2[filteredMatches[idx]].pt.x;
        matched_points2[2*offset+1] = keypoints2[filteredMatches[idx]].pt.y;
        offset++;
    }
}    
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!