对照别人的测试,也想着换一个方法去检测特征,但对于我的案例,flann效果也不好

  • https://blog.csdn.net/qq_45832961/article/details/122776322

测试图片和目标:

                   

          测试图片                 目标图片

 测试代码:

import cv2 as cv

def ORB_Feature(img1, img2):

    sift = cv.SIFT_create()

    kp1, des1 = sift.detectAndCompute(img1, None)
    kp2, des2 = sift.detectAndCompute(img2, None)  

    index_params = dict(algorithm=1, tree=5)
    search_params = dict(checks=50)

    flann = cv.FlannBasedMatcher(index_params, search_params)
    
    matches = flann.knnMatch(des1, des2, k=2)

    # 准备一个空的掩膜来绘制好的匹配
    good_matches = [[0, 0] for i in range(len(matches))]
    
    # 向掩膜中添加数据
    for i, (m, n) in enumerate(matches):
        if m.distance < 0.7 * n.distance:
            good_matches[i] = [1, 0]

    img_matches = cv.drawMatchesKnn(img1, kp1, img2, kp2, matches, None,
                                    matchColor=(0, 255, 0), singlePointColor=(255, 0, 0),
                                    matchesMask=good_matches, flags=0)

    cv.imshow("Match Result", img_matches)
    cv.waitKey(0)


def rescale_image(img,opt,times):
    if opt == "up":
        scale_up_x = int(times)
        scale_up_y = int(times)
        return  cv.resize(img, None, fx= scale_up_x, fy= scale_up_y, interpolation= cv.INTER_LINEAR)
    if opt == "down":
        scale_down = int(times)
        return  cv.resize(img, None, fx= scale_down, fy= scale_down, interpolation= cv.INTER_LINEAR)


if __name__ == '__main__':
    # 读取图片
    image1 = cv.imread('orb1.png')
    image2 = cv.imread('orb2.png')
    image2 = rescale_image(image2, opt="up", times=5)
    ORB_Feature(image1, image2)

结果:

其实效果还不错,但想试试还有没有别的更准的

 

posted on 2023-07-27 16:51  Jolyne123  阅读(224)  评论(0)    收藏  举报