我想要匹配这个logo with this image(它们是2个不同的图像)

代码设法找到正确的关键点,但他在两个图像之间不匹配 . 上面的图片也显示了关键点

码:

在此部分之前,我正在加载两个图像并使用SIFT从每个图像中提取关键点 . 因此,sceneDescripters是第一个图像的关键点描述符,而templateDescripters是第二个图像的描述符 .

在这部分中,我使用flann匹配每个图像的关键点 .

MatOfDMatch matchs = new MatOfDMatch();
    DescriptorMatcher matcher = DescriptorMatcher.create(DescriptorMatcher.FLANNBASED);
    matcher.match(sceneDescripters, templateDescripters, matchs);

找到最小距离和最大距离 . 然后只重命名匹配它们之间足够小的匹配 .

DMatch[] matchesArr = matchs.toArray();

    double minDist = Double.MAX_VALUE; 
    double maxDist = 0;
    for(int i =0; i< matchesArr.length; i++)
    {
        double dist = matchesArr[i].distance;
        if(dist < minDist)
            minDist = dist;
        else if(dist > maxDist)
            maxDist = dist;
    }


    final double threasholdFactor = 2.0;
    List<DMatch> bestMatches = new Vector<DMatch>();
    for( int i = 0; i < matchesArr.length; i++ )
    {
        if( matchesArr[i].distance <= threasholdFactor*minDist )
        {
            bestMatches.add(matchesArr[i]); 
        }

    }

    MatOfDMatch bests = new MatOfDMatch();
    bests.fromList(bestMatches);

    Mat matchedImage = new Mat(scene.rows(), scene.cols()*2, scene.type());
    Features2d.drawMatches(scene, sceneKeyPoints, template, templateKeyPoints,bests , matchedImage);

    Imgcodecs.imwrite(resultImgPath, matchedImage);

这是result image

我给它一个小的距离阈值,所以你可以看到它只给出了错误的匹配 . 如果距离阈值较高,则会返回太多匹配 .